fix(procurement): parse active query filter exactly

This commit is contained in:
mihir 2026-09-23 00:09:22 +05:30
parent d3599036a6
commit a9dc62167f
3 changed files with 18 additions and 1 deletions

View File

@ -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 | | 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. 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. 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.

View File

@ -66,7 +66,10 @@ export const supplierMaterialSchema = z
.strict(); .strict();
export const procurementQuery = pageSchema export const procurementQuery = pageSchema
.extend({ .extend({
active: z.coerce.boolean().optional(), active: z
.enum(['true', 'false'])
.transform((value) => value === 'true')
.optional(),
search: text(100).optional(), search: text(100).optional(),
}) })
.strict(); .strict();

View File

@ -87,6 +87,19 @@ describe('supplier and material API', () => {
.auth(ctx.token, auth) .auth(ctx.token, auth)
.expect(200); .expect(200);
expect(activeOnly.body).toHaveLength(0); 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( expect(
await ctx.db.auditEvent.count({ await ctx.db.auditEvent.count({
where: { where: {