forked from hpi-sam/digital-fuesim-manv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uuid.ts
25 lines (22 loc) · 829 Bytes
/
uuid.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import type { ValidationArguments, ValidationOptions } from 'class-validator';
import { v4 } from 'uuid';
/**
* Generates a v4 uuid
*/
export function uuid(): UUID {
// this is an extra function to make the imports easier (no `v4 as uuid` that can't be auto-generated)
return v4();
}
export type UUID = string;
const uuidValidationFailedWithId = (id: string) => `Got malformed id: '${id}'.`;
const uuidValidationFailedMessage: (
validationArguments: ValidationArguments
) => string = (validationArguments: ValidationArguments) =>
uuidValidationFailedWithId(String(validationArguments.value));
export const uuidValidationOptions: ValidationOptions = {
message: uuidValidationFailedMessage,
};
export const uuidArrayValidationOptions: ValidationOptions = {
...uuidValidationOptions,
each: true,
};