@dakkitor/api-contracts 1.1.4 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actives.contract.d.ts","sourceRoot":"","sources":["../../contracts/actives/actives.contract.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,QAAA,MAAM,kBAAkB,qGAQtB,CAAC;AAEH,QAAA,MAAM,4BAA4B,8DAKhC,CAAC;AAEH,QAAA,MAAM,0BAA0B,oEAM9B,CAAC;AAEH,QAAA,MAAM,cAAc,gCAA8B,CAAC;AA+CnD,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuCM,CAAC;AAGhC,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQM,CAAC;AAGtC,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQM,CAAC;AAGtC,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4B7B,CAAC;AAEH,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIO,CAAC;AAGlD,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC9D,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAC1C,OAAO,4BAA4B,CACpC,CAAC;AACF,MAAM,MAAM,oBAAoB,G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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4FjC,CAAC"}
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.activesContractRouter = exports.PaginatedActiveResponseSchema = exports.FilterActiveSchema = exports.UpdateActiveSchema = exports.CreateActiveSchema = exports.ActiveSchema = void 0;
4
+ const zod_openapi_1 = require("@anatine/zod-openapi");
5
+ const core_1 = require("@ts-rest/core");
6
+ const zod_1 = require("zod");
7
+ const error_schemas_1 = require("../common/error-schemas");
8
+ const pagination_schema_1 = require("../common/pagination.schema");
9
+ (0, zod_openapi_1.extendZodWithOpenApi)(zod_1.z);
10
+ // Enums
11
+ const ActiveStatusSchema = zod_1.z.enum([
12
+ 'PENDING',
13
+ 'ACTIVE',
14
+ 'VACATION',
15
+ 'LEFT_THE_SITE',
16
+ 'MEDICAL_LEAVE',
17
+ 'DAY_OFF',
18
+ 'INJURY',
19
+ ]);
20
+ const ActiveStatusFilterTypeSchema = zod_1.z.enum([
21
+ 'SECOND_AGENT',
22
+ 'FIRST_AGENT',
23
+ 'BOTH',
24
+ 'EITHER',
25
+ ]);
26
+ const ActiveSortableFieldsSchema = zod_1.z.enum([
27
+ 'date',
28
+ 'payRate',
29
+ 'status',
30
+ 'createdAt',
31
+ 'updatedAt',
32
+ ]);
33
+ const RateUnitSchema = zod_1.z.enum(['DAILY', 'HOURLY']);
34
+ const SortOrderSchema = zod_1.z.enum(['ASC', 'DESC']);
35
+ // Common schemas
36
+ const DateRangeSchema = zod_1.z.object({
37
+ from: zod_1.z.string().datetime().optional(),
38
+ to: zod_1.z.string().datetime().optional(),
39
+ });
40
+ const PayRangeSchema = zod_1.z.object({
41
+ min: zod_1.z.number().min(0).optional().describe('Minimum pay rate'),
42
+ max: zod_1.z.number().min(0).optional().describe('Maximum pay rate'),
43
+ });
44
+ // Pay schema
45
+ const PaySchema = zod_1.z.object({
46
+ rate: zod_1.z.number().describe('Pay Rate'),
47
+ unit: RateUnitSchema.describe('Pay Unit'),
48
+ });
49
+ const WorkerPaySchema = zod_1.z.object({
50
+ rate: zod_1.z.number().min(0).describe('Pay Rate'),
51
+ unit: RateUnitSchema.describe('Pay Unit'),
52
+ });
53
+ // Simplified Booking schema (only fields needed for Active responses)
54
+ const BookingSchema = zod_1.z
55
+ .object({
56
+ id: zod_1.z.string().uuid().describe('Booking ID'),
57
+ // Add other booking fields as needed based on what's exposed in ActiveDto
58
+ })
59
+ .openapi({ title: 'Booking' });
60
+ // Active Status Filter
61
+ const ActiveStatusFilterSchema = zod_1.z
62
+ .object({
63
+ status: ActiveStatusSchema.optional().describe('Filter by status value'),
64
+ filterType: ActiveStatusFilterTypeSchema.optional()
65
+ .default('EITHER')
66
+ .describe('Status filter type: SECOND_AGENT (check only SA status), FIRST_AGENT (check only FA status), BOTH (both statuses must be the same), EITHER (either SA or FA status can match)'),
67
+ })
68
+ .openapi({ title: 'ActiveStatusFilter' });
69
+ // Main Active schema
70
+ exports.ActiveSchema = zod_1.z
71
+ .object({
72
+ id: zod_1.z.string().uuid().describe('Active Record ID'),
73
+ date: zod_1.z
74
+ .union([zod_1.z.string().date(), zod_1.z.date()])
75
+ .transform((val) => val instanceof Date ? val.toISOString().split('T')[0] : val)
76
+ .describe('Active Date'),
77
+ pay: PaySchema.describe('Pay Information'),
78
+ comment: zod_1.z.string().nullable().describe('Comment'),
79
+ statusSa: ActiveStatusSchema.describe('Second Agent Status'),
80
+ statusSaUpdatedAt: zod_1.z
81
+ .union([zod_1.z.string().datetime(), zod_1.z.date(), zod_1.z.null()])
82
+ .transform((val) => (val instanceof Date ? val.toISOString() : val))
83
+ .nullable()
84
+ .describe('SA Status Updated At'),
85
+ statusFa: ActiveStatusSchema.describe('First Agent Status'),
86
+ statusFaUpdatedAt: zod_1.z
87
+ .union([zod_1.z.string().datetime(), zod_1.z.date(), zod_1.z.null()])
88
+ .transform((val) => (val instanceof Date ? val.toISOString() : val))
89
+ .nullable()
90
+ .describe('FA Status Updated At'),
91
+ hoursWorked: zod_1.z.number().nullable().describe('Hours Worked'),
92
+ hoursWorkedUpdatedAt: zod_1.z
93
+ .union([zod_1.z.string().datetime(), zod_1.z.date(), zod_1.z.null()])
94
+ .transform((val) => (val instanceof Date ? val.toISOString() : val))
95
+ .nullable()
96
+ .describe('Hours Worked Updated At'),
97
+ booking: BookingSchema.describe('Associated Booking'),
98
+ createdAt: zod_1.z
99
+ .union([zod_1.z.string().datetime(), zod_1.z.date()])
100
+ .transform((val) => (val instanceof Date ? val.toISOString() : val))
101
+ .describe('Creation Date'),
102
+ updatedAt: zod_1.z
103
+ .union([zod_1.z.string().datetime(), zod_1.z.date()])
104
+ .transform((val) => (val instanceof Date ? val.toISOString() : val))
105
+ .describe('Last Update Date'),
106
+ })
107
+ .openapi({ title: 'Active' });
108
+ // Create Active schema
109
+ exports.CreateActiveSchema = zod_1.z
110
+ .object({
111
+ date: zod_1.z.string().date().describe('Select date'),
112
+ pay: WorkerPaySchema.describe('Pay rate and unit'),
113
+ comment: zod_1.z.string().optional().describe('Enter comment'),
114
+ statusSa: ActiveStatusSchema.optional().describe('Select SA status'),
115
+ statusFa: ActiveStatusSchema.optional().describe('Select FA status'),
116
+ })
117
+ .openapi({ title: 'CreateActive' });
118
+ // Update Active schema
119
+ exports.UpdateActiveSchema = zod_1.z
120
+ .object({
121
+ pay: WorkerPaySchema.optional().describe('Updated pay rate and unit'),
122
+ hoursWorked: zod_1.z.number().min(0).optional().describe('Updated hours worked'),
123
+ comment: zod_1.z.string().optional().describe('Updated comment'),
124
+ statusSa: ActiveStatusSchema.optional().describe('Updated SA status'),
125
+ statusFa: ActiveStatusSchema.optional().describe('Updated FA status'),
126
+ })
127
+ .openapi({ title: 'UpdateActive' });
128
+ // Filter Active schema
129
+ exports.FilterActiveSchema = zod_1.z.object({
130
+ limit: zod_1.z.coerce
131
+ .number()
132
+ .default(50)
133
+ .describe('The number of items to return per page'),
134
+ page: zod_1.z.coerce.number().default(1).describe('The page number to retrieve'),
135
+ bookingId: zod_1.z
136
+ .string()
137
+ .uuid()
138
+ .optional()
139
+ .nullable()
140
+ .describe('Filter by booking ID'),
141
+ date: DateRangeSchema.optional().nullable().describe('Filter by date range'),
142
+ pay: PayRangeSchema.optional()
143
+ .nullable()
144
+ .describe('Filter by pay rate range'),
145
+ status: ActiveStatusFilterSchema.optional()
146
+ .nullable()
147
+ .describe('Filter by status'),
148
+ createdAt: DateRangeSchema.optional()
149
+ .nullable()
150
+ .describe('Filter by created date range'),
151
+ sortBy: ActiveSortableFieldsSchema.optional()
152
+ .nullable()
153
+ .describe('The field to sort the results by'),
154
+ sortOrder: SortOrderSchema.optional()
155
+ .nullable()
156
+ .describe('The order to sort the results by'),
157
+ });
158
+ exports.PaginatedActiveResponseSchema = (0, pagination_schema_1.createPaginatedResponseSchema)(exports.ActiveSchema)
159
+ .describe('Active records retrieved successfully')
160
+ .openapi({ title: 'ActivesPaginatedResponse' });
161
+ // Contract
162
+ const c = (0, core_1.initContract)();
163
+ exports.activesContractRouter = c.router({
164
+ create: {
165
+ method: 'POST',
166
+ path: '/v2/bookings/:bookingId/actives',
167
+ responses: {
168
+ 201: exports.ActiveSchema,
169
+ 404: error_schemas_1.ErrorResponseSchema,
170
+ 409: error_schemas_1.ErrorResponseSchema,
171
+ },
172
+ pathParams: zod_1.z.object({
173
+ bookingId: zod_1.z.string().uuid().describe('Booking ID'),
174
+ }),
175
+ body: exports.CreateActiveSchema,
176
+ summary: 'Create a new active record for a specific booking',
177
+ metadata: {
178
+ tags: ['Actives'],
179
+ openApi: { operationId: 'createActiveForBooking' },
180
+ },
181
+ },
182
+ findAll: {
183
+ method: 'GET',
184
+ path: '/v2/actives',
185
+ responses: {
186
+ 200: exports.PaginatedActiveResponseSchema,
187
+ },
188
+ query: exports.FilterActiveSchema,
189
+ summary: 'Get all active records',
190
+ metadata: {
191
+ tags: ['Actives'],
192
+ openApi: { operationId: 'findAllActives' },
193
+ },
194
+ },
195
+ findOne: {
196
+ method: 'GET',
197
+ path: '/v2/actives/:id',
198
+ responses: {
199
+ 200: exports.ActiveSchema,
200
+ 404: error_schemas_1.ErrorResponseSchema,
201
+ },
202
+ pathParams: zod_1.z.object({
203
+ id: zod_1.z.string().uuid().describe('Active Record ID'),
204
+ }),
205
+ summary: 'Get an active record by ID',
206
+ metadata: {
207
+ tags: ['Actives'],
208
+ openApi: { operationId: 'findActiveById' },
209
+ },
210
+ },
211
+ update: {
212
+ method: 'PATCH',
213
+ path: '/v2/actives/:id',
214
+ responses: {
215
+ 200: exports.ActiveSchema,
216
+ 404: error_schemas_1.ErrorResponseSchema,
217
+ },
218
+ pathParams: zod_1.z.object({
219
+ id: zod_1.z.string().uuid().describe('Active Record ID'),
220
+ }),
221
+ body: exports.UpdateActiveSchema,
222
+ summary: 'Update an active record',
223
+ metadata: {
224
+ tags: ['Actives'],
225
+ openApi: { operationId: 'updateActive' },
226
+ },
227
+ },
228
+ remove: {
229
+ method: 'DELETE',
230
+ path: '/v2/actives/:id',
231
+ responses: {
232
+ 204: zod_1.z.undefined(),
233
+ 404: error_schemas_1.ErrorResponseSchema,
234
+ },
235
+ pathParams: zod_1.z.object({
236
+ id: zod_1.z.string().uuid().describe('Active Record ID'),
237
+ }),
238
+ body: c.noBody(),
239
+ summary: 'Delete an active record',
240
+ metadata: {
241
+ tags: ['Actives'],
242
+ openApi: { operationId: 'deleteActive' },
243
+ },
244
+ },
245
+ }, {
246
+ commonResponses: {
247
+ 400: error_schemas_1.ErrorResponseSchema,
248
+ 401: error_schemas_1.ErrorResponseSchema,
249
+ 403: error_schemas_1.ErrorResponseSchema,
250
+ 500: error_schemas_1.ErrorResponseSchema,
251
+ },
252
+ });