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,31 @@
import { Inject, Service } from 'typedi';
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
import events from '@/subscribers/events';
import SaleInvoicesService from '@/services/Sales/SalesInvoices';
import { ISaleInvoiceCreatedPayload } from '@/interfaces';
@Service()
export default class SaleInvoiceAutoIncrementSubscriber extends EventSubscriber {
@Inject()
saleInvoicesService: SaleInvoicesService;
/**
* Constructor method.
*/
public attach(bus) {
bus.subscribe(
events.saleInvoice.onCreated,
this.handleInvoiceNextNumberIncrement
);
}
/**
* Handles sale invoice next number increment once invoice created.
* @param {ISaleInvoiceCreatedPayload} payload -
*/
private handleInvoiceNextNumberIncrement = async ({
tenantId,
}: ISaleInvoiceCreatedPayload) => {
await this.saleInvoicesService.incrementNextInvoiceNumber(tenantId);
};
}

View File

@@ -0,0 +1,41 @@
import { Inject, Service } from 'typedi';
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
import events from '@/subscribers/events';
import SaleEstimateService from '@/services/Sales/SalesEstimate';
import { ISaleInvoiceCreatedPayload } from '@/interfaces';
@Service()
export default class SaleInvoiceConvertFromEstimateSubscriber extends EventSubscriber {
@Inject()
saleEstimatesService: SaleEstimateService;
/**
* Constructor method.
*/
public attach(bus) {
bus.subscribe(
events.saleInvoice.onCreated,
this.handleMarkEstimateConvertOnceInvoiceCreated
);
}
/**
* Marks the sale estimate as converted from the sale invoice once created.
*/
private handleMarkEstimateConvertOnceInvoiceCreated = async ({
tenantId,
saleInvoice,
saleInvoiceDTO,
saleInvoiceId,
trx,
}: ISaleInvoiceCreatedPayload) => {
if (saleInvoiceDTO.fromEstimateId) {
await this.saleEstimatesService.convertEstimateToInvoice(
tenantId,
saleInvoiceDTO.fromEstimateId,
saleInvoiceId,
trx
);
}
};
}

View File

@@ -0,0 +1,44 @@
import { Inject, Service } from 'typedi';
import events from '@/subscribers/events';
import SaleInvoiceNotifyBySms from '@/services/Sales/SaleInvoiceNotifyBySms';
import { ISaleInvoiceCreatedPayload } from '@/interfaces';
import { runAfterTransaction } from '@/services/UnitOfWork/TransactionsHooks';
@Service()
export default class SendSmsNotificationToCustomer {
@Inject()
saleInvoiceNotifyBySms: SaleInvoiceNotifyBySms;
/**
* Attaches events with handlers.
*/
public attach(bus) {
bus.subscribe(
events.saleInvoice.onCreated,
this.sendSmsNotificationAfterInvoiceCreation
);
}
/**
* Hnadle sending SMS notification after invoice transaction creation.
*/
private sendSmsNotificationAfterInvoiceCreation = async ({
tenantId,
saleInvoiceId,
saleInvoice,
trx,
}: ISaleInvoiceCreatedPayload) => {
// Can't continue if the sale invoice is not marked as delivered.
if (!saleInvoice.deliveredAt) return;
// Notify via sms after transactions complete running.
runAfterTransaction(trx, async () => {
try {
await this.saleInvoiceNotifyBySms.notifyDetailsBySmsAfterCreation(
tenantId,
saleInvoiceId
);
} catch (error) {}
});
};
}

View File

@@ -0,0 +1,87 @@
import { Service, Inject } from 'typedi';
import events from '@/subscribers/events';
import TenancyService from '@/services/Tenancy/TenancyService';
import SaleInvoicesService from '@/services/Sales/SalesInvoices';
import {
ISaleInvoiceCreatedPayload,
ISaleInvoiceDeletedPayload,
ISaleInvoiceEditedPayload,
} from '@/interfaces';
@Service()
export default class WriteInventoryTransactions {
@Inject()
tenancy: TenancyService;
@Inject()
saleInvoicesService: SaleInvoicesService;
/**
* Attaches events with handles
*/
public attach(bus) {
bus.subscribe(
events.saleInvoice.onCreated,
this.handleWritingInventoryTransactions
);
bus.subscribe(
events.saleInvoice.onEdited,
this.handleRewritingInventoryTransactions
);
bus.subscribe(
events.saleInvoice.onDeleted,
this.handleDeletingInventoryTransactions
);
}
/**
* Handles the writing inventory transactions once the invoice created.
* @param {ISaleInvoiceCreatedPayload} payload
*/
private handleWritingInventoryTransactions = async ({
tenantId,
saleInvoice,
trx,
}: ISaleInvoiceCreatedPayload) => {
await this.saleInvoicesService.recordInventoryTranscactions(
tenantId,
saleInvoice,
false,
trx
);
};
/**
* Rewriting the inventory transactions once the sale invoice be edited.
* @param {ISaleInvoiceEditPayload} payload -
*/
private handleRewritingInventoryTransactions = async ({
tenantId,
saleInvoice,
trx,
}: ISaleInvoiceEditedPayload) => {
await this.saleInvoicesService.recordInventoryTranscactions(
tenantId,
saleInvoice,
true,
trx
);
};
/**
* Handles deleting the inventory transactions once the invoice deleted.
* @param {ISaleInvoiceDeletedPayload} payload -
*/
private handleDeletingInventoryTransactions = async ({
tenantId,
saleInvoiceId,
oldSaleInvoice,
trx,
}: ISaleInvoiceDeletedPayload) => {
await this.saleInvoicesService.revertInventoryTransactions(
tenantId,
saleInvoiceId,
trx
);
};
}

View File

@@ -0,0 +1,77 @@
import { Service, Inject } from 'typedi';
import events from '@/subscribers/events';
import {
ISaleInvoiceCreatedPayload,
ISaleInvoiceDeletePayload,
ISaleInvoiceEditedPayload,
} from '@/interfaces';
import { SaleInvoiceGLEntries } from '@/services/Sales/Invoices/InvoiceGLEntries';
@Service()
export default class SaleInvoiceWriteGLEntriesSubscriber {
@Inject()
private saleInvoiceGLEntries: SaleInvoiceGLEntries;
/**
* Constructor method.
*/
attach(bus) {
bus.subscribe(
events.saleInvoice.onCreated,
this.handleWriteJournalEntriesOnInvoiceCreated
);
bus.subscribe(
events.saleInvoice.onEdited,
this.handleRewriteJournalEntriesOnceInvoiceEdit
);
bus.subscribe(
events.saleInvoice.onDeleted,
this.handleRevertingInvoiceJournalEntriesOnDelete
);
}
/**
* Records journal entries of the non-inventory invoice.
*/
private handleWriteJournalEntriesOnInvoiceCreated = async ({
tenantId,
saleInvoiceId,
trx,
}: ISaleInvoiceCreatedPayload) => {
await this.saleInvoiceGLEntries.writeInvoiceGLEntries(
tenantId,
saleInvoiceId,
trx
);
};
/**
* Records journal entries of the non-inventory invoice.
*/
private handleRewriteJournalEntriesOnceInvoiceEdit = async ({
tenantId,
saleInvoice,
trx,
}: ISaleInvoiceEditedPayload) => {
await this.saleInvoiceGLEntries.rewritesInvoiceGLEntries(
tenantId,
saleInvoice.id,
trx
);
};
/**
* Handle reverting journal entries once sale invoice delete.
*/
private handleRevertingInvoiceJournalEntriesOnDelete = async ({
tenantId,
saleInvoiceId,
trx,
}: ISaleInvoiceDeletePayload) => {
await this.saleInvoiceGLEntries.revertInvoiceGLEntries(
tenantId,
saleInvoiceId,
trx
);
};
}