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

@@ -13,8 +13,10 @@ import {
ICustomerNewDTO,
ICustomerOpeningBalanceEditDTO,
} from './types/Customers.types';
import { PublicRoute } from '../Auth/Jwt.guard';
@Controller('customers')
@PublicRoute()
export class CustomersController {
constructor(private customersApplication: CustomersApplication) {}

View File

@@ -19,7 +19,7 @@ export class DeleteCustomer {
constructor(
private uow: UnitOfWork,
private eventPublisher: EventEmitter2,
@Inject(Customer.name) private contactModel: typeof Customer,
@Inject(Customer.name) private customerModel: typeof Customer,
) {}
/**
@@ -31,10 +31,9 @@ export class DeleteCustomer {
customerId: number,
): Promise<void> {
// Retrieve the customer or throw not found service error.
const oldCustomer = await this.contactModel
const oldCustomer = await this.customerModel
.query()
.findById(customerId)
.modify('customer')
.throwIfNotFound();
// .queryAndThrowIfHasRelations({
// type: ERRORS.CUSTOMER_HAS_TRANSACTIONS,
@@ -49,7 +48,7 @@ export class DeleteCustomer {
// Deletes the customer and associated entities under UOW transaction.
return this.uow.withTransaction(async (trx: Knex.Transaction) => {
// Delete the customer from the storage.
await this.contactModel.query(trx).findById(customerId).delete();
await this.customerModel.query(trx).findById(customerId).delete();
// Throws `onCustomerDeleted` event.
await this.eventPublisher.emitAsync(events.customers.onDeleted, {

View File

@@ -23,7 +23,7 @@ export class EditCustomer {
private uow: UnitOfWork,
private eventPublisher: EventEmitter2,
private customerDTO: CreateEditCustomerDTO,
@Inject(Customer.name) private contactModel: typeof Customer,
@Inject(Customer.name) private customerModel: typeof Customer,
) {}
/**
@@ -37,10 +37,9 @@ export class EditCustomer {
customerDTO: ICustomerEditDTO,
): Promise<Customer> {
// Retrieve the customer or throw not found error.
const oldCustomer = await this.contactModel
const oldCustomer = await this.customerModel
.query()
.findById(customerId)
.modify('customer')
.throwIfNotFound();
// Transforms the given customer DTO to object.
@@ -56,7 +55,7 @@ export class EditCustomer {
} as ICustomerEventEditingPayload);
// Edits the customer details on the storage.
const customer = await this.contactModel
const customer = await this.customerModel
.query()
.updateAndFetchById(customerId, {
...customerObj,