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 {
IVendorNewDTO,
IVendorOpeningBalanceEditDTO,
} from './types/Vendors.types';
import { PublicRoute } from '../Auth/Jwt.guard';
@Controller('vendors')
@PublicRoute()
export class VendorsController {
constructor(private vendorsApplication: VendorsApplication) {}

View File

@@ -19,7 +19,7 @@ export class DeleteVendorService {
constructor(
private eventPublisher: EventEmitter2,
private uow: UnitOfWork,
@Inject(Vendor.name) private contactModel: typeof Vendor,
@Inject(Vendor.name) private vendorModel: typeof Vendor,
) {}
/**
@@ -29,9 +29,8 @@ export class DeleteVendorService {
*/
public async deleteVendor(vendorId: number) {
// Retrieves the old vendor or throw not found service error.
const oldVendor = await this.contactModel
const oldVendor = await this.vendorModel
.query()
.modify('vendor')
.findById(vendorId)
.throwIfNotFound();
// .queryAndThrowIfHasRelations({
@@ -47,7 +46,7 @@ export class DeleteVendorService {
// Deletes vendor contact under unit-of-work.
return this.uow.withTransaction(async (trx: Knex.Transaction) => {
// Deletes the vendor contact from the storage.
await this.contactModel.query(trx).findById(vendorId).delete();
await this.vendorModel.query(trx).findById(vendorId).delete();
// Triggers `onVendorDeleted` event.
await this.eventPublisher.emitAsync(events.vendors.onDeleted, {

View File

@@ -170,7 +170,7 @@ export class Vendor extends BaseModel {
return {
bills: {
relation: Model.HasManyRelation,
modelClass: Bill.default,
modelClass: Bill,
join: {
from: 'contacts.id',
to: 'bills.vendorId',
@@ -178,7 +178,7 @@ export class Vendor extends BaseModel {
},
overdueBills: {
relation: Model.HasManyRelation,
modelClass: Bill.default,
modelClass: Bill,
join: {
from: 'contacts.id',
to: 'bills.vendorId',

View File

@@ -18,7 +18,6 @@ export class GetVendorService {
const vendor = await this.vendorModel
.query()
.findById(vendorId)
.modify('vendor')
.throwIfNotFound();
// Transformes the vendor.