refactor(assignments): move workflows into use cases
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const assignmentSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
quantity: z.coerce.number().int().nonnegative().min(1, {
|
||||
error: "Quantity is required",
|
||||
}),
|
||||
notes: z.string().optional(),
|
||||
itemId: z
|
||||
.string()
|
||||
.min(1, {
|
||||
error: "Item is required",
|
||||
})
|
||||
.optional(),
|
||||
assetId: z.string().optional(),
|
||||
recipientId: z.string().min(1, {
|
||||
error: "Recipient is required",
|
||||
}),
|
||||
assignmentDate: z.date().optional(),
|
||||
returnDate: z.date().optional(),
|
||||
})
|
||||
|
||||
export const createAssignmentSchema = assignmentSchema.omit({
|
||||
id: true,
|
||||
returnDate: true,
|
||||
})
|
||||
export type CreateAssignmentFormType = z.input<typeof createAssignmentSchema>
|
||||
export type CreateAssignmentData = z.output<typeof createAssignmentSchema>
|
||||
|
||||
export const updateAssignmentSchema = assignmentSchema
|
||||
.omit({
|
||||
returnDate: true,
|
||||
})
|
||||
.superRefine((data, ctx) => {
|
||||
if (data.itemId && !data.assetId) {
|
||||
ctx.addIssue({
|
||||
code: "custom",
|
||||
message: "Asset ID is required when item ID is provided",
|
||||
path: ["assetId"],
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
export type UpdateAssignmentFormType = z.input<typeof updateAssignmentSchema>
|
||||
export type UpdateAssignmentData = z.output<typeof updateAssignmentSchema>
|
||||
|
||||
export const returnAssignmentSchema = z.object({
|
||||
id: z.string().min(1, {
|
||||
error: "Assignment ID is required",
|
||||
}),
|
||||
})
|
||||
export type ReturnAssignmentFormType = z.infer<typeof returnAssignmentSchema>
|
||||
@@ -0,0 +1,21 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const movementSchema = z.object({
|
||||
type: z.enum(["IN", "OUT", "ASSIGNMENT", "RETURN", "ADJUSTMENT"]),
|
||||
quantity: z.coerce.number().int().nonnegative().min(1, {
|
||||
error: "Quantity is required",
|
||||
}),
|
||||
details: z.string().optional(),
|
||||
notes: z.string().optional(),
|
||||
itemId: z.string().optional(),
|
||||
assetId: z.string().optional(),
|
||||
userId: z.string(),
|
||||
assignmentId: z.string().optional(),
|
||||
recipientId: z.string().optional(),
|
||||
})
|
||||
|
||||
export const createMovementSchema = movementSchema.omit({
|
||||
userId: true,
|
||||
})
|
||||
|
||||
export type CreateMovementFormType = z.infer<typeof createMovementSchema>
|
||||
Reference in New Issue
Block a user