Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import { Injectable } from '@nestjs/common'; import { LedgerService } from '../../stock-ledger/services/ledger.service'; @Injectable() export class TraceabilityService { constructor(private readonly ledgerService: LedgerService) {} async getItemTraceability(tenantId: string, itemCode: string): Promise<any> { const entries = await this.ledgerService.getLedgerEntries(tenantId, itemCode); return { itemCode, timeline: entries.map(e => ({ id: (e as any)._id.toString(), date: e.postingDate, activity: `${e.transactionType} change of ${e.quantityChange} units`, warehouse: e.warehouseId, cost: e.totalCost, source: { id: e.sourceEntityId, type: e.sourceEntityType }, })), }; } async getBatchTraceability(tenantId: string, batchNumber: string): Promise<any> { const filter = { tenantId, batchNumber }; const entries = await (this.ledgerService as any).ledgerModel.find(filter).sort({ postingDate: 1 }).exec(); return { batchNumber, timeline: entries.map((e: any) => ({ id: e._id.toString(), date: e.postingDate, activity: `${e.transactionType} of ${e.quantityChange}`, source: { id: e.sourceEntityId, type: e.sourceEntityType }, })), }; } async getSerialTraceability(tenantId: string, serialNumber: string): Promise<any> { const filter = { tenantId, serialNumber }; const entries = await (this.ledgerService as any).ledgerModel.find(filter).sort({ postingDate: 1 }).exec(); return { serialNumber, timeline: entries.map((e: any) => ({ id: e._id.toString(), date: e.postingDate, activity: `${e.transactionType} of ${e.quantityChange}`, source: { id: e.sourceEntityId, type: e.sourceEntityType }, })), }; } } |