vr-commons 1.0.143 → 1.0.144
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,8 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export declare const PAIR_ID_REGEX: RegExp;
|
|
3
3
|
export declare const validateUniquePairIds: (pairIds: string[]) => boolean;
|
|
4
|
-
export declare const createDevicePairsSchema: z.
|
|
5
|
-
body: z.ZodObject<{
|
|
4
|
+
export declare const createDevicePairsSchema: z.ZodObject<{
|
|
5
|
+
body: z.ZodEffects<z.ZodObject<{
|
|
6
6
|
productId: z.ZodString;
|
|
7
7
|
pairIds: z.ZodArray<z.ZodString, "many">;
|
|
8
8
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -11,6 +11,12 @@ export declare const createDevicePairsSchema: z.ZodEffects<z.ZodObject<{
|
|
|
11
11
|
}, {
|
|
12
12
|
productId: string;
|
|
13
13
|
pairIds: string[];
|
|
14
|
+
}>, {
|
|
15
|
+
productId: string;
|
|
16
|
+
pairIds: string[];
|
|
17
|
+
}, {
|
|
18
|
+
productId: string;
|
|
19
|
+
pairIds: string[];
|
|
14
20
|
}>;
|
|
15
21
|
}, "strip", z.ZodTypeAny, {
|
|
16
22
|
body: {
|
|
@@ -22,15 +28,27 @@ export declare const createDevicePairsSchema: z.ZodEffects<z.ZodObject<{
|
|
|
22
28
|
productId: string;
|
|
23
29
|
pairIds: string[];
|
|
24
30
|
};
|
|
25
|
-
}
|
|
31
|
+
}>;
|
|
32
|
+
export declare const createDeviceSchema: z.ZodObject<{
|
|
33
|
+
body: z.ZodObject<{
|
|
34
|
+
serialNumber: z.ZodString;
|
|
35
|
+
productId: z.ZodString;
|
|
36
|
+
}, "strip", z.ZodTypeAny, {
|
|
37
|
+
productId: string;
|
|
38
|
+
serialNumber: string;
|
|
39
|
+
}, {
|
|
40
|
+
productId: string;
|
|
41
|
+
serialNumber: string;
|
|
42
|
+
}>;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
44
|
body: {
|
|
27
45
|
productId: string;
|
|
28
|
-
|
|
46
|
+
serialNumber: string;
|
|
29
47
|
};
|
|
30
48
|
}, {
|
|
31
49
|
body: {
|
|
32
50
|
productId: string;
|
|
33
|
-
|
|
51
|
+
serialNumber: string;
|
|
34
52
|
};
|
|
35
53
|
}>;
|
|
36
54
|
export declare const updateDeviceSchema: z.ZodObject<{
|
|
@@ -103,8 +121,8 @@ export declare const getDevicesSchema: z.ZodObject<{
|
|
|
103
121
|
sortBy: z.ZodOptional<z.ZodEnum<["serialNumber", "status", "createdAt", "updatedAt"]>>;
|
|
104
122
|
sortOrder: z.ZodOptional<z.ZodEnum<["ASC", "DESC"]>>;
|
|
105
123
|
}, "strip", z.ZodTypeAny, {
|
|
106
|
-
status?: "locked" | "unlocked" | "disabled" | undefined;
|
|
107
124
|
productId?: string | undefined;
|
|
125
|
+
status?: "locked" | "unlocked" | "disabled" | undefined;
|
|
108
126
|
dedicatedUser?: "PASSENGER" | "RIDER" | "N/A" | undefined;
|
|
109
127
|
page?: number | undefined;
|
|
110
128
|
limit?: number | undefined;
|
|
@@ -114,8 +132,8 @@ export declare const getDevicesSchema: z.ZodObject<{
|
|
|
114
132
|
sortBy?: "status" | "serialNumber" | "createdAt" | "updatedAt" | undefined;
|
|
115
133
|
sortOrder?: "ASC" | "DESC" | undefined;
|
|
116
134
|
}, {
|
|
117
|
-
status?: "locked" | "unlocked" | "disabled" | undefined;
|
|
118
135
|
productId?: string | undefined;
|
|
136
|
+
status?: "locked" | "unlocked" | "disabled" | undefined;
|
|
119
137
|
dedicatedUser?: "PASSENGER" | "RIDER" | "N/A" | undefined;
|
|
120
138
|
page?: string | undefined;
|
|
121
139
|
limit?: string | undefined;
|
|
@@ -127,8 +145,8 @@ export declare const getDevicesSchema: z.ZodObject<{
|
|
|
127
145
|
}>;
|
|
128
146
|
}, "strip", z.ZodTypeAny, {
|
|
129
147
|
query: {
|
|
130
|
-
status?: "locked" | "unlocked" | "disabled" | undefined;
|
|
131
148
|
productId?: string | undefined;
|
|
149
|
+
status?: "locked" | "unlocked" | "disabled" | undefined;
|
|
132
150
|
dedicatedUser?: "PASSENGER" | "RIDER" | "N/A" | undefined;
|
|
133
151
|
page?: number | undefined;
|
|
134
152
|
limit?: number | undefined;
|
|
@@ -140,8 +158,8 @@ export declare const getDevicesSchema: z.ZodObject<{
|
|
|
140
158
|
};
|
|
141
159
|
}, {
|
|
142
160
|
query: {
|
|
143
|
-
status?: "locked" | "unlocked" | "disabled" | undefined;
|
|
144
161
|
productId?: string | undefined;
|
|
162
|
+
status?: "locked" | "unlocked" | "disabled" | undefined;
|
|
145
163
|
dedicatedUser?: "PASSENGER" | "RIDER" | "N/A" | undefined;
|
|
146
164
|
page?: string | undefined;
|
|
147
165
|
limit?: string | undefined;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkAvailabilitySchema = exports.makePermanentSchema = exports.disableDeviceSchema = exports.adminUnlockDeviceSchema = exports.adminLockDeviceSchema = exports.deleteDeviceSchema = exports.getDevicesSchema = exports.getDeviceSchema = exports.updateDeviceSchema = exports.createDevicePairsSchema = exports.validateUniquePairIds = exports.PAIR_ID_REGEX = void 0;
|
|
3
|
+
exports.checkAvailabilitySchema = exports.makePermanentSchema = exports.disableDeviceSchema = exports.adminUnlockDeviceSchema = exports.adminLockDeviceSchema = exports.deleteDeviceSchema = exports.getDevicesSchema = exports.getDeviceSchema = exports.updateDeviceSchema = exports.createDeviceSchema = exports.createDevicePairsSchema = exports.validateUniquePairIds = exports.PAIR_ID_REGEX = void 0;
|
|
4
|
+
// src/validations/device.validations.ts
|
|
4
5
|
const zod_1 = require("zod");
|
|
5
6
|
const vr_models_1 = require("vr-models");
|
|
6
7
|
// Constants
|
|
@@ -28,26 +29,33 @@ const validateUniquePairIds = (pairIds) => {
|
|
|
28
29
|
};
|
|
29
30
|
exports.validateUniquePairIds = validateUniquePairIds;
|
|
30
31
|
// ✅ ONLY bulk create - no single device creation
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
body: zod_1.z
|
|
32
|
+
// ✅ Using refine on the body object instead of superRefine on the whole schema
|
|
33
|
+
exports.createDevicePairsSchema = zod_1.z.object({
|
|
34
|
+
body: zod_1.z
|
|
35
|
+
.object({
|
|
34
36
|
productId: zod_1.z.string().uuid("Invalid product ID"),
|
|
35
37
|
pairIds: zod_1.z
|
|
36
38
|
.array(zod_1.z.string().regex(exports.PAIR_ID_REGEX, PAIR_ID_ERROR))
|
|
37
39
|
.min(1, "At least one pair ID required")
|
|
38
40
|
.max(50, "Cannot create more than 50 pairs at once"),
|
|
41
|
+
})
|
|
42
|
+
.refine((data) => {
|
|
43
|
+
const { pairIds } = data;
|
|
44
|
+
// ✅ Ensure no duplicate pair IDs in the request body
|
|
45
|
+
return (0, exports.validateUniquePairIds)(pairIds);
|
|
46
|
+
}, {
|
|
47
|
+
message: "Duplicate pair IDs found. Please ensure all pair IDs are unique.",
|
|
48
|
+
path: ["pairIds"],
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
// Create device schema (admin adds new stock)
|
|
52
|
+
exports.createDeviceSchema = zod_1.z.object({
|
|
53
|
+
body: zod_1.z.object({
|
|
54
|
+
serialNumber: deviceBaseSchema.serialNumber,
|
|
55
|
+
productId: deviceBaseSchema.productId,
|
|
56
|
+
// Status defaults to "locked" in model
|
|
57
|
+
// dedicatedUser starts as null
|
|
39
58
|
}),
|
|
40
|
-
})
|
|
41
|
-
.superRefine((data, ctx) => {
|
|
42
|
-
const { pairIds } = data.body;
|
|
43
|
-
// ✅ Ensure no duplicate pair IDs in the request body
|
|
44
|
-
if (!(0, exports.validateUniquePairIds)(pairIds)) {
|
|
45
|
-
ctx.addIssue({
|
|
46
|
-
code: zod_1.z.ZodIssueCode.custom,
|
|
47
|
-
message: `Duplicate pair IDs found. Please ensure all pair IDs are unique.`,
|
|
48
|
-
path: ["pairIds"],
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
59
|
});
|
|
52
60
|
// Update device schema
|
|
53
61
|
exports.updateDeviceSchema = zod_1.z.object({
|