@dakkitor/api-contracts 1.1.8 → 1.1.10

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":"bookings.contract.d.ts","sourceRoot":"","sources":["../../contracts/bookings/bookings.contract.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,eAAO,MAAM,mBAAmB,usBA2BM,CAAC;AAEvC,eAAO,MAAM,2BAA2B,8DAEM,CAAC;AAG/C,eAAO,MAAM,gBAAgB;;;;;;;;;EAKM,CAAC;AAEpC,eAAO,MAAM,gBAAgB;;;;;;EAIM,CAAC;AAEpC,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQM,CAAC;AAErC,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;EA2BM,CAAC;AAG5C,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;EAK5B,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;EAI9B,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;EAG3B,CAAC;AAGH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4BM,CAAC;AAEjC,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKM,CAAC;AAEvC,eAAO,MAAM,mBAAmB;;;;;;;;;;;;EAMM,CAAC;AAEvC,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyFlC,CAAC"}
@@ -0,0 +1,286 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bookingsContractRouter = exports.PaginatedBookingResponseSchema = exports.FilterBookingSchema = exports.UpdateBookingSchema = exports.CreateBookingSchema = exports.BookingSchema = exports.BookingJobSchema = exports.BookingWorkerSchema = exports.BookingUserSchema = exports.FilterJobInBookingSchema = exports.BookingItemSchema = exports.ResourceIdSchema = exports.BookingPaySchema = exports.BookingSortableFieldsSchema = exports.BookingStatusSchema = 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 common_schemas_1 = require("../common/common-schemas");
8
+ const error_schemas_1 = require("../common/error-schemas");
9
+ const pagination_query_schema_1 = require("../common/pagination-query.schema");
10
+ const pagination_schema_1 = require("../common/pagination.schema");
11
+ (0, zod_openapi_1.extendZodWithOpenApi)(zod_1.z);
12
+ // Enum Schemas
13
+ exports.BookingStatusSchema = zod_1.z
14
+ .enum([
15
+ 'JOB_CANCELLED',
16
+ 'REFUSED_BY_CLIENT',
17
+ 'REFUSED_BY_FIRST_BECAUSE_OF_NATIONALITY',
18
+ 'REFUSED_BY_FIRST_NOT_ENOUGH_EXPERIENCE',
19
+ 'REFUSED_BY_FIRST_JOB_FILLED',
20
+ 'REFUSED_BY_FIRST_IGNORED_DENIED',
21
+ 'REFUSED_BY_FIRST_BECAUSE_OF_DISTANCE',
22
+ 'WAITING_FOR_CONFIRMATION',
23
+ 'DIDNT_START_BECAUSE_OF_WORKER',
24
+ 'DIDNT_START_BECAUSE_OF_US',
25
+ 'DIDNT_START_BECAUSE_OF_CONSTRUCTION_SITE',
26
+ 'DIDNT_START_BECAUSE_OF_AGENCY',
27
+ 'DIDNT_START_BECAUSE_OF_TOOLS_REQUIREMENTS',
28
+ 'DIDNT_START_OVERBOOK_BY_CLIENT',
29
+ 'DIDNT_START_OVERBOOK_BY_US',
30
+ 'ANOTHER_SITUATION',
31
+ 'CONFIRMED_OVERBOOK',
32
+ 'CONFIRMED',
33
+ 'YELLOW_FOR_TOMORROW',
34
+ 'SPOKE_WITH_WORKER_IN_THE_MORNING',
35
+ 'ON_THE_WAY_TO_THE_SITE',
36
+ 'AT_THE_INDUCTION',
37
+ 'STARTED_THE_JOB',
38
+ 'COMPLETED',
39
+ ])
40
+ .openapi({ title: 'BookingStatus' });
41
+ exports.BookingSortableFieldsSchema = zod_1.z
42
+ .enum(['status', 'startDate', 'createdAt', 'updatedAt'])
43
+ .openapi({ title: 'BookingSortableFields' });
44
+ // Nested Schemas
45
+ exports.BookingPaySchema = zod_1.z
46
+ .object({
47
+ rate: zod_1.z.number().describe('Pay Rate'),
48
+ unit: common_schemas_1.RateUnitSchema.describe('Pay Unit'),
49
+ })
50
+ .openapi({ title: 'BookingPay' });
51
+ exports.ResourceIdSchema = zod_1.z
52
+ .object({
53
+ id: zod_1.z.string().uuid().describe('Resource ID'),
54
+ })
55
+ .openapi({ title: 'ResourceId' });
56
+ exports.BookingItemSchema = zod_1.z
57
+ .object({
58
+ worker: exports.ResourceIdSchema.describe('Worker to Book'),
59
+ startDate: zod_1.z.string().datetime().describe('Start Date'),
60
+ endDate: zod_1.z.string().datetime().nullable().optional().describe('End Date'),
61
+ status: exports.BookingStatusSchema.optional().describe('Booking Status'),
62
+ pay: exports.BookingPaySchema.optional().describe('Pay Information'),
63
+ })
64
+ .openapi({ title: 'BookingItem' });
65
+ exports.FilterJobInBookingSchema = zod_1.z
66
+ .object({
67
+ userId: zod_1.z
68
+ .string()
69
+ .uuid()
70
+ .optional()
71
+ .nullable()
72
+ .describe('Filter by User ID'),
73
+ clientId: zod_1.z
74
+ .string()
75
+ .uuid()
76
+ .optional()
77
+ .nullable()
78
+ .describe('Filter by Client ID'),
79
+ companyId: zod_1.z
80
+ .string()
81
+ .uuid()
82
+ .optional()
83
+ .nullable()
84
+ .describe('Filter by Company ID'),
85
+ tradeId: zod_1.z
86
+ .string()
87
+ .uuid()
88
+ .optional()
89
+ .nullable()
90
+ .describe('Filter by Trade ID'),
91
+ })
92
+ .openapi({ title: 'FilterJobInBooking' });
93
+ // Simplified schemas for related entities (to avoid circular dependencies)
94
+ exports.BookingUserSchema = zod_1.z.object({
95
+ id: zod_1.z.string().uuid(),
96
+ firstName: zod_1.z.string(),
97
+ lastName: zod_1.z.string(),
98
+ email: zod_1.z.string().email(),
99
+ });
100
+ exports.BookingWorkerSchema = zod_1.z.object({
101
+ id: zod_1.z.string().uuid(),
102
+ firstName: zod_1.z.string(),
103
+ lastName: zod_1.z.string(),
104
+ });
105
+ exports.BookingJobSchema = zod_1.z.object({
106
+ id: zod_1.z.string().uuid(),
107
+ title: zod_1.z.string(),
108
+ });
109
+ // Main Schemas
110
+ exports.BookingSchema = zod_1.z
111
+ .object({
112
+ id: zod_1.z.string().uuid().describe('Booking ID'),
113
+ status: exports.BookingStatusSchema.describe('Booking Status'),
114
+ startDate: zod_1.z
115
+ .union([zod_1.z.string().datetime(), zod_1.z.date()])
116
+ .transform((val) => (val instanceof Date ? val.toISOString() : val))
117
+ .describe('Start Date'),
118
+ endDate: zod_1.z
119
+ .union([zod_1.z.string().datetime(), zod_1.z.date(), zod_1.z.null()])
120
+ .transform((val) => (val instanceof Date ? val.toISOString() : val))
121
+ .nullable()
122
+ .optional()
123
+ .describe('End Date'),
124
+ worker: exports.BookingWorkerSchema.describe('Worker'),
125
+ user: exports.BookingUserSchema.describe('User'),
126
+ pay: exports.BookingPaySchema.describe('Pay Information'),
127
+ job: exports.BookingJobSchema.describe('Job'),
128
+ userId: zod_1.z.string().uuid().describe('User ID'),
129
+ createdAt: zod_1.z
130
+ .union([zod_1.z.string().datetime(), zod_1.z.date()])
131
+ .transform((val) => (val instanceof Date ? val.toISOString() : val))
132
+ .describe('Creation Date'),
133
+ updatedAt: zod_1.z
134
+ .union([zod_1.z.string().datetime(), zod_1.z.date()])
135
+ .transform((val) => (val instanceof Date ? val.toISOString() : val))
136
+ .describe('Last Update Date'),
137
+ })
138
+ .openapi({ title: 'Booking' });
139
+ exports.CreateBookingSchema = zod_1.z
140
+ .object({
141
+ job: exports.ResourceIdSchema.describe('Job'),
142
+ bookings: zod_1.z.array(exports.BookingItemSchema).describe('List of Workers to Book'),
143
+ })
144
+ .openapi({ title: 'CreateBooking' });
145
+ exports.UpdateBookingSchema = zod_1.z
146
+ .object({
147
+ startDate: zod_1.z.string().datetime().optional().describe('Start Date'),
148
+ endDate: zod_1.z.string().datetime().optional().describe('End Date'),
149
+ status: exports.BookingStatusSchema.optional().describe('Booking Status'),
150
+ })
151
+ .openapi({ title: 'UpdateBooking' });
152
+ exports.FilterBookingSchema = pagination_query_schema_1.PaginationQuerySchema.extend({
153
+ workerName: zod_1.z
154
+ .string()
155
+ .optional()
156
+ .nullable()
157
+ .describe('Fuzzy search by worker full name'),
158
+ job: exports.FilterJobInBookingSchema.optional()
159
+ .nullable()
160
+ .describe('Filter by job details'),
161
+ createdAt: common_schemas_1.DateRangeSchema.optional()
162
+ .nullable()
163
+ .describe('Filter by created date range'),
164
+ startDate: common_schemas_1.DateRangeSchema.optional()
165
+ .nullable()
166
+ .describe('Filter by start date range'),
167
+ endDate: common_schemas_1.DateRangeSchema.optional()
168
+ .nullable()
169
+ .describe('Filter by end date range'),
170
+ sortBy: exports.BookingSortableFieldsSchema.optional()
171
+ .nullable()
172
+ .describe('Field to sort by'),
173
+ sortOrder: common_schemas_1.SortOrderSchema.optional().nullable().describe('Sort order'),
174
+ status: exports.BookingStatusSchema.optional()
175
+ .nullable()
176
+ .describe('Filter by status'),
177
+ clientId: zod_1.z
178
+ .string()
179
+ .uuid()
180
+ .optional()
181
+ .nullable()
182
+ .describe('Filter by Client ID'),
183
+ companyId: zod_1.z
184
+ .string()
185
+ .uuid()
186
+ .optional()
187
+ .nullable()
188
+ .describe('Filter by Company ID'),
189
+ agentName: zod_1.z
190
+ .string()
191
+ .optional()
192
+ .nullable()
193
+ .describe('Fuzzy search by agent name'),
194
+ });
195
+ exports.PaginatedBookingResponseSchema = (0, pagination_schema_1.createPaginatedResponseSchema)(exports.BookingSchema)
196
+ .describe('Bookings retrieved successfully')
197
+ .openapi({ title: 'BookingsPaginatedResponse' });
198
+ // Contract Definition
199
+ const c = (0, core_1.initContract)();
200
+ exports.bookingsContractRouter = c.router({
201
+ create: {
202
+ method: 'POST',
203
+ path: '/v2/bookings',
204
+ responses: {
205
+ 201: zod_1.z.array(exports.BookingSchema),
206
+ 409: error_schemas_1.ErrorResponseSchema,
207
+ },
208
+ body: exports.CreateBookingSchema,
209
+ summary: 'Create new bookings (bulk operation)',
210
+ metadata: {
211
+ tags: ['Bookings'],
212
+ openApi: { operationId: 'createBookings' },
213
+ },
214
+ },
215
+ findAll: {
216
+ method: 'GET',
217
+ path: '/v2/bookings',
218
+ responses: {
219
+ 200: exports.PaginatedBookingResponseSchema,
220
+ },
221
+ query: exports.FilterBookingSchema,
222
+ summary: 'Get all bookings',
223
+ metadata: {
224
+ tags: ['Bookings'],
225
+ openApi: { operationId: 'findAllBookings' },
226
+ },
227
+ },
228
+ findOne: {
229
+ method: 'GET',
230
+ path: '/v2/bookings/:id',
231
+ responses: {
232
+ 200: exports.BookingSchema,
233
+ 404: error_schemas_1.ErrorResponseSchema,
234
+ },
235
+ pathParams: zod_1.z.object({
236
+ id: zod_1.z.string().uuid().describe('Booking ID'),
237
+ }),
238
+ summary: 'Get a booking by ID',
239
+ metadata: {
240
+ tags: ['Bookings'],
241
+ openApi: { operationId: 'findBookingById' },
242
+ },
243
+ },
244
+ update: {
245
+ method: 'PATCH',
246
+ path: '/v2/bookings/:id',
247
+ responses: {
248
+ 200: exports.BookingSchema,
249
+ 404: error_schemas_1.ErrorResponseSchema,
250
+ 409: error_schemas_1.ErrorResponseSchema,
251
+ },
252
+ pathParams: zod_1.z.object({
253
+ id: zod_1.z.string().uuid().describe('Booking ID'),
254
+ }),
255
+ body: exports.UpdateBookingSchema,
256
+ summary: 'Update a booking',
257
+ metadata: {
258
+ tags: ['Bookings'],
259
+ openApi: { operationId: 'updateBooking' },
260
+ },
261
+ },
262
+ remove: {
263
+ method: 'DELETE',
264
+ path: '/v2/bookings/:id',
265
+ responses: {
266
+ 204: zod_1.z.undefined(),
267
+ 404: error_schemas_1.ErrorResponseSchema,
268
+ },
269
+ pathParams: zod_1.z.object({
270
+ id: zod_1.z.string().uuid().describe('Booking ID'),
271
+ }),
272
+ body: c.noBody(),
273
+ summary: 'Delete a booking',
274
+ metadata: {
275
+ tags: ['Bookings'],
276
+ openApi: { operationId: 'deleteBooking' },
277
+ },
278
+ },
279
+ }, {
280
+ commonResponses: {
281
+ 400: error_schemas_1.ErrorResponseSchema,
282
+ 401: error_schemas_1.ErrorResponseSchema,
283
+ 403: error_schemas_1.ErrorResponseSchema,
284
+ 500: error_schemas_1.ErrorResponseSchema,
285
+ },
286
+ });