mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
refactor(common): add validation for notification channel flag combinations
Add refine validation to NotificationChannelSchema to ensure only valid flag combinations are accepted. Computes valid flags using bitwise OR of all enum values.
This commit is contained in:
@@ -1,14 +1,24 @@
|
||||
import z from 'zod';
|
||||
|
||||
export const NotificationChannel = {
|
||||
NotSet: 0,
|
||||
Email: 1,
|
||||
SMS: 2,
|
||||
Phone: 4,
|
||||
Fax: 8,
|
||||
Postal: 16,
|
||||
} as const;
|
||||
|
||||
export const NotificationChannelSchema = z.nativeEnum(NotificationChannel).describe('Notification channel');
|
||||
|
||||
export type NotificationChannel = z.infer<typeof NotificationChannelSchema>;
|
||||
import z from 'zod';
|
||||
|
||||
export const NotificationChannel = {
|
||||
NotSet: 0,
|
||||
Email: 1,
|
||||
SMS: 2,
|
||||
Phone: 4,
|
||||
Fax: 8,
|
||||
Postal: 16,
|
||||
} as const;
|
||||
|
||||
const ALL_FLAGS = Object.values(NotificationChannel).reduce<number>(
|
||||
(a, b) => a | b,
|
||||
0,
|
||||
);
|
||||
|
||||
export const NotificationChannelSchema = z
|
||||
.nativeEnum(NotificationChannel)
|
||||
.refine((val) => (val & ALL_FLAGS) === val, {
|
||||
message: 'Invalid notification channel',
|
||||
})
|
||||
.describe('Notification channel');
|
||||
|
||||
export type NotificationChannel = z.infer<typeof NotificationChannelSchema>;
|
||||
|
||||
Reference in New Issue
Block a user