Skip to content

Commit

Permalink
(fix):O3-4209 Enhance stock operation validations to support negative…
Browse files Browse the repository at this point in the history
… stock adjustments (#240)
  • Loading branch information
makombe authored Nov 21, 2024
1 parent 3b0d9ec commit 91e084c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/stock-operations/add-stock-operation/validationSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,18 @@ export function useValidationSchema(operationType?: string) {
stockItems: z.array(customSchema),
});
}
if (operationType === 'adjustment') {
const customSchema = stockItemTableSchema.extend({
quantity: z.coerce
.number()
.refine((value) => value !== 0, {
message: 'Quantity cannot be zero.',
})
.or(z.literal(0, { invalid_type_error: 'Invalid quantity format' })),
});
return z.object({
stockItems: z.array(customSchema),
});
}
return stockOperationItemsSchema;
}

0 comments on commit 91e084c

Please sign in to comment.