All files / apps/data-refreshments/src/refreshments-execute/sync/userConnector user-sync-request-schema.ts

100% Statements 22/22
100% Branches 0/0
100% Functions 0/0
100% Lines 22/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 231x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import * as z from 'zod';
 
import { CurrencySymbolsEnum } from '@amalia/ext/iso-4217';
import { LanguagesEnum } from '@amalia/kernel/intl/types';
import { UserExternalIdSource, UserHrisIdSource, UserRole, type SyncUserRequest } from '@amalia/tenants/users/types';
 
export const userSyncRequestSchema: z.ZodType<SyncUserRequest> = z.object({
  id: z.uuidv4({ error: 'Invalid user ID (UUID)' }).optional(),
  email: z.email({ error: 'Invalid email address', pattern: z.regexes.unicodeEmail }).optional(),
  firstName: z.string({ error: 'Invalid first name' }).optional(),
  lastName: z.string({ error: 'Invalid last name' }).optional(),
  // language is set to "en" as default if not provided or not in LanguagesEnum
  language: z.enum(LanguagesEnum).catch(LanguagesEnum.en).default(LanguagesEnum.en),
  role: z.enum(UserRole, { error: 'Invalid user role' }).optional(),
  currency: z.enum(CurrencySymbolsEnum, { error: 'Invalid currency symbol' }).optional(),
  externalId: z.union([z.string(), z.number().transform(String)], { error: 'Invalid external ID' }).optional(),
  externalIdSource: z.enum(UserExternalIdSource, { error: 'Invalid external ID source' }).optional(),
  hrisId: z.union([z.string(), z.number().transform(String)], { error: 'Invalid HRIS ID' }).optional(),
  hrisIdSource: z.enum(UserHrisIdSource, { error: 'Invalid HRIS ID source' }).optional(),
});
 
export const formatZodError = z.prettifyError;