mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 18:48:11 +00:00
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { DataSource } from 'typeorm';
|
|
|
|
import { Warehouse } from './entities/warehouse.entity';
|
|
import { WarehouseInventory } from './entities/warehouse-inventory.entity';
|
|
|
|
export interface WarehouseDashboard {
|
|
totalWarehouses: number;
|
|
totalInventory: number;
|
|
receivedToday: number;
|
|
stored: number;
|
|
reserved: number;
|
|
readyForLoading: number;
|
|
loaded: number;
|
|
dispatched: number;
|
|
}
|
|
|
|
@Injectable()
|
|
export class WarehouseDashboardService {
|
|
constructor(private readonly dataSource: DataSource) {}
|
|
|
|
async getDashboard(): Promise<WarehouseDashboard> {
|
|
const warehouseRepo = this.dataSource.getRepository(Warehouse);
|
|
const inventoryRepo = this.dataSource.getRepository(WarehouseInventory);
|
|
|
|
const startOfToday = new Date();
|
|
startOfToday.setHours(0, 0, 0, 0);
|
|
|
|
const [totalWarehouses, totalInventory, stored, reserved, readyForLoading, loaded, dispatched, receivedToday] =
|
|
await Promise.all([
|
|
warehouseRepo.count(),
|
|
inventoryRepo.count(),
|
|
inventoryRepo.count({ where: { status: 'STORED' } }),
|
|
inventoryRepo.count({ where: { status: 'RESERVED' } }),
|
|
inventoryRepo.count({ where: { status: 'READY_FOR_LOADING' } }),
|
|
inventoryRepo.count({ where: { status: 'LOADED' } }),
|
|
inventoryRepo.count({ where: { status: 'DISPATCHED' } }),
|
|
inventoryRepo
|
|
.createQueryBuilder('inv')
|
|
.where('inv.arrived_at >= :start', { start: startOfToday })
|
|
.getCount(),
|
|
]);
|
|
|
|
return {
|
|
totalWarehouses,
|
|
totalInventory,
|
|
receivedToday,
|
|
stored,
|
|
reserved,
|
|
readyForLoading,
|
|
loaded,
|
|
dispatched,
|
|
};
|
|
}
|
|
}
|