feat(nestjs): migrate to NestJS

This commit is contained in:
Ahmed Bouhuolia
2025-04-07 11:51:24 +02:00
parent f068218a16
commit 55fcc908ef
3779 changed files with 631 additions and 195332 deletions

View File

@@ -0,0 +1,46 @@
import * as moment from 'moment';
import { Inject, Injectable } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { Knex } from 'knex';
import { SaleEstimate } from '../models/SaleEstimate';
import { events } from '@/common/events/events';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class ConvertSaleEstimate {
constructor(
private readonly eventPublisher: EventEmitter2,
@Inject(SaleEstimate.name)
private readonly saleEstimateModel: TenantModelProxy<typeof SaleEstimate>,
) {}
/**
* Converts estimate to invoice.
* @param {number} estimateId -
* @return {Promise<void>}
*/
public async convertEstimateToInvoice(
estimateId: number,
invoiceId: number,
trx?: Knex.Transaction,
): Promise<void> {
// Retrieve details of the given sale estimate.
const saleEstimate = await this.saleEstimateModel()
.query()
.findById(estimateId)
.throwIfNotFound();
// Marks the estimate as converted from the givne invoice.
await this.saleEstimateModel().query(trx).where('id', estimateId).patch({
convertedToInvoiceId: invoiceId,
convertedToInvoiceAt: moment().toMySqlDateTime(),
});
// Triggers `onSaleEstimateConvertedToInvoice` event.
await this.eventPublisher.emitAsync(
events.saleEstimate.onConvertedToInvoice,
{},
);
}
}