Types
All types should be defined in the @tms/shared package, using the database table definitions as a base, these are imported from the @tms/db package.
Here is an example of a complex type, the ServiceOrder type:
import { createSelectSchema, serviceOrder } from '@tms/db'
import { serviceOrderCategorySchema, serviceOrderStatusLUSchema, serviceOrderTypeSchema } from './serviceOrderLUs'
// Other imports
/*
Here we extend the base serviceOrder schema created with `createSelectSchema` with the schemas of the related entities
These are not included when using `createSelectSchema` because of performance reasons.
So we need to include them manually.
*/
export const serviceOrderSchema = createSelectSchema(serviceOrder, { createdAt: z.coerce.date() }).extend({
status: serviceOrderStatusLUSchema.pick({
id: true,
name: true,
description: true,
}),
assist: assistSchema.pick({
id: true,
name: true,
slug: true,
}),
organization: organizationSchema.pick({
id: true,
name: true,
}),
serviceOrderCategory: serviceOrderCategorySchema.pick({
id: true,
name: true,
description: true,
}),
fareType: fareTypeSchema.pick({
id: true,
name: true,
}),
damageType: damageTypeSchema.pick({
id: true,
name: true,
}),
serviceOrderType: serviceOrderTypeSchema.pick({
id: true,
name: true,
description: true,
}),
car: carInformationSchema.omit({
createdAt: true,
updatedAt: true,
}),
contactInformation: newContactInformationSchema,
createdBy: userSchema.pick({
id: true,
username: true,
name: true,
paternalLastName: true,
maternalLastName: true,
}),
assignment: assignmentSchema.nullable().optional(),
originAddress: addressSchema,
destinationAddress: addressSchema,
})Last updated on