mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
refactor: tenant proxy providers
This commit is contained in:
@@ -31,10 +31,10 @@ const models = [
|
||||
LedgerModule,
|
||||
DynamicListModule,
|
||||
InventoryCostModule,
|
||||
...models,
|
||||
],
|
||||
controllers: [InventoryAdjustmentsController],
|
||||
providers: [
|
||||
...models,
|
||||
CreateQuickInventoryAdjustmentService,
|
||||
PublishInventoryAdjustmentService,
|
||||
GetInventoryAdjustmentsService,
|
||||
|
||||
@@ -19,18 +19,21 @@ import { BranchTransactionDTOTransformer } from '@/modules/Branches/integrations
|
||||
import { WarehouseTransactionDTOTransform } from '@/modules/Warehouses/Integrations/WarehouseTransactionDTOTransform';
|
||||
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
|
||||
import { ERRORS } from '../constants/InventoryAdjustments.constants';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class CreateQuickInventoryAdjustmentService {
|
||||
constructor(
|
||||
@Inject(InventoryAdjustment.name)
|
||||
private readonly inventoryAdjustmentModel: typeof InventoryAdjustment,
|
||||
private readonly inventoryAdjustmentModel: TenantModelProxy<
|
||||
typeof InventoryAdjustment
|
||||
>,
|
||||
|
||||
@Inject(Item.name)
|
||||
private readonly itemModel: typeof Item,
|
||||
private readonly itemModel: TenantModelProxy<typeof Item>,
|
||||
|
||||
@Inject(Account.name)
|
||||
private readonly accountModel: typeof Account,
|
||||
private readonly accountModel: TenantModelProxy<typeof Account>,
|
||||
|
||||
private readonly tenancyContext: TenancyContext,
|
||||
private readonly eventEmitter: EventEmitter2,
|
||||
@@ -89,13 +92,13 @@ export class CreateQuickInventoryAdjustmentService {
|
||||
quickAdjustmentDTO: IQuickInventoryAdjustmentDTO,
|
||||
): Promise<InventoryAdjustment> {
|
||||
// Retrieve the adjustment account or throw not found error.
|
||||
const adjustmentAccount = await this.accountModel
|
||||
const adjustmentAccount = await this.accountModel()
|
||||
.query()
|
||||
.findById(quickAdjustmentDTO.adjustmentAccountId)
|
||||
.throwIfNotFound();
|
||||
|
||||
// Retrieve the item model or throw not found service error.
|
||||
const item = await this.itemModel
|
||||
const item = await this.itemModel()
|
||||
.query()
|
||||
.findById(quickAdjustmentDTO.itemId)
|
||||
.throwIfNotFound();
|
||||
@@ -119,7 +122,7 @@ export class CreateQuickInventoryAdjustmentService {
|
||||
} as IInventoryAdjustmentCreatingPayload,
|
||||
);
|
||||
// Saves the inventory adjustment with associated entries to the storage.
|
||||
const inventoryAdjustment = await this.inventoryAdjustmentModel
|
||||
const inventoryAdjustment = await this.inventoryAdjustmentModel()
|
||||
.query(trx)
|
||||
.upsertGraphAndFetch({
|
||||
...invAdjustmentObject,
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
import { UnitOfWork } from '@/modules/Tenancy/TenancyDB/UnitOfWork.service';
|
||||
import { InventoryAdjustmentEntry } from '../models/InventoryAdjustmentEntry';
|
||||
import { InventoryAdjustment } from '../models/InventoryAdjustment';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class DeleteInventoryAdjustmentService {
|
||||
@@ -17,10 +18,14 @@ export class DeleteInventoryAdjustmentService {
|
||||
private readonly uow: UnitOfWork,
|
||||
|
||||
@Inject(InventoryAdjustment.name)
|
||||
private readonly inventoryAdjustmentModel: typeof InventoryAdjustment,
|
||||
private readonly inventoryAdjustmentModel: TenantModelProxy<
|
||||
typeof InventoryAdjustment
|
||||
>,
|
||||
|
||||
@Inject(InventoryAdjustmentEntry.name)
|
||||
private readonly inventoryAdjustmentEntryModel: typeof InventoryAdjustmentEntry,
|
||||
private readonly inventoryAdjustmentEntryModel: TenantModelProxy<
|
||||
typeof InventoryAdjustmentEntry
|
||||
>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -31,7 +36,7 @@ export class DeleteInventoryAdjustmentService {
|
||||
inventoryAdjustmentId: number,
|
||||
): Promise<void> {
|
||||
// Retrieve the inventory adjustment or throw not found service error.
|
||||
const oldInventoryAdjustment = await this.inventoryAdjustmentModel
|
||||
const oldInventoryAdjustment = await this.inventoryAdjustmentModel()
|
||||
.query()
|
||||
.findById(inventoryAdjustmentId)
|
||||
.throwIfNotFound();
|
||||
@@ -46,13 +51,13 @@ export class DeleteInventoryAdjustmentService {
|
||||
} as IInventoryAdjustmentDeletingPayload);
|
||||
|
||||
// Deletes the inventory adjustment entries.
|
||||
await this.inventoryAdjustmentEntryModel
|
||||
await this.inventoryAdjustmentEntryModel()
|
||||
.query(trx)
|
||||
.where('adjustment_id', inventoryAdjustmentId)
|
||||
.delete();
|
||||
|
||||
// Deletes the inventory adjustment transaction.
|
||||
await this.inventoryAdjustmentModel
|
||||
await this.inventoryAdjustmentModel()
|
||||
.query(trx)
|
||||
.findById(inventoryAdjustmentId)
|
||||
.delete();
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
import { events } from '@/common/events/events';
|
||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||
import { ERRORS } from '../constants/InventoryAdjustments.constants';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class PublishInventoryAdjustmentService {
|
||||
@@ -19,7 +20,9 @@ export class PublishInventoryAdjustmentService {
|
||||
private readonly uow: UnitOfWork,
|
||||
|
||||
@Inject(InventoryAdjustment.name)
|
||||
private readonly inventoryAdjustmentModel: typeof InventoryAdjustment,
|
||||
private readonly inventoryAdjustmentModel: TenantModelProxy<
|
||||
typeof InventoryAdjustment
|
||||
>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -30,7 +33,7 @@ export class PublishInventoryAdjustmentService {
|
||||
inventoryAdjustmentId: number,
|
||||
): Promise<void> {
|
||||
// Retrieve the inventory adjustment or throw not found service error.
|
||||
const oldInventoryAdjustment = await this.inventoryAdjustmentModel
|
||||
const oldInventoryAdjustment = await this.inventoryAdjustmentModel()
|
||||
.query()
|
||||
.findById(inventoryAdjustmentId)
|
||||
.throwIfNotFound();
|
||||
@@ -50,14 +53,14 @@ export class PublishInventoryAdjustmentService {
|
||||
);
|
||||
|
||||
// Publish the inventory adjustment transaction.
|
||||
await this.inventoryAdjustmentModel
|
||||
await this.inventoryAdjustmentModel()
|
||||
.query()
|
||||
.findById(inventoryAdjustmentId)
|
||||
.patch({
|
||||
publishedAt: moment().toMySqlDateTime(),
|
||||
});
|
||||
// Retrieve the inventory adjustment after the modification.
|
||||
const inventoryAdjustment = await this.inventoryAdjustmentModel
|
||||
const inventoryAdjustment = await this.inventoryAdjustmentModel()
|
||||
.query()
|
||||
.findById(inventoryAdjustmentId)
|
||||
.withGraphFetched('entries');
|
||||
|
||||
@@ -4,6 +4,7 @@ import { LedgerStorageService } from '../../../Ledger/LedgerStorage.service';
|
||||
import { InventoryAdjustment } from '../../models/InventoryAdjustment';
|
||||
import { TenancyContext } from '../../../Tenancy/TenancyContext.service';
|
||||
import { InventoryAdjustmentsGL } from './InventoryAdjustmentGL';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class InventoryAdjustmentsGLEntries {
|
||||
@@ -12,7 +13,9 @@ export class InventoryAdjustmentsGLEntries {
|
||||
private readonly tenancyContext: TenancyContext,
|
||||
|
||||
@Inject(InventoryAdjustment.name)
|
||||
private readonly inventoryAdjustment: typeof InventoryAdjustment,
|
||||
private readonly inventoryAdjustment: TenantModelProxy<
|
||||
typeof InventoryAdjustment
|
||||
>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -25,7 +28,8 @@ export class InventoryAdjustmentsGLEntries {
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> => {
|
||||
// Retrieves the inventory adjustment with associated entries.
|
||||
const adjustment = await this.inventoryAdjustment.query(trx)
|
||||
const adjustment = await this.inventoryAdjustment()
|
||||
.query(trx)
|
||||
.findById(inventoryAdjustmentId)
|
||||
.withGraphFetched('entries.item');
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common';
|
||||
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
|
||||
import { InventoryAdjustment } from '../models/InventoryAdjustment';
|
||||
import { InventoryAdjustmentTransformer } from '../InventoryAdjustmentTransformer';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class GetInventoryAdjustmentService {
|
||||
@@ -9,7 +10,9 @@ export class GetInventoryAdjustmentService {
|
||||
private readonly transformer: TransformerInjectable,
|
||||
|
||||
@Inject(InventoryAdjustment.name)
|
||||
private readonly inventoryAdjustmentModel: typeof InventoryAdjustment,
|
||||
private readonly inventoryAdjustmentModel: TenantModelProxy<
|
||||
typeof InventoryAdjustment
|
||||
>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -18,7 +21,7 @@ export class GetInventoryAdjustmentService {
|
||||
*/
|
||||
async getInventoryAdjustment(inventoryAdjustmentId: number) {
|
||||
// Retrieve inventory adjustment transation with associated models.
|
||||
const inventoryAdjustment = await this.inventoryAdjustmentModel
|
||||
const inventoryAdjustment = await this.inventoryAdjustmentModel()
|
||||
.query()
|
||||
.findById(inventoryAdjustmentId)
|
||||
.withGraphFetched('entries.item')
|
||||
|
||||
@@ -6,6 +6,7 @@ import { InventoryAdjustment } from '../models/InventoryAdjustment';
|
||||
import { IInventoryAdjustmentsFilter } from '../types/InventoryAdjustments.types';
|
||||
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
|
||||
import { DynamicListService } from '@/modules/DynamicListing/DynamicList.service';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class GetInventoryAdjustmentsService {
|
||||
@@ -14,7 +15,9 @@ export class GetInventoryAdjustmentsService {
|
||||
private readonly dynamicListService: DynamicListService,
|
||||
|
||||
@Inject(InventoryAdjustment.name)
|
||||
private readonly inventoryAdjustmentModel: typeof InventoryAdjustment,
|
||||
private readonly inventoryAdjustmentModel: TenantModelProxy<
|
||||
typeof InventoryAdjustment
|
||||
>,
|
||||
) {}
|
||||
/**
|
||||
* Retrieve the inventory adjustments paginated list.
|
||||
@@ -32,10 +35,10 @@ export class GetInventoryAdjustmentsService {
|
||||
|
||||
// Dynamic list service.
|
||||
const dynamicFilter = await this.dynamicListService.dynamicList(
|
||||
this.inventoryAdjustmentModel,
|
||||
this.inventoryAdjustmentModel(),
|
||||
filter,
|
||||
);
|
||||
const { results, pagination } = await this.inventoryAdjustmentModel
|
||||
const { results, pagination } = await this.inventoryAdjustmentModel()
|
||||
.query()
|
||||
.onBuild((query) => {
|
||||
query.withGraphFetched('entries.item');
|
||||
|
||||
Reference in New Issue
Block a user