mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
feat: wip migrate to nestjs
This commit is contained in:
@@ -27,7 +27,7 @@ export class CreateBill {
|
||||
private billModel: typeof Bill,
|
||||
|
||||
@Inject(Vendor.name)
|
||||
private contactModel: typeof Vendor,
|
||||
private vendorModel: typeof Vendor,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -49,9 +49,8 @@ export class CreateBill {
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<Bill> {
|
||||
// Retrieves the given bill vendor or throw not found error.
|
||||
const vendor = await this.contactModel
|
||||
const vendor = await this.vendorModel
|
||||
.query()
|
||||
.modify('vendor')
|
||||
.findById(billDTO.vendorId)
|
||||
.throwIfNotFound();
|
||||
|
||||
@@ -70,10 +69,7 @@ export class CreateBill {
|
||||
billDTO.entries,
|
||||
);
|
||||
// Transform the bill DTO to model object.
|
||||
const billObj = await this.transformerDTO.billDTOToModel(
|
||||
billDTO,
|
||||
vendor,
|
||||
);
|
||||
const billObj = await this.transformerDTO.billDTOToModel(billDTO, vendor);
|
||||
|
||||
// Write new bill transaction with associated transactions under UOW env.
|
||||
return this.uow.withTransaction(async (trx: Knex.Transaction) => {
|
||||
@@ -84,12 +80,11 @@ export class CreateBill {
|
||||
} as IBillCreatingPayload);
|
||||
|
||||
// Inserts the bill graph object to the storage.
|
||||
const bill = await this.billModel.query(trx).upsertGraph(billObj);
|
||||
const bill = await this.billModel.query(trx).upsertGraphAndFetch(billObj);
|
||||
|
||||
// Triggers `onBillCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.bill.onCreated, {
|
||||
bill,
|
||||
billId: bill.id,
|
||||
billDTO,
|
||||
trx,
|
||||
} as IBillCreatedPayload);
|
||||
|
||||
Reference in New Issue
Block a user