refactor(nestjs): add importable service to other modules

This commit is contained in:
Ahmed Bouhuolia
2025-04-12 19:26:15 +02:00
parent 51de3631fc
commit 1d53063e09
30 changed files with 1666 additions and 139 deletions

View File

@@ -1,4 +1,5 @@
import { Module } from '@nestjs/common';
import { BullModule } from '@nestjs/bull';
import { PaymentReceivesController } from './PaymentsReceived.controller';
import { PaymentReceivesApplication } from './PaymentReceived.application';
import { CreatePaymentReceivedService } from './commands/CreatePaymentReceived.serivce';
@@ -32,7 +33,6 @@ import { MailNotificationModule } from '../MailNotification/MailNotification.mod
import { DynamicListModule } from '../DynamicListing/DynamicList.module';
import { MailModule } from '../Mail/Mail.module';
import { SendPaymentReceivedMailProcessor } from './processors/PaymentReceivedMailNotification.processor';
import { BullModule } from '@nestjs/bull';
import { SEND_PAYMENT_RECEIVED_MAIL_QUEUE } from './constants';
import { PaymentsReceivedExportable } from './commands/PaymentsReceivedExportable';
import { PaymentsReceivedImportable } from './commands/PaymentsReceivedImportable';
@@ -62,12 +62,14 @@ import { PaymentsReceivedImportable } from './commands/PaymentsReceivedImportabl
SendPaymentReceiveMailNotification,
SendPaymentReceivedMailProcessor,
PaymentsReceivedExportable,
PaymentsReceivedImportable
PaymentsReceivedImportable,
],
exports: [
PaymentReceivesApplication,
CreatePaymentReceivedService,
PaymentReceivedGLEntries,
PaymentsReceivedExportable,
PaymentsReceivedImportable,
],
imports: [
ChromiumlyTenancyModule,

View File

@@ -3,8 +3,11 @@ import { PaymentReceivesApplication } from '../PaymentReceived.application';
import { IPaymentsReceivedFilter } from '../types/PaymentReceived.types';
import { EXPORT_SIZE_LIMIT } from '@/modules/Export/constants';
import { Exportable } from '@/modules/Export/Exportable';
import { ExportableService } from '@/modules/Export/decorators/ExportableModel.decorator';
import { PaymentReceived } from '../models/PaymentReceived';
@Injectable()
@ExportableService({ name: PaymentReceived.name })
export class PaymentsReceivedExportable extends Exportable {
constructor(private readonly paymentReceivedApp: PaymentReceivesApplication) {
super();

View File

@@ -4,8 +4,11 @@ import { Injectable } from '@nestjs/common';
import { PaymentsReceiveSampleData } from '../constants';
import { CreatePaymentReceivedService } from './CreatePaymentReceived.serivce';
import { Importable } from '@/modules/Import/Importable';
import { ImportableService } from '@/modules/Import/decorators/Import.decorator';
import { PaymentReceived } from '../models/PaymentReceived';
@Injectable()
@ImportableService({ name: PaymentReceived.name })
export class PaymentsReceivedImportable extends Importable {
constructor(
private readonly createPaymentReceiveService: CreatePaymentReceivedService,

View File

@@ -0,0 +1,210 @@
import { Features } from "@/common/types/Features";
export const PaymentReceivedMeta = {
importable: true,
exportable: true,
exportFlattenOn: 'entries',
importAggregator: 'group',
importAggregateOn: 'entries',
importAggregateBy: 'paymentReceiveNo',
fields: {
customer: {
name: 'payment_receive.field.customer',
column: 'customer_id',
fieldType: 'relation',
relationType: 'enumeration',
relationKey: 'customer',
relationEntityLabel: 'display_name',
relationEntityKey: 'id',
},
payment_date: {
name: 'payment_receive.field.payment_date',
column: 'payment_date',
fieldType: 'date',
},
amount: {
name: 'payment_receive.field.amount',
column: 'amount',
fieldType: 'number',
},
reference_no: {
name: 'payment_receive.field.reference_no',
column: 'reference_no',
fieldType: 'text',
},
deposit_account: {
name: 'payment_receive.field.deposit_account',
column: 'deposit_account_id',
fieldType: 'relation',
relationType: 'enumeration',
relationKey: 'depositAccount',
relationEntityLabel: 'name',
relationEntityKey: 'slug',
},
payment_receive_no: {
name: 'payment_receive.field.payment_receive_no',
column: 'payment_receive_no',
fieldType: 'text',
},
statement: {
name: 'payment_receive.field.statement',
column: 'statement',
fieldType: 'text',
},
created_at: {
name: 'payment_receive.field.created_at',
column: 'created_at',
fieldDate: 'date',
},
},
columns: {
customer: {
name: 'payment_receive.field.customer',
accessor: 'customer.displayName',
type: 'text',
},
paymentDate: {
name: 'payment_receive.field.payment_date',
type: 'date',
accessor: 'formattedPaymentDate',
},
amount: {
name: 'payment_receive.field.amount',
type: 'number',
accessor: 'formattedAmount',
},
referenceNo: {
name: 'payment_receive.field.reference_no',
type: 'text',
},
depositAccount: {
name: 'payment_receive.field.deposit_account',
accessor: 'depositAccount.name',
type: 'text',
},
paymentReceiveNo: {
name: 'payment_receive.field.payment_receive_no',
type: 'text',
},
statement: {
name: 'payment_receive.field.statement',
type: 'text',
printable: false,
},
entries: {
name: 'Entries',
accessor: 'entries',
type: 'collection',
collectionOf: 'object',
columns: {
date: {
name: 'Invoice date',
accessor: 'invoice.invoiceDateFormatted',
},
invoiceNo: {
name: 'Invoice No.',
accessor: 'invoice.invoiceNo',
},
invoiceRefNo: {
name: 'Invoice Reference No.',
accessor: 'invoice.referenceNo',
},
invoiceAmount: {
name: 'Invoice Amount',
accessor: 'invoice.totalFormatted',
},
paidAmount: {
name: 'Paid Amount',
accessor: 'paymentAmountFormatted',
},
},
},
created_at: {
name: 'payment_receive.field.created_at',
type: 'date',
printable: false,
},
branch: {
name: 'Branch',
type: 'text',
accessor: 'branch.name',
features: [Features.BRANCHES],
},
},
fields2: {
customerId: {
name: 'payment_receive.field.customer',
fieldType: 'relation',
relationModel: 'Contact',
relationImportMatch: ['displayName'],
required: true,
},
exchangeRate: {
name: 'payment_receive.field.exchange_rate',
fieldType: 'number',
},
paymentDate: {
name: 'payment_receive.field.payment_date',
fieldType: 'date',
required: true,
},
referenceNo: {
name: 'payment_receive.field.reference_no',
fieldType: 'text',
},
depositAccountId: {
name: 'payment_receive.field.deposit_account',
fieldType: 'relation',
relationModel: 'Account',
relationImportMatch: ['name', 'code'],
required: true,
importHint: 'Matches the account name or code.',
},
paymentReceiveNo: {
name: 'payment_receive.field.payment_receive_no',
fieldType: 'text',
importHint: 'The payment number should be unique.',
},
statement: {
name: 'payment_receive.field.statement',
fieldType: 'text',
},
entries: {
name: 'payment_receive.field.entries',
fieldType: 'collection',
collectionOf: 'object',
collectionMinLength: 1,
required: true,
fields: {
invoiceId: {
name: 'payment_receive.field.invoice',
fieldType: 'relation',
relationModel: 'SaleInvoice',
relationImportMatch: 'invoiceNo',
required: true,
importHint: 'Matches the invoice number.',
},
paymentAmount: {
name: 'payment_receive.field.entries.payment_amount',
fieldType: 'number',
required: true,
},
},
},
branchId: {
name: 'Branch',
fieldType: 'relation',
relationModel: 'Branch',
relationImportMatch: ['name', 'code'],
features: [Features.BRANCHES],
required: true,
},
},
};

View File

@@ -2,8 +2,13 @@ import { Model } from 'objection';
import { PaymentReceivedEntry } from './PaymentReceivedEntry';
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';
import { ExportableModel } from '@/modules/Export/decorators/ExportableModel.decorator';
import { ImportableModel } from '@/modules/Import/decorators/Import.decorator';
import { InjectModelMeta } from '@/modules/Tenancy/TenancyModels/decorators/InjectModelMeta.decorator';
import { PaymentReceivedMeta } from './PaymentReceived.meta';
@ExportableModel()
@ImportableModel()
@InjectModelMeta(PaymentReceivedMeta)
export class PaymentReceived extends TenantBaseModel {
customerId: number;
paymentDate: string;