feat: configuring import services on more resources

This commit is contained in:
Ahmed Bouhuolia
2024-04-06 04:06:15 +02:00
parent dd9098bdc1
commit bbafdcd8bd
24 changed files with 805 additions and 106 deletions

View File

@@ -42,7 +42,8 @@ export class CreatePaymentReceive {
public async createPaymentReceive(
tenantId: number,
paymentReceiveDTO: IPaymentReceiveCreateDTO,
authorizedUser: ISystemUser
authorizedUser: ISystemUser,
trx?: Knex.Transaction
) {
const { PaymentReceive, Contact } = this.tenancy.models(tenantId);
@@ -88,31 +89,35 @@ export class CreatePaymentReceive {
tenantMeta.baseCurrency
);
// Creates a payment receive transaction under UOW envirment.
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
// Triggers `onPaymentReceiveCreating` event.
await this.eventPublisher.emitAsync(events.paymentReceive.onCreating, {
trx,
paymentReceiveDTO,
tenantId,
} as IPaymentReceiveCreatingPayload);
return this.uow.withTransaction(
tenantId,
async (trx: Knex.Transaction) => {
// Triggers `onPaymentReceiveCreating` event.
await this.eventPublisher.emitAsync(events.paymentReceive.onCreating, {
trx,
paymentReceiveDTO,
tenantId,
} as IPaymentReceiveCreatingPayload);
// Inserts the payment receive transaction.
const paymentReceive = await PaymentReceive.query(
trx
).insertGraphAndFetch({
...paymentReceiveObj,
});
// Triggers `onPaymentReceiveCreated` event.
await this.eventPublisher.emitAsync(events.paymentReceive.onCreated, {
tenantId,
paymentReceive,
paymentReceiveId: paymentReceive.id,
authorizedUser,
trx,
} as IPaymentReceiveCreatedPayload);
// Inserts the payment receive transaction.
const paymentReceive = await PaymentReceive.query(
trx
).insertGraphAndFetch({
...paymentReceiveObj,
});
// Triggers `onPaymentReceiveCreated` event.
await this.eventPublisher.emitAsync(events.paymentReceive.onCreated, {
tenantId,
paymentReceive,
paymentReceiveId: paymentReceive.id,
authorizedUser,
trx,
} as IPaymentReceiveCreatedPayload);
return paymentReceive;
});
return paymentReceive;
},
trx
);
}
/**

View File

@@ -0,0 +1,45 @@
import { Inject, Service } from 'typedi';
import { Knex } from 'knex';
import { IPaymentReceiveCreateDTO } from '@/interfaces';
import { Importable } from '@/services/Import/Importable';
import { CreatePaymentReceive } from './CreatePaymentReceive';
@Service()
export class PaymentReceivesImportable extends Importable {
@Inject()
private createPaymentReceiveService: CreatePaymentReceive;
/**
* Importing to account service.
* @param {number} tenantId
* @param {IAccountCreateDTO} createAccountDTO
* @returns
*/
public importable(
tenantId: number,
createPaymentDTO: IPaymentReceiveCreateDTO,
trx?: Knex.Transaction
) {
return this.createPaymentReceiveService.createPaymentReceive(
tenantId,
createPaymentDTO,
{},
trx
);
}
/**
* Concurrrency controlling of the importing process.
* @returns {number}
*/
public get concurrency() {
return 1;
}
/**
* Retrieves the sample data that used to download accounts sample sheet.
*/
public sampleData(): any[] {
return [];
}
}

View File

@@ -41,7 +41,8 @@ export class CreateSaleReceipt {
*/
public async createSaleReceipt(
tenantId: number,
saleReceiptDTO: any
saleReceiptDTO: any,
trx?: Knex.Transaction
): Promise<ISaleReceipt> {
const { SaleReceipt, Contact } = this.tenancy.models(tenantId);
@@ -80,27 +81,31 @@ export class CreateSaleReceipt {
);
}
// Creates a sale receipt transaction and associated transactions under UOW env.
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
// Triggers `onSaleReceiptCreating` event.
await this.eventPublisher.emitAsync(events.saleReceipt.onCreating, {
saleReceiptDTO,
tenantId,
trx,
} as ISaleReceiptCreatingPayload);
return this.uow.withTransaction(
tenantId,
async (trx: Knex.Transaction) => {
// Triggers `onSaleReceiptCreating` event.
await this.eventPublisher.emitAsync(events.saleReceipt.onCreating, {
saleReceiptDTO,
tenantId,
trx,
} as ISaleReceiptCreatingPayload);
// Inserts the sale receipt graph to the storage.
const saleReceipt = await SaleReceipt.query().upsertGraph({
...saleReceiptObj,
});
// Triggers `onSaleReceiptCreated` event.
await this.eventPublisher.emitAsync(events.saleReceipt.onCreated, {
tenantId,
saleReceipt,
saleReceiptId: saleReceipt.id,
trx,
} as ISaleReceiptCreatedPayload);
// Inserts the sale receipt graph to the storage.
const saleReceipt = await SaleReceipt.query().upsertGraph({
...saleReceiptObj,
});
// Triggers `onSaleReceiptCreated` event.
await this.eventPublisher.emitAsync(events.saleReceipt.onCreated, {
tenantId,
saleReceipt,
saleReceiptId: saleReceipt.id,
trx,
} as ISaleReceiptCreatedPayload);
return saleReceipt;
});
return saleReceipt;
},
trx
);
}
}

View File

@@ -0,0 +1,45 @@
import { Inject, Service } from 'typedi';
import { Knex } from 'knex';
import { IAccountCreateDTO } from '@/interfaces';
import { CreateSaleReceipt } from './CreateSaleReceipt';
import { Importable } from '@/services/Import/Importable';
import { SaleReceiptsSampleData } from './constants';
@Service()
export class SaleReceiptsImportable extends Importable {
@Inject()
private createReceiptService: CreateSaleReceipt;
/**
* Importing to sale receipts service.
* @param {number} tenantId
* @param {IAccountCreateDTO} createAccountDTO
* @returns
*/
public importable(
tenantId: number,
createAccountDTO: IAccountCreateDTO,
trx?: Knex.Transaction
) {
return this.createReceiptService.createSaleReceipt(
tenantId,
createAccountDTO,
trx
);
}
/**
* Concurrrency controlling of the importing process.
* @returns {number}
*/
public get concurrency() {
return 1;
}
/**
* Retrieves the sample data that used to download accounts sample sheet.
*/
public sampleData(): any[] {
return SaleReceiptsSampleData;
}
}

View File

@@ -46,3 +46,23 @@ export const DEFAULT_VIEWS = [
columns: DEFAULT_VIEW_COLUMNS,
},
];
export const SaleReceiptsSampleData = [
{
"Receipt Date": "2023-01-01",
"Customer": "Randall Kohler",
"Deposit Account": "Petty Cash",
"Exchange Rate": "",
"Receipt Number": "REC-00001",
"Reference No.": "REF-0001",
"Statement": "Delectus unde aut soluta et accusamus placeat.",
"Receipt Message": "Vitae asperiores dicta.",
"Closed": "T",
"Item": "Schmitt Group",
"Quantity": 100,
"Rate": 200,
"Line Description": "Distinctio distinctio sit veritatis consequatur iste quod veritatis."
}
]