mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
feat: wip migrate to nestjs
This commit is contained in:
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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, {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user