api: introduce schemas for new care actions
Pedro Lucas Porcellis porcellis@eletrotupi.com · 4 months ago
b4b88475b5701079de2ba2dcb338c6519f8ad7a5 Browse filesParents
f17ee88Changed files
3
Additions
+82
Deletions
0
/dev/null → api/src/schemas/careAction.schema.ts
1 +
import { z } from 'zod';
2 +
import {
3 +
CareActionType,
4 +
AppointmentType,
5 +
ActivityType,
6 +
MedicinePeriodicity,
7 +
} from '@prisma/client';
8 +
9 +
const MedicineInlineSchema = z.object({
10 +
name: z.string().min(1),
11 +
dosage: z.string().min(1),
12 +
periodicity: z.nativeEnum(MedicinePeriodicity),
13 +
scheduledAt: z.string().optional(),
14 +
});
15 +
16 +
export const CreateCareActionSchema = z.object({
17 +
type: z.nativeEnum(CareActionType),
18 +
moment: z.coerce.date(),
19 +
triggerId: z.number().int().positive().optional(),
20 +
moodId: z.number().int().positive().optional(),
21 +
22 +
// MEDICINE fields
23 +
regimenId: z.number().int().positive().optional(),
24 +
medicine: MedicineInlineSchema.optional(),
25 +
26 +
// APPOINTMENT fields
27 +
appointment: z
28 +
.object({
29 +
type: z.nativeEnum(AppointmentType),
30 +
duration: z.number().int().positive(),
31 +
note: z.string().optional(),
32 +
})
33 +
.optional(),
34 +
35 +
// ACTIVITY fields
36 +
activity: z
37 +
.object({
38 +
type: z.nativeEnum(ActivityType),
39 +
duration: z.number().int().positive().optional(),
40 +
})
41 +
.optional(),
42 +
});
43 +
44 +
export type CreateCareActionInput = z.infer<typeof CreateCareActionSchema>;
api/src/schemas/index.ts
1 1
export {
2 2
CreateMoodSchema,
3 3
MoodComponentSchema,
4 4
} from "@app/schemas/mood.schema";
5 5
39 39
40 40
export {
41 41
InsightsQuerySchema,
42 42
type InsightsQueryInput,
43 43
} from "@app/schemas/insight.schema";
44 +
45 +
export {
46 +
LinkMoodSchema,
47 +
type LinkMoodInput,
48 +
} from "@app/schemas/triggerMoodLink.schema";
49 +
50 +
export {
51 +
CreateCareActionSchema,
52 +
type CreateCareActionInput,
53 +
} from "@app/schemas/careAction.schema";
54 +
55 +
export {
56 +
CreateMedicineRegimenSchema,
57 +
type CreateMedicineRegimenInput,
58 +
UpdateMedicineRegimenSchema,
59 +
type UpdateMedicineRegimenInput,
60 +
} from "@app/schemas/medicineRegimen.schema";
/dev/null → api/src/schemas/medicineRegimen.schema.ts
1 +
import { z } from 'zod';
2 +
import { MedicinePeriodicity } from '@prisma/client';
3 +
4 +
export const CreateMedicineRegimenSchema = z.object({
5 +
name: z.string().min(1),
6 +
dosage: z.string().min(1),
7 +
periodicity: z.nativeEnum(MedicinePeriodicity),
8 +
scheduledAt: z.string().optional(),
9 +
});
10 +
11 +
export type CreateMedicineRegimenInput = z.infer<typeof CreateMedicineRegimenSchema>;
12 +
13 +
export const UpdateMedicineRegimenSchema = z.object({
14 +
name: z.string().min(1).optional(),
15 +
dosage: z.string().min(1).optional(),
16 +
periodicity: z.nativeEnum(MedicinePeriodicity).optional(),
17 +
scheduledAt: z.string().optional(),
18 +
active: z.boolean().optional(),
19 +
});
20 +
21 +
export type UpdateMedicineRegimenInput = z.infer<typeof UpdateMedicineRegimenSchema>;