fix: import resource imporements

This commit is contained in:
Ahmed Bouhuolia
2024-03-27 04:01:01 +02:00
parent 973d1832bd
commit ad4e51d81d
59 changed files with 1508 additions and 211 deletions

View File

@@ -49,6 +49,10 @@ export class CreateEditVendorDTO {
).toMySqlDateTime(),
}
: {}),
openingBalanceExchangeRate: defaultTo(
vendorDTO.openingBalanceExchangeRate,
1
),
};
};

View File

@@ -35,7 +35,7 @@ export class CreateVendor {
public async createVendor(
tenantId: number,
vendorDTO: IVendorNewDTO,
authorizedUser: ISystemUser
trx?: Knex.Transaction
) {
const { Contact } = this.tenancy.models(tenantId);
@@ -45,28 +45,31 @@ export class CreateVendor {
vendorDTO
);
// Creates vendor contact under unit-of-work evnirement.
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
// Triggers `onVendorCreating` event.
await this.eventPublisher.emitAsync(events.vendors.onCreating, {
tenantId,
vendorDTO,
trx,
} as IVendorEventCreatingPayload);
return this.uow.withTransaction(
tenantId,
async (trx: Knex.Transaction) => {
// Triggers `onVendorCreating` event.
await this.eventPublisher.emitAsync(events.vendors.onCreating, {
tenantId,
vendorDTO,
trx,
} as IVendorEventCreatingPayload);
// Creates a new contact as vendor.
const vendor = await Contact.query(trx).insertAndFetch({
...vendorObject,
});
// Triggers `onVendorCreated` event.
await this.eventPublisher.emitAsync(events.vendors.onCreated, {
tenantId,
vendorId: vendor.id,
vendor,
authorizedUser,
trx,
} as IVendorEventCreatedPayload);
// Creates a new contact as vendor.
const vendor = await Contact.query(trx).insertAndFetch({
...vendorObject,
});
// Triggers `onVendorCreated` event.
await this.eventPublisher.emitAsync(events.vendors.onCreated, {
tenantId,
vendorId: vendor.id,
vendor,
trx,
} as IVendorEventCreatedPayload);
return vendor;
});
return vendor;
},
trx
);
}
}

View File

@@ -0,0 +1,24 @@
import { Importable } from '@/services/Import/Importable';
import { CreateVendor } from './CRUD/CreateVendor';
import { Knex } from 'knex';
import { Inject, Service } from 'typedi';
@Service()
export class VendorsImportable extends Importable {
@Inject()
private createVendorService: CreateVendor;
/**
* Maps the imported data to create a new vendor service.
* @param {number} tenantId
* @param {} createDTO
* @param {Knex.Transaction} trx
*/
public async importable(
tenantId: number,
createDTO: any,
trx?: Knex.Transaction<any, any[]>
): Promise<void> {
await this.createVendorService.createVendor(tenantId, createDTO, trx);
}
}