add server to monorepo.

This commit is contained in:
a.bouhuolia
2023-02-03 11:57:50 +02:00
parent 28e309981b
commit 80b97b5fdc
1303 changed files with 137049 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import { Service, Inject } from 'typedi';
import events from '@/subscribers/events';
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
import PaymentReceiveService from '@/services/Sales/PaymentReceives/PaymentsReceives';
import { IPaymentReceiveCreatedPayload } from '@/interfaces';
@Service()
export default class PaymentReceiveAutoSerialSubscriber extends EventSubscriber {
@Inject()
paymentReceivesService: PaymentReceiveService;
/**
* Attaches the events with handles.
* @param bus
*/
public attach(bus) {
bus.subscribe(
events.paymentReceive.onCreated,
this.handlePaymentNextNumberIncrement
);
}
/**
* Handles increment next number of payment receive once be created.
* @param {IPaymentReceiveCreatedPayload} payload -
*/
private handlePaymentNextNumberIncrement = async ({
tenantId,
paymentReceiveId,
trx,
}: IPaymentReceiveCreatedPayload) => {
await this.paymentReceivesService.incrementNextPaymentReceiveNumber(
tenantId
);
};
}

View File

@@ -0,0 +1,89 @@
import { Inject, Service } from 'typedi';
import events from '@/subscribers/events';
import PaymentReceiveService from '@/services/Sales/PaymentReceives/PaymentsReceives';
import {
IPaymentReceiveCreatedPayload,
IPaymentReceiveDeletedPayload,
IPaymentReceiveEditedPayload,
} from '@/interfaces';
@Service()
export default class PaymentReceiveSyncInvoices {
@Inject()
paymentReceivesService: PaymentReceiveService;
/**
* Attaches the events to handles.
* @param bus
*/
attach(bus) {
bus.subscribe(
events.paymentReceive.onCreated,
this.handleInvoiceIncrementPaymentOnceCreated
);
bus.subscribe(
events.paymentReceive.onEdited,
this.handleInvoiceIncrementPaymentOnceEdited
);
bus.subscribe(
events.paymentReceive.onDeleted,
this.handleInvoiceDecrementPaymentAmount
);
}
/**
* Handle sale invoice increment/decrement payment amount
* once created, edited or deleted.
*/
private handleInvoiceIncrementPaymentOnceCreated = async ({
tenantId,
paymentReceiveId,
paymentReceive,
trx,
}: IPaymentReceiveCreatedPayload) => {
await this.paymentReceivesService.saveChangeInvoicePaymentAmount(
tenantId,
paymentReceive.entries,
null,
trx
);
};
/**
* Handle sale invoice increment/decrement payment amount once edited.
*/
private handleInvoiceIncrementPaymentOnceEdited = async ({
tenantId,
paymentReceiveId,
paymentReceive,
oldPaymentReceive,
trx,
}: IPaymentReceiveEditedPayload) => {
await this.paymentReceivesService.saveChangeInvoicePaymentAmount(
tenantId,
paymentReceive.entries,
oldPaymentReceive?.entries || null,
trx
);
};
/**
* Handle revert invoices payment amount once payment receive deleted.
*/
private handleInvoiceDecrementPaymentAmount = async ({
tenantId,
paymentReceiveId,
oldPaymentReceive,
trx,
}: IPaymentReceiveDeletedPayload) => {
await this.paymentReceivesService.saveChangeInvoicePaymentAmount(
tenantId,
oldPaymentReceive.entries.map((entry) => ({
...entry,
paymentAmount: 0,
})),
oldPaymentReceive.entries,
trx
);
};
}

View File

@@ -0,0 +1,40 @@
import { Service, Inject } from 'typedi';
import events from '@/subscribers/events';
import PaymentReceiveNotifyBySms from '@/services/Sales/PaymentReceives/PaymentReceiveSmsNotify';
import { IPaymentReceiveCreatedPayload } from '@/interfaces';
import { runAfterTransaction } from '@/services/UnitOfWork/TransactionsHooks';
@Service()
export default class SendSmsNotificationPaymentReceive {
@Inject()
paymentReceiveSmsNotify: PaymentReceiveNotifyBySms;
/**
* Attach events.
*/
public attach(bus) {
bus.subscribe(
events.paymentReceive.onCreated,
this.handleNotifyViaSmsOncePaymentPublish
);
}
/**
* Handles send SMS notification after payment transaction creation.
*/
private handleNotifyViaSmsOncePaymentPublish = ({
tenantId,
paymentReceiveId,
trx,
}: IPaymentReceiveCreatedPayload) => {
// Notify via Sms after transactions complete running.
runAfterTransaction(trx, async () => {
try {
await this.paymentReceiveSmsNotify.notifyViaSmsNotificationAfterCreation(
tenantId,
paymentReceiveId
);
} catch (error) {}
});
};
}

View File

@@ -0,0 +1,77 @@
import { Inject, Service } from 'typedi';
import {
IPaymentReceiveCreatedPayload,
IPaymentReceiveDeletedPayload,
IPaymentReceiveEditedPayload,
} from '@/interfaces';
import events from '@/subscribers/events';
import { PaymentReceiveGLEntries } from '@/services/Sales/PaymentReceives/PaymentReceiveGLEntries';
@Service()
export default class PaymentReceivesWriteGLEntriesSubscriber {
@Inject()
private paymentReceiveGLEntries: PaymentReceiveGLEntries;
/**
* Attaches events with handlers.
*/
public attach(bus) {
bus.subscribe(
events.paymentReceive.onCreated,
this.handleWriteJournalEntriesOnceCreated
);
bus.subscribe(
events.paymentReceive.onEdited,
this.handleOverwriteJournalEntriesOnceEdited
);
bus.subscribe(
events.paymentReceive.onDeleted,
this.handleRevertJournalEntriesOnceDeleted
);
}
/**
* Handle journal entries writing once the payment receive created.
*/
private handleWriteJournalEntriesOnceCreated = async ({
tenantId,
paymentReceiveId,
trx,
}: IPaymentReceiveCreatedPayload) => {
await this.paymentReceiveGLEntries.writePaymentGLEntries(
tenantId,
paymentReceiveId,
trx
);
};
/**
* Handle journal entries writing once the payment receive edited.
*/
private handleOverwriteJournalEntriesOnceEdited = async ({
tenantId,
paymentReceive,
trx,
}: IPaymentReceiveEditedPayload) => {
await this.paymentReceiveGLEntries.rewritePaymentGLEntries(
tenantId,
paymentReceive.id,
trx
);
};
/**
* Handles revert journal entries once deleted.
*/
private handleRevertJournalEntriesOnceDeleted = async ({
tenantId,
paymentReceiveId,
trx,
}: IPaymentReceiveDeletedPayload) => {
await this.paymentReceiveGLEntries.revertPaymentGLEntries(
tenantId,
paymentReceiveId,
trx
);
};
}