fix(BE-122/123/124/125): vendor delete, license race fix, request DTOs, paginated findAll - #1368
Conversation
…lock to prevent race condition
|
@devzakari-sketch is attempting to deploy a commit to the naijabuz's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@devzakari-sketch 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! 🚀 |
…-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).
yusuftomilola
left a comment
There was a problem hiding this comment.
Reviewed. Real, valuable fixes:
- License seat over-allocation race condition (BE-123):
assign()previously read seatsUsed/seatsTotal, then wrote, with no lock in between — two concurrent requests could both pass the check and over-allocate seats. Now wrapped in a DB transaction with a pessimistic write lock on the license row. Correct fix for a real concurrency bug. - Vendor delete (BE-122) now blocks deletion when the vendor has an open (non-RECEIVED) purchase order, returning a clear 400 with the PO number. Minor note for a follow-up: it treats CANCELLED POs as 'open' too (only excludes RECEIVED), so a vendor with only cancelled POs can't be deleted even though nothing is actually pending — not harmful (fails safe), just overly strict.
- Real DTOs (BE-124) replacing
@Body() dto: anyacross branches/purchase-orders/transfers/vendors, plus consistent pagination (BE-125) across branches/departments/purchase-orders/transfers/vendors list endpoints.
Found and fixed one compile bug before merging: create-purchase-order.dto.ts imported and used @IsMin(0) from class-validator, which has no such export (the correct decorator is @Min, as already used in this exact repo's own pagination.dto.ts). Renamed to @Min(0).
Also resolved conflicts against #1361 (branch delete, PO cancel, transfer cancel/complete) and #1363 (JwtAuthGuard everywhere) — all additive, kept both sides. Note: purchase-orders.service.ts's paginated findAll now also keeps eager-loading lineItems, which the pagination rewrite would otherwise have silently dropped from the list endpoint.
Approving.
Summary
This PR addresses four backend issues (BE-122, BE-123, BE-124, BE-125).
BE-122 - VendorsService missing delete()
BE-123 - LicensesService.assign() race condition
BE-124 - Unvalidated �ny bodies in controllers
BE-125 - Unpaginated findAll() in 5 services
closes #1264
closes #1265
closes #1266
closes #1267