56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { BaseCustomManager } from 'src/core/modules/domain/usecase/managers/base-custom.manager';
|
|
import { TransactionEntity } from 'src/modules/transaction/transaction/domain/entities/transaction.entity';
|
|
import { EventTopics } from 'src/core/strings/constants/interface.constants';
|
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
|
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
|
import { GeneratePdf } from '../templates/helpers/generate-pdf.helper';
|
|
|
|
@Injectable()
|
|
export class PdfMakeManager extends BaseCustomManager<TransactionEntity> {
|
|
get entityTarget(): any {
|
|
return TransactionModel;
|
|
}
|
|
|
|
get eventTopics(): EventTopics[] {
|
|
return [];
|
|
}
|
|
|
|
async validateProcess(): Promise<void> {
|
|
return;
|
|
}
|
|
|
|
async beforeProcess(): Promise<void> {
|
|
return;
|
|
}
|
|
|
|
async process(): Promise<void> {
|
|
try {
|
|
const transaction = await this.dataService.getOneByOptions({
|
|
where: {
|
|
id: this.data.id,
|
|
},
|
|
relations: ['items'],
|
|
});
|
|
const banks = await this.dataServiceFirstOpt.getManyByOptions({
|
|
where: {
|
|
status: STATUS.ACTIVE,
|
|
},
|
|
});
|
|
|
|
this.result = GeneratePdf(transaction, this.data.invoice_type, banks);
|
|
} catch (error) {
|
|
console.log(error, 'generate pdf');
|
|
}
|
|
return;
|
|
}
|
|
|
|
async afterProcess(): Promise<void> {
|
|
return;
|
|
}
|
|
|
|
getResult() {
|
|
return this.result;
|
|
}
|
|
}
|