mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
add server to monorepo.
This commit is contained in:
50
packages/server/src/jobs/writeInvoicesJEntries.ts
Normal file
50
packages/server/src/jobs/writeInvoicesJEntries.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { Container } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import SalesInvoicesCost from '@/services/Sales/SalesInvoicesCost';
|
||||
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
||||
|
||||
export default class WriteInvoicesJournalEntries {
|
||||
eventPublisher: EventPublisher;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
*/
|
||||
constructor(agenda) {
|
||||
const eventName = 'rewrite-invoices-journal-entries';
|
||||
this.eventPublisher = Container.get(EventPublisher);
|
||||
|
||||
agenda.define(
|
||||
eventName,
|
||||
{ priority: 'normal', concurrency: 1 },
|
||||
this.handler.bind(this)
|
||||
);
|
||||
agenda.on(`complete:${eventName}`, this.onJobCompleted.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the job execuation.
|
||||
*/
|
||||
public async handler(job, done: Function): Promise<void> {
|
||||
const { startingDate, tenantId } = job.attrs.data;
|
||||
const salesInvoicesCost = Container.get(SalesInvoicesCost);
|
||||
|
||||
try {
|
||||
await salesInvoicesCost.writeCostLotsGLEntries(tenantId, startingDate);
|
||||
done();
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the job complete.
|
||||
*/
|
||||
async onJobCompleted(job) {
|
||||
const { startingDate, itemId, tenantId } = job.attrs.data;
|
||||
|
||||
await this.eventPublisher.emitAsync(
|
||||
events.inventory.onInventoryCostEntriesWritten,
|
||||
{ startingDate, itemId, tenantId }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user