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,44 @@
import { GetItemWarehouseTransformer } from './GettItemWarehouseTransformer';
import { Inject, Injectable } from '@nestjs/common';
import { ItemWarehouseQuantity } from '../models/ItemWarehouseQuantity';
import { Item } from '@/modules/Items/models/Item';
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class GetItemWarehouses {
constructor(
@Inject(ItemWarehouseQuantity.name)
private readonly itemWarehouseQuantityModel: TenantModelProxy<
typeof ItemWarehouseQuantity
>,
@Inject(Item.name)
private readonly itemModel: TenantModelProxy<typeof Item>,
private readonly transformer: TransformerInjectable,
) {}
/**
* Retrieves the item warehouses.
* @param {number} itemId
* @returns
*/
public getItemWarehouses = async (itemId: number) => {
// Retrieves specific item or throw not found service error.
const item = await this.itemModel()
.query()
.findById(itemId)
.throwIfNotFound();
const itemWarehouses = await this.itemWarehouseQuantityModel()
.query()
.where('itemId', itemId)
.withGraphFetched('warehouse');
// Retrieves the transformed items warehouses.
return this.transformer.transform(
itemWarehouses,
new GetItemWarehouseTransformer(),
);
};
}

View File

@@ -0,0 +1,46 @@
import { Transformer } from '@/modules/Transformer/Transformer';
import { Item } from '@/modules/Items/models/Item';
export class GetItemWarehouseTransformer extends Transformer {
/**
* Include these attributes to sale invoice object.
* @returns {Array}
*/
public includeAttributes = (): string[] => {
return [
'warehouseId',
'warehouseName',
'warehouseCode',
'quantityOnHandFormatted',
];
};
/**
* Exclude the warehouse attribute.
* @returns {Array}
*/
public excludeAttributes = (): string[] => {
return ['warehouse'];
};
/**
* Formatted sell price.
* @param item
* @returns {string}
*/
public quantityOnHandFormatted(item: Item): string {
return this.formatNumber(item.quantityOnHand, { money: false });
}
public warehouseCode(item: Item): string {
return item.warehouse.code;
}
public warehouseName(item: Item): string {
return item.warehouse.name;
}
public warehouseId(item: Item): number {
return item.warehouse.id;
}
}