@zyacreatives/shared 2.5.69 → 2.5.71

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.
@@ -1,88 +1,46 @@
1
+ // job.schemas.ts
2
+
1
3
  import { z } from "@hono/zod-openapi";
2
4
 
3
5
  import {
4
6
  EMPLOYMENT_TYPE,
5
- type EmploymentType,
6
7
  EXPERIENCE_LEVELS,
7
- type ExperienceLevel,
8
8
  GIG_TYPE,
9
- type GigType,
10
9
  JOB_LOCATIONS,
11
10
  JOB_SECTIONS,
12
11
  JOB_STATUS,
13
- type JobStatus,
14
12
  JOB_TYPE,
15
- type JobType,
16
13
  WAGES_CURRENCY,
17
- type WagesCurrency,
18
14
  WAGE_TYPES,
19
- type WageTypes,
20
15
  WORK_MODE,
21
- type WorkMode,
22
- JobLocation,
23
16
  } from "../constants";
24
17
 
25
18
  /**
26
19
  * --------------------------------
27
- * ENUMS
20
+ * SHAPE
28
21
  * --------------------------------
29
22
  */
30
23
 
31
- export const JobTypeSchema = z.enum(
32
- Object.values(JOB_TYPE) as [JobType, ...JobType[]],
33
- );
34
-
35
- export const EmploymentTypeSchema = z.enum(
36
- Object.values(EMPLOYMENT_TYPE) as [EmploymentType, ...EmploymentType[]],
37
- );
38
-
39
- export const WorkModeSchema = z.enum(
40
- Object.values(WORK_MODE) as [WorkMode, ...WorkMode[]],
41
- );
42
-
43
- export const JobStatusSchema = z.enum(
44
- Object.values(JOB_STATUS) as [JobStatus, ...JobStatus[]],
45
- );
46
-
47
- export const GigTypeSchema = z.enum(
48
- Object.values(GIG_TYPE) as [GigType, ...GigType[]],
49
- );
50
-
51
- export const JobLocationSchema = z.enum(
52
- Object.values(JOB_LOCATIONS) as [JobLocation, ...JobLocation[]],
53
- );
54
-
55
- export const ExperienceLevelSchema = z.enum(
56
- Object.values(EXPERIENCE_LEVELS) as [ExperienceLevel, ...ExperienceLevel[]],
57
- );
58
-
59
- export const WageCurrencySchema = z.enum(
60
- Object.values(WAGES_CURRENCY) as [WagesCurrency, ...WagesCurrency[]],
61
- );
62
-
63
- export const WageTypeSchema = z.enum(
64
- Object.values(WAGE_TYPES) as [WageTypes, ...WageTypes[]],
65
- );
66
-
67
- export const JobSectionSchema = z.enum(
68
- Object.values(JOB_SECTIONS) as [string, ...string[]],
69
- );
24
+ export const JobCleanupSchema = z.object({
25
+ maxApplications: z.number().int().positive().nullable().optional(),
26
+ maxHires: z.number().int().positive().nullable().optional(),
27
+ applicationDeadline: z.iso.datetime().nullable().optional(),
28
+ autoArchiveWhenFilled: z.boolean().default(true).optional(),
29
+ });
70
30
 
71
- /**
72
- * --------------------------------
73
- * SHAPE
74
- * --------------------------------
75
- */
31
+ export type JobCleanup = z.infer<typeof JobCleanupSchema>;
76
32
 
77
33
  export const JobShape = z.object({
78
34
  title: z.string().min(3).max(255),
79
35
  brandId: z.cuid2(),
80
- jobType: JobTypeSchema,
81
- employmentType: EmploymentTypeSchema.optional(),
82
- workMode: WorkModeSchema,
83
- gigType: GigTypeSchema.optional(),
84
- location: JobLocationSchema,
85
- jobSections: z.array(JobSectionSchema),
36
+ jobType: z.enum(JOB_TYPE),
37
+ employmentType: z.enum(EMPLOYMENT_TYPE).optional(),
38
+ workMode: z.enum(WORK_MODE),
39
+ gigType: z.enum(GIG_TYPE).optional(),
40
+ location: z.enum(JOB_LOCATIONS),
41
+ jobSections: z.array(z.enum(JOB_SECTIONS)),
42
+
43
+ ...JobCleanupSchema.shape,
86
44
  });
87
45
 
88
46
  export type JobShapeType = z.infer<typeof JobShape>;
@@ -99,7 +57,7 @@ export const JobEntitySchema = z
99
57
 
100
58
  ...JobShape.shape,
101
59
 
102
- status: JobStatusSchema,
60
+ status: z.enum(JOB_STATUS),
103
61
 
104
62
  brandName: z.string(),
105
63
  brandImgUrl: z.string().nullable().optional(),
@@ -115,6 +73,9 @@ export const JobEntitySchema = z
115
73
 
116
74
  export type JobEntity = z.infer<typeof JobEntitySchema>;
117
75
 
76
+ export const BaseJobEntitySchema = JobEntitySchema;
77
+ export type BaseJobEntity = z.infer<typeof BaseJobEntitySchema>;
78
+
118
79
  /**
119
80
  * --------------------------------
120
81
  * ROLE / GIG DETAILS
@@ -129,12 +90,14 @@ export const GigDetailsSchema = z.object({
129
90
  requiredSkills: z.array(z.string()),
130
91
  wagesMin: z.number().nullable().optional(),
131
92
  wagesMax: z.number().nullable().optional(),
132
- wagesCurrency: WageCurrencySchema.optional(),
133
- wagesType: WageTypeSchema.optional(),
93
+ wagesCurrency: z.enum(WAGES_CURRENCY).optional(),
94
+ wagesType: z.enum(WAGE_TYPES).optional(),
134
95
  });
135
96
 
97
+ export type GigDetails = z.infer<typeof GigDetailsSchema>;
98
+
136
99
  export const RoleDetailsSchema = z.object({
137
- experienceLevel: ExperienceLevelSchema,
100
+ experienceLevel: z.enum(EXPERIENCE_LEVELS),
138
101
  overview: z.string(),
139
102
  keyResponsibilities: z.string(),
140
103
  requiredSkills: z.array(z.string()),
@@ -142,21 +105,22 @@ export const RoleDetailsSchema = z.object({
142
105
  companyBenefits: z.string().optional(),
143
106
  wagesMin: z.number().nullable().optional(),
144
107
  wagesMax: z.number().nullable().optional(),
145
- wagesCurrency: WageCurrencySchema.optional(),
146
- wagesType: WageTypeSchema.optional(),
108
+ wagesCurrency: z.enum(WAGES_CURRENCY).optional(),
109
+ wagesType: z.enum(WAGE_TYPES).optional(),
147
110
  });
148
111
 
112
+ export type RoleDetails = z.infer<typeof RoleDetailsSchema>;
113
+
149
114
  /**
150
115
  * --------------------------------
151
116
  * DETAILED ENTITIES
152
117
  * --------------------------------
153
118
  */
154
119
 
155
-
156
120
  export const GigJobEntitySchema = JobEntitySchema.extend({
157
121
  jobType: z.literal(JOB_TYPE.GIG),
158
- gigType: GigTypeSchema,
159
- employmentType: EmploymentTypeSchema.optional(),
122
+ gigType: z.enum(GIG_TYPE),
123
+ employmentType: z.enum(EMPLOYMENT_TYPE).optional(),
160
124
  ...GigDetailsSchema.shape,
161
125
  }).openapi("GigJob");
162
126
 
@@ -164,8 +128,8 @@ export type GigJobEntity = z.infer<typeof GigJobEntitySchema>;
164
128
 
165
129
  export const RoleJobEntitySchema = JobEntitySchema.extend({
166
130
  jobType: z.literal(JOB_TYPE.ROLE),
167
- employmentType: EmploymentTypeSchema,
168
- gigType: GigTypeSchema.optional(),
131
+ employmentType: z.enum(EMPLOYMENT_TYPE),
132
+ gigType: z.enum(GIG_TYPE).optional(),
169
133
  ...RoleDetailsSchema.shape,
170
134
  }).openapi("RoleJob");
171
135
 
@@ -182,10 +146,6 @@ export type JobWithRoleDetailsEntity = RoleJobEntity;
182
146
 
183
147
  /**
184
148
  * Keep this as a regular union.
185
- *
186
- * Do not use discriminatedUnion here because JobEntitySchema has jobType as
187
- * "GIG" | "ROLE", while GigJobEntitySchema and RoleJobEntitySchema use
188
- * literals. That makes the discriminator ambiguous.
189
149
  */
190
150
  export const NormalizedJobSchema = z.union([
191
151
  GigJobEntitySchema,
@@ -201,6 +161,12 @@ export type NormalizedJobEntity = z.infer<typeof NormalizedJobSchema>;
201
161
  * --------------------------------
202
162
  */
203
163
 
164
+ export const JobIdSchema = z.object({
165
+ jobId: z.cuid2().openapi({ param: { name: "jobId", in: "path" } }),
166
+ });
167
+
168
+ export type JobId = z.infer<typeof JobIdSchema>;
169
+
204
170
  export const CreateJobInputSchema = JobShape.superRefine((data, ctx) => {
205
171
  if (data.jobType === JOB_TYPE.ROLE && !data.employmentType) {
206
172
  ctx.addIssue({
@@ -223,15 +189,42 @@ export type CreateJobInput = z.infer<typeof CreateJobInputSchema>;
223
189
 
224
190
  export const UpdateJobInputSchema = CreateJobInputSchema.partial().extend({
225
191
  id: z.cuid2(),
226
- status: JobStatusSchema.optional(),
192
+ status: z.enum(JOB_STATUS).optional(),
227
193
  version: z.int(),
228
194
  });
229
195
 
230
196
  export type UpdateJobInput = z.infer<typeof UpdateJobInputSchema>;
231
197
 
198
+ export const CreateGigJobInputSchema = GigDetailsSchema.extend({
199
+ id: z.cuid2(),
200
+ });
201
+
202
+ export type CreateGigJobInput = z.infer<typeof CreateGigJobInputSchema>;
203
+
204
+ export const UpdateGigJobInputSchema = CreateGigJobInputSchema.partial().extend({
205
+ id: z.cuid2(),
206
+ version: z.int().default(1),
207
+ });
208
+
209
+ export type UpdateGigJobInput = z.infer<typeof UpdateGigJobInputSchema>;
210
+
211
+ export const CreateRoleJobInputSchema = RoleDetailsSchema.extend({
212
+ id: z.cuid2(),
213
+ });
214
+
215
+ export type CreateRoleJobInput = z.infer<typeof CreateRoleJobInputSchema>;
216
+
217
+ export const UpdateRoleJobInputSchema =
218
+ CreateRoleJobInputSchema.partial().extend({
219
+ id: z.cuid2(),
220
+ version: z.int().default(1),
221
+ });
222
+
223
+ export type UpdateRoleJobInput = z.infer<typeof UpdateRoleJobInputSchema>;
224
+
232
225
  export const GetJobsInputSchema = z.object({
233
226
  q: z.string().optional(),
234
- jobType: JobTypeSchema.optional(),
227
+ jobType: z.enum(JOB_TYPE).optional(),
235
228
  page: z.coerce.number().min(1).default(1),
236
229
  limit: z.coerce.number().min(1).max(100).default(20),
237
230
  });
@@ -256,6 +249,15 @@ export const GetJobsOutputSchema = z.object({
256
249
 
257
250
  export type GetJobsOutput = z.infer<typeof GetJobsOutputSchema>;
258
251
 
252
+ export const GetCreatedJobsOutputSchema = z.object({
253
+ jobs: z.array(NormalizedJobSchema),
254
+ noOfJobs: z.number(),
255
+ noOfArchivedJobs: z.number(),
256
+ noOfActiveJobs: z.number(),
257
+ });
258
+
259
+ export type GetCreatedJobsOutput = z.infer<typeof GetCreatedJobsOutputSchema>;
260
+
259
261
  /**
260
262
  * --------------------------------
261
263
  * SEARCH DOCUMENT
@@ -270,65 +272,21 @@ export const JobSearchDocumentSchema = z
270
272
  brandId: z.cuid2(),
271
273
  brandName: z.string(),
272
274
  brandImgUrl: z.string().nullable().optional(),
273
- jobType: z.enum(["GIG", "ROLE"]),
274
- status: z.string().optional(),
275
- employmentType: z.string().nullable().optional(),
276
- workMode: z.string(),
277
- gigType: z.string().nullable().optional(),
278
- location: z.string(),
275
+ jobType: z.enum(JOB_TYPE),
276
+ status: z.enum(JOB_STATUS).optional(),
277
+ employmentType: z.enum(EMPLOYMENT_TYPE).nullable().optional(),
278
+ workMode: z.enum(WORK_MODE),
279
+ gigType: z.enum(GIG_TYPE).nullable().optional(),
280
+ location: z.enum(JOB_LOCATIONS),
279
281
  overview: z.string(),
280
282
  requiredSkills: z.array(z.string()),
281
283
  wagesMin: z.number().nullable().optional(),
282
284
  wagesMax: z.number().nullable().optional(),
283
- wagesCurrency: z.string().nullable().optional(),
284
- wagesType: z.string().nullable().optional(),
285
+ wagesCurrency: z.enum(WAGES_CURRENCY).nullable().optional(),
286
+ wagesType: z.enum(WAGE_TYPES).nullable().optional(),
285
287
  createdAt: z.string(),
286
288
  updatedAt: z.string(),
287
289
  })
288
290
  .openapi("JobSearchDocument");
289
291
 
290
- export type JobSearchDocument = z.infer<typeof JobSearchDocumentSchema>;
291
-
292
- export const JobIdSchema = z.object({
293
- jobId: z.cuid2().openapi({ param: { name: "jobId", in: "path" } }),
294
- });
295
-
296
- export type JobId = z.infer<typeof JobIdSchema>;
297
-
298
- export const BaseJobEntitySchema = JobEntitySchema;
299
- export type BaseJobEntity = z.infer<typeof BaseJobEntitySchema>;
300
-
301
- export const CreateGigJobInputSchema = GigDetailsSchema.extend({
302
- id: z.cuid2(),
303
- });
304
-
305
- export type CreateGigJobInput = z.infer<typeof CreateGigJobInputSchema>;
306
-
307
- export const UpdateGigJobInputSchema = CreateGigJobInputSchema.partial().extend({
308
- id: z.cuid2(),
309
- version: z.int().default(1),
310
- });
311
-
312
- export type UpdateGigJobInput = z.infer<typeof UpdateGigJobInputSchema>;
313
-
314
- export const CreateRoleJobInputSchema = RoleDetailsSchema.extend({
315
- id: z.cuid2(),
316
- });
317
-
318
- export type CreateRoleJobInput = z.infer<typeof CreateRoleJobInputSchema>;
319
-
320
- export const UpdateRoleJobInputSchema = CreateRoleJobInputSchema.partial().extend({
321
- id: z.cuid2(),
322
- version: z.int().default(1),
323
- });
324
-
325
- export type UpdateRoleJobInput = z.infer<typeof UpdateRoleJobInputSchema>;
326
-
327
- export const GetCreatedJobsOutputSchema = z.object({
328
- jobs: z.array(NormalizedJobSchema),
329
- noOfJobs: z.number(),
330
- noOfArchivedJobs: z.number(),
331
- noOfActiveJobs: z.number(),
332
- });
333
-
334
- export type GetCreatedJobsOutput = z.infer<typeof GetCreatedJobsOutputSchema>;
292
+ export type JobSearchDocument = z.infer<typeof JobSearchDocumentSchema>;