feat: wip migrate to nestjs

This commit is contained in:
Ahmed Bouhuolia
2024-12-26 15:40:29 +02:00
parent a6932d76f3
commit cd84872a61
96 changed files with 2051 additions and 745 deletions

View File

@@ -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);