refactor: split the services to multiple service classes (#202)

This commit is contained in:
Ahmed Bouhuolia
2023-08-10 20:29:39 +02:00
committed by GitHub
parent ffef627dc3
commit 26c6ca9e36
150 changed files with 7188 additions and 5007 deletions

View File

@@ -1,13 +1,13 @@
import { Inject, Service } from 'typedi';
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
import events from '@/subscribers/events';
import SaleInvoicesService from '@/services/Sales/SalesInvoices';
import { SaleInvoiceIncrement } from '@/services/Sales/Invoices/SaleInvoiceIncrement';
import { ISaleInvoiceCreatedPayload } from '@/interfaces';
@Service()
export default class SaleInvoiceAutoIncrementSubscriber extends EventSubscriber {
@Inject()
saleInvoicesService: SaleInvoicesService;
private saleInvoicesService: SaleInvoiceIncrement;
/**
* Constructor method.

View File

@@ -1,13 +1,13 @@
import { Inject, Service } from 'typedi';
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
import events from '@/subscribers/events';
import SaleEstimateService from '@/services/Sales/SalesEstimate';
import { ConvertSaleEstimate } from '@/services/Sales/Estimates/ConvetSaleEstimate';
import { ISaleInvoiceCreatedPayload } from '@/interfaces';
import events from '@/subscribers/events';
@Service()
export default class SaleInvoiceConvertFromEstimateSubscriber extends EventSubscriber {
@Inject()
saleEstimatesService: SaleEstimateService;
private convertEstimateToInvoiceService: ConvertSaleEstimate;
/**
* Constructor method.
@@ -30,7 +30,7 @@ export default class SaleInvoiceConvertFromEstimateSubscriber extends EventSubsc
trx,
}: ISaleInvoiceCreatedPayload) => {
if (saleInvoiceDTO.fromEstimateId) {
await this.saleEstimatesService.convertEstimateToInvoice(
await this.convertEstimateToInvoiceService.convertEstimateToInvoice(
tenantId,
saleInvoiceDTO.fromEstimateId,
saleInvoiceId,

View File

@@ -1,13 +1,13 @@
import { Inject, Service } from 'typedi';
import events from '@/subscribers/events';
import SaleInvoiceNotifyBySms from '@/services/Sales/SaleInvoiceNotifyBySms';
import { SaleInvoiceNotifyBySms } from '@/services/Sales/Invoices/SaleInvoiceNotifyBySms';
import { ISaleInvoiceCreatedPayload } from '@/interfaces';
import { runAfterTransaction } from '@/services/UnitOfWork/TransactionsHooks';
@Service()
export default class SendSmsNotificationToCustomer {
@Inject()
saleInvoiceNotifyBySms: SaleInvoiceNotifyBySms;
private saleInvoiceNotifyBySms: SaleInvoiceNotifyBySms;
/**
* Attaches events with handlers.

View File

@@ -1,20 +1,16 @@
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';
import { InvoiceInventoryTransactions } from '@/services/Sales/Invoices/InvoiceInventoryTransactions';
@Service()
export default class WriteInventoryTransactions {
@Inject()
tenancy: TenancyService;
@Inject()
saleInvoicesService: SaleInvoicesService;
private saleInvoiceInventory: InvoiceInventoryTransactions;
/**
* Attaches events with handles
@@ -43,7 +39,7 @@ export default class WriteInventoryTransactions {
saleInvoice,
trx,
}: ISaleInvoiceCreatedPayload) => {
await this.saleInvoicesService.recordInventoryTranscactions(
await this.saleInvoiceInventory.recordInventoryTranscactions(
tenantId,
saleInvoice,
false,
@@ -53,14 +49,14 @@ export default class WriteInventoryTransactions {
/**
* Rewriting the inventory transactions once the sale invoice be edited.
* @param {ISaleInvoiceEditPayload} payload -
* @param {ISaleInvoiceEditPayload} payload -
*/
private handleRewritingInventoryTransactions = async ({
tenantId,
saleInvoice,
trx,
}: ISaleInvoiceEditedPayload) => {
await this.saleInvoicesService.recordInventoryTranscactions(
await this.saleInvoiceInventory.recordInventoryTranscactions(
tenantId,
saleInvoice,
true,
@@ -70,7 +66,7 @@ export default class WriteInventoryTransactions {
/**
* Handles deleting the inventory transactions once the invoice deleted.
* @param {ISaleInvoiceDeletedPayload} payload -
* @param {ISaleInvoiceDeletedPayload} payload -
*/
private handleDeletingInventoryTransactions = async ({
tenantId,
@@ -78,7 +74,7 @@ export default class WriteInventoryTransactions {
oldSaleInvoice,
trx,
}: ISaleInvoiceDeletedPayload) => {
await this.saleInvoicesService.revertInventoryTransactions(
await this.saleInvoiceInventory.revertInventoryTransactions(
tenantId,
saleInvoiceId,
trx