diff --git a/docs/procurement-api.md b/docs/procurement-api.md index 1d30fec..fcc5517 100644 --- a/docs/procurement-api.md +++ b/docs/procurement-api.md @@ -12,5 +12,6 @@ This phase introduces private, organization-scoped supplier and material master | PUT | /suppliers/:supplierId/materials/:materialId | procurement.manage | Create or replace compatibility, commercial lead time and quote | Supplier and material codes are uppercase, organization-unique identifiers. Materials use a fixed kind and unit to avoid ambiguous procurement and BOM quantities. Compatibility records hold a supplier SKU, lead time, minimum quantity, price, currency, and active status. A future purchase order must snapshot these values rather than rely on a later edit. +The `active` list filter accepts only `true` or `false`; `active=false` returns inactive records. All endpoints require a session and enforce a permission again inside write transactions. Missing suppliers and materials produce distinct scoped errors. Create, update, and compatibility actions are audit-recorded without arbitrary payloads. The migration is append-only and grants the new permissions only to existing system roles; custom roles require an explicit update. diff --git a/src/procurement/procurement.schemas.ts b/src/procurement/procurement.schemas.ts index 771989b..b3bc4ce 100644 --- a/src/procurement/procurement.schemas.ts +++ b/src/procurement/procurement.schemas.ts @@ -66,7 +66,10 @@ export const supplierMaterialSchema = z .strict(); export const procurementQuery = pageSchema .extend({ - active: z.coerce.boolean().optional(), + active: z + .enum(['true', 'false']) + .transform((value) => value === 'true') + .optional(), search: text(100).optional(), }) .strict(); diff --git a/test/procurement.spec.ts b/test/procurement.spec.ts index aab13b6..ae6b90f 100644 --- a/test/procurement.spec.ts +++ b/test/procurement.spec.ts @@ -87,6 +87,19 @@ describe('supplier and material API', () => { .auth(ctx.token, auth) .expect(200); expect(activeOnly.body).toHaveLength(0); + const inactiveOnly = await ctx + .api() + .get('/api/v1/suppliers?active=false') + .auth(ctx.token, auth) + .expect(200); + expect(inactiveOnly.body.map((row: { id: string }) => row.id)).toContain( + supplier.body.id, + ); + await ctx + .api() + .get('/api/v1/suppliers?active=not-a-boolean') + .auth(ctx.token, auth) + .expect(400); expect( await ctx.db.auditEvent.count({ where: {