feat(nestjs): migrate to NestJS

This commit is contained in:
Ahmed Bouhuolia
2025-04-07 11:51:24 +02:00
parent f068218a16
commit 55fcc908ef
3779 changed files with 631 additions and 195332 deletions

View File

@@ -0,0 +1,34 @@
import { Inject, Injectable } from '@nestjs/common';
import { Warehouse } from '../models/Warehouse.model';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
import { Bill } from '@/modules/Bills/models/Bill';
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
@Injectable()
export class BillActivateWarehouses {
constructor(
@Inject(Bill.name)
private readonly billModel: TenantModelProxy<typeof Bill>,
@Inject(ItemEntry.name)
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
) {}
/**
* Updates all credit note transactions with the primary warehouse.
* @param {Warehouse} primaryWarehouse
* @returns {Promise<void>}
*/
public updateBillsWithWarehouse = async (
primaryWarehouse: Warehouse,
): Promise<void> => {
// Updates the sale estimates with primary warehouse.
await this.billModel().query().update({
warehouseId: primaryWarehouse.id,
});
// Update the sale estimates entries with primary warehouse.
await this.itemEntryModel().query().where('referenceType', 'Bill').update({
warehouseId: primaryWarehouse.id,
});
};
}

View File

@@ -0,0 +1,37 @@
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
import { CreditNote } from '@/modules/CreditNotes/models/CreditNote';
import { Inject, Injectable } from '@nestjs/common';
import { Warehouse } from '../models/Warehouse.model';
@Injectable()
export class CreditNotesActivateWarehouses {
constructor(
@Inject(CreditNote.name)
private readonly creditNoteModel: TenantModelProxy<typeof CreditNote>,
@Inject(ItemEntry.name)
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
) {}
/**
* Updates all credit note transactions with the primary warehouse.
* @param {Warehouse} primaryWarehouse
* @returns {Promise<void>}
*/
public updateCreditsWithWarehouse = async (
primaryWarehouse: Warehouse
): Promise<void> => {
// Updates the sale estimates with primary warehouse.
await this.creditNoteModel().query().update({
warehouseId: primaryWarehouse.id,
});
// Update the sale estimates entries with primary warehouse.
await this.itemEntryModel()
.query()
.where('referenceType', 'CreditNote')
.update({
warehouseId: primaryWarehouse.id,
});
};
}

View File

@@ -0,0 +1,35 @@
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
import { SaleEstimate } from '@/modules/SaleEstimates/models/SaleEstimate';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
import { Injectable } from '@nestjs/common';
import { Warehouse } from '../models/Warehouse.model';
@Injectable()
export class EstimatesActivateWarehouses {
constructor(
private readonly saleEstimateModel: TenantModelProxy<typeof SaleEstimate>,
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
) {}
/**
* Updates all inventory transactions with the primary warehouse.
* @param {Warehouse} primaryWarehouse
* @returns {Promise<void>}
*/
public updateEstimatesWithWarehouse = async (
primaryWarehouse: Warehouse,
): Promise<void> => {
// Updates the sale estimates with primary warehouse.
await this.saleEstimateModel()
.query()
.update({ warehouseId: primaryWarehouse.id });
// Update the sale estimates entries with primary warehouse.
await this.itemEntryModel()
.query()
.where('referenceType', 'SaleEstimate')
.update({
warehouseId: primaryWarehouse.id,
});
};
}

View File

@@ -0,0 +1,31 @@
import { InventoryTransaction } from "@/modules/InventoryCost/models/InventoryTransaction";
import { TenantModelProxy } from "@/modules/System/models/TenantBaseModel";
import { Injectable } from "@nestjs/common";
import { Warehouse } from "../models/Warehouse.model";
import { InventoryCostLotTracker } from "@/modules/InventoryCost/models/InventoryCostLotTracker";
@Injectable()
export class InventoryActivateWarehouses {
constructor(
private readonly inventoryTransactionModel: TenantModelProxy<typeof InventoryTransaction>,
private readonly inventoryCostLotTrackerModel: TenantModelProxy<typeof InventoryCostLotTracker>,
) {}
/**
* Updates all inventory transactions with the primary warehouse.
* @param {number} tenantId
* @param {number} primaryWarehouse
* @returns {Promise<void>}
*/
public updateInventoryTransactionsWithWarehouse = async (
primaryWarehouse: Warehouse
): Promise<void> => {
// Updates the inventory transactions with primary warehouse.
await this.inventoryTransactionModel().query().update({
warehouseId: primaryWarehouse.id,
});
await this.inventoryCostLotTrackerModel().query().update({
warehouseId: primaryWarehouse.id,
});
};
}

View File

@@ -0,0 +1,38 @@
import { Inject, Injectable } from '@nestjs/common';
import { Warehouse } from '../models/Warehouse.model';
import { SaleInvoice } from '@/modules/SaleInvoices/models/SaleInvoice';
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class InvoicesActivateWarehouses {
constructor(
@Inject(SaleInvoice.name)
private readonly saleInvoiceModel: TenantModelProxy<typeof SaleInvoice>,
@Inject(ItemEntry.name)
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
) {}
/**
* Updates all inventory transactions with the primary warehouse.
* @param {Warehouse} primaryWarehouse
* @returns {Promise<void>}
*/
updateInvoicesWithWarehouse = async (
primaryWarehouse: Warehouse,
): Promise<void> => {
// Updates the sale invoices with primary warehouse.
await this.saleInvoiceModel().query().update({
warehouseId: primaryWarehouse.id,
});
// Update the sale invoices entries with primary warehouse.
await this.itemEntryModel()
.query()
.where('referenceType', 'SaleInvoice')
.update({
warehouseId: primaryWarehouse.id,
});
};
}

View File

@@ -0,0 +1,37 @@
import { Inject, Injectable } from '@nestjs/common';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
import { Warehouse } from '../models/Warehouse.model';
import { SaleReceipt } from '@/modules/SaleReceipts/models/SaleReceipt';
@Injectable()
export class ReceiptActivateWarehouses {
constructor(
@Inject(SaleReceipt.name)
private readonly saleReceiptModel: TenantModelProxy<typeof SaleReceipt>,
@Inject(ItemEntry.name)
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
) {}
/**
* Updates all sale receipts transactions with the primary warehouse.
* @param {Warehouse} primaryWarehouse
* @returns {Promise<void>}
*/
public updateReceiptsWithWarehouse = async (
primaryWarehouse: Warehouse,
): Promise<void> => {
// Updates the vendor credits transactions with primary warehouse.
await this.saleReceiptModel().query().update({
warehouseId: primaryWarehouse.id,
});
// Update the sale invoices entries with primary warehouse.
await this.itemEntryModel()
.query()
.where('referenceType', 'SaleReceipt')
.update({
warehouseId: primaryWarehouse.id,
});
};
}

View File

@@ -0,0 +1,38 @@
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
import { VendorCredit } from '@/modules/VendorCredit/models/VendorCredit';
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
import { Warehouse } from '../models/Warehouse.model';
import { Inject, Injectable } from '@nestjs/common';
@Injectable()
export class VendorCreditActivateWarehouses {
constructor(
@Inject(VendorCredit.name)
private readonly vendorCreditModel: TenantModelProxy<typeof VendorCredit>,
@Inject(ItemEntry.name)
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
) {}
/**
* Updates all vendor credits transactions with the primary warehouse.
* @param {Warehouse} primaryWarehouse
* @returns {Promise<void>}
*/
public updateCreditsWithWarehouse = async (
primaryWarehouse: Warehouse,
): Promise<void> => {
// Updates the vendor credits transactions with primary warehouse.
await this.vendorCreditModel().query().update({
warehouseId: primaryWarehouse.id,
});
// Update the sale invoices entries with primary warehouse.
await this.itemEntryModel()
.query()
.where('referenceType', 'VendorCredit')
.update({
warehouseId: primaryWarehouse.id,
});
};
}