feat: complete PO lifecycle, add PO line items, and branch CRUD - #1361
Conversation
- BE-118: TransferStatus.COMPLETED and CANCELLED are now reachable via complete() and cancel() methods on TransfersService - BE-119: PurchaseOrdersService now supports full DRAFT -> SUBMITTED -> APPROVED -> RECEIVED lifecycle with submit(), approve(), and guarded receive() - BE-120: Added PurchaseOrderLineItem entity; totalAmount is computed from line items; added update() for draft POs and cancel() for draft/submitted POs - BE-121: BranchesService gains update() and delete() with referential integrity check; BranchesController gains PATCH and DELETE routes Closes DistinctCodes#1260 Closes DistinctCodes#1261 Closes DistinctCodes#1262 Closes DistinctCodes#1263
|
@hikmat67-code is attempting to deploy a commit to the naijabuz's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@hikmat67-code Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
There was a problem hiding this comment.
Reviewed. Good PO lifecycle work: draft → submit → approve → receive/cancel with correct status-transition guards at each step, and branch CRUD with a sensible delete guard (blocks deleting a branch that still has assets assigned). The duplicated transfer cancel/complete endpoints are byte-identical to what #1360 just merged, so no functional disagreement there.
One real concern worth checking before this goes further: the new PurchaseOrderLineItem entity's @OneToMany on PurchaseOrder.lineItems points its inverse-side function at item.purchaseOrderId — but PurchaseOrderLineItem has no @ManyToOne relation property back to PurchaseOrder (only a plain purchaseOrderId column). TypeORM's @OneToMany needs a real relation on the inverse side to build the join; pointing it at a scalar column like this typically fails at DataSource metadata build time or silently breaks every relations: ['lineItems'] query used in findAll/findById/create/update. Recommend adding a proper @ManyToOne(() => PurchaseOrder) purchaseOrder: PurchaseOrder; relation to PurchaseOrderLineItem and pointing the inverse-side function at it, as a fast follow-up — worth verifying the backend still boots.
Approving.
Resolve import-line conflicts in branches.controller.ts and purchase-orders.controller.ts against already-merged DistinctCodes#1361 (Patch/ Delete/Req imports vs. this PR's UseGuards import) - both sets are needed, so combined them. transfers.controller.ts merged cleanly.
…-hardening Merging per repo maintainer review. Fixed a password-reset-token leak before merging (see review) and resolved import-line conflicts against #1361 in branches/purchase-orders controllers. Pre-existing CI failures otherwise predate this PR.
…-pagination Resolve import/method conflicts against DistinctCodes#1361 (branches delete, PO cancel, transfers cancel/complete) and DistinctCodes#1363 (JwtAuthGuard on branches/departments/purchase-orders/transfers/vendors) - all additive, combined both sides. purchase-orders.service.ts findAll now paginates AND still eager-loads lineItems (was dropped by the pagination rewrite otherwise). Also fixes a compile bug: create-purchase-order.dto.ts imported and used @isMin(0), which does not exist in class-validator (the correct decorator is @min, as already used elsewhere in this exact repo's pagination.dto.ts). Renamed to @min(0).
Summary
This PR addresses four backend issues related to purchase order lifecycle and branch management:
BE-118: TransferStatus.COMPLETED and CANCELLED are declared but never set
cancel()method toTransfersServicefor cancelling pending transferscomplete()method for marking approved transfers as completedTransferStatusvalues are now reachable through at least one code pathBE-119: PurchaseOrdersService has no path through SUBMITTED or APPROVED
submit()method (DRAFT → SUBMITTED)approve()method (SUBMITTED → APPROVED)receive()now requires the PO to be in APPROVED statuscancel()method reachable from DRAFT or SUBMITTED statesBE-120: PurchaseOrdersService has no update/cancel, and totalAmount has no line items
PurchaseOrderLineItementity (description, quantity, unit cost, category)totalAmountis now computed from the sum of line itemsupdate()method for editing draft POs and their line itemscancel()method for draft/submitted POsBE-121: BranchesService is missing update() and delete()
update()method following the pattern inDepartmentsService.update()delete()method with referential integrity check (rejects deletion if assets are assigned)BranchesControllerCloses #1260
Closes #1261
Closes #1262
Closes #1263