vr-commons 1.0.145 → 1.0.146
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,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export declare const PAIR_ID_REGEX: RegExp;
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const deduplicatePairIds: (pairIds: string[]) => string[];
|
|
4
4
|
export declare const createDevicePairsSchema: z.ZodObject<{
|
|
5
5
|
body: z.ZodEffects<z.ZodObject<{
|
|
6
6
|
productId: z.ZodString;
|
|
@@ -12,16 +12,16 @@ export declare const createDevicePairsSchema: z.ZodObject<{
|
|
|
12
12
|
productId: string;
|
|
13
13
|
pairIds: string[];
|
|
14
14
|
}>, {
|
|
15
|
-
productId: string;
|
|
16
15
|
pairIds: string[];
|
|
16
|
+
productId: string;
|
|
17
17
|
}, {
|
|
18
18
|
productId: string;
|
|
19
19
|
pairIds: string[];
|
|
20
20
|
}>;
|
|
21
21
|
}, "strip", z.ZodTypeAny, {
|
|
22
22
|
body: {
|
|
23
|
-
productId: string;
|
|
24
23
|
pairIds: string[];
|
|
24
|
+
productId: string;
|
|
25
25
|
};
|
|
26
26
|
}, {
|
|
27
27
|
body: {
|
|
@@ -1,6 +1,6 @@
|
|
|
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.createDeviceSchema = exports.createDevicePairsSchema = exports.
|
|
3
|
+
exports.checkAvailabilitySchema = exports.makePermanentSchema = exports.disableDeviceSchema = exports.adminUnlockDeviceSchema = exports.adminLockDeviceSchema = exports.deleteDeviceSchema = exports.getDevicesSchema = exports.getDeviceSchema = exports.updateDeviceSchema = exports.createDeviceSchema = exports.createDevicePairsSchema = exports.deduplicatePairIds = exports.PAIR_ID_REGEX = void 0;
|
|
4
4
|
// src/validations/device.validations.ts
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
const vr_models_1 = require("vr-models");
|
|
@@ -22,14 +22,13 @@ const deviceBaseSchema = {
|
|
|
22
22
|
// No letter 'O' to avoid confusion with 0
|
|
23
23
|
exports.PAIR_ID_REGEX = /^[A-NP-Z]{2}[0-9]{3}[A-NP-Z]{1}$/;
|
|
24
24
|
const PAIR_ID_ERROR = "Pair ID must be 6 characters: 2 letters (A-Z, excluding O) + 3 digits + 1 letter (A-Z, excluding O). Example: AA001A";
|
|
25
|
-
// ✅ Helper to
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
return unique.size === pairIds.length;
|
|
25
|
+
// ✅ Helper to remove duplicates and return unique pair IDs
|
|
26
|
+
const deduplicatePairIds = (pairIds) => {
|
|
27
|
+
return [...new Set(pairIds)];
|
|
29
28
|
};
|
|
30
|
-
exports.
|
|
29
|
+
exports.deduplicatePairIds = deduplicatePairIds;
|
|
31
30
|
// ✅ ONLY bulk create - no single device creation
|
|
32
|
-
// ✅
|
|
31
|
+
// ✅ Removes duplicates automatically instead of rejecting
|
|
33
32
|
exports.createDevicePairsSchema = zod_1.z.object({
|
|
34
33
|
body: zod_1.z
|
|
35
34
|
.object({
|
|
@@ -39,13 +38,13 @@ exports.createDevicePairsSchema = zod_1.z.object({
|
|
|
39
38
|
.min(1, "At least one pair ID required")
|
|
40
39
|
.max(50, "Cannot create more than 50 pairs at once"),
|
|
41
40
|
})
|
|
42
|
-
.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
.transform((data) => {
|
|
42
|
+
// ✅ Remove duplicates and keep unique pair IDs
|
|
43
|
+
const uniquePairIds = (0, exports.deduplicatePairIds)(data.pairIds);
|
|
44
|
+
return {
|
|
45
|
+
...data,
|
|
46
|
+
pairIds: uniquePairIds,
|
|
47
|
+
};
|
|
49
48
|
}),
|
|
50
49
|
});
|
|
51
50
|
// Create device schema (admin adds new stock)
|