From 6c056cf03b6ac64989ed6d5c4769d682d21748a0 Mon Sep 17 00:00:00 2001 From: Joe Karow <58997957+JoeKarow@users.noreply.github.com> Date: Mon, 25 Mar 2024 18:02:22 -0400 Subject: [PATCH] generate id if not provided --- packages/api/router/user/mutation.adminCreate.schema.ts | 6 +++--- packages/api/router/user/mutation.create.schema.ts | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/api/router/user/mutation.adminCreate.schema.ts b/packages/api/router/user/mutation.adminCreate.schema.ts index 989baeaa3b..3e07792740 100644 --- a/packages/api/router/user/mutation.adminCreate.schema.ts +++ b/packages/api/router/user/mutation.adminCreate.schema.ts @@ -7,7 +7,7 @@ import { connectOne, connectOneRequired, createManyOptional } from '~api/schemas export const ZAdminCreateSchema = z .object({ - id: prefixedId('user').default(generateId('user')), + id: prefixedId('user').optional(), email: z.string().email().toLowerCase(), password: z.string(), name: z.string().optional(), @@ -70,14 +70,14 @@ export const ZAdminCreateSchema = z .optional(), }) .transform((data) => { - const { id, name, email, password, image, cogintoSubject, cognitoMessage } = data + const { id: providedId, name, email, password, image, cogintoSubject, cognitoMessage } = data const permissions = createManyOptional(data?.permissions) const orgPermission = createManyOptional(data?.orgPermission) const locationPermission = createManyOptional(data?.locationPermission) const roles = createManyOptional(data?.roles) const userType = connectOneRequired({ type: data.userType }) const langPref = connectOne({ localeCode: data.language }) - + const id = providedId ?? generateId('user') const scalarData = { id, name, diff --git a/packages/api/router/user/mutation.create.schema.ts b/packages/api/router/user/mutation.create.schema.ts index 72f5d09fe1..07214f0f56 100644 --- a/packages/api/router/user/mutation.create.schema.ts +++ b/packages/api/router/user/mutation.create.schema.ts @@ -6,7 +6,7 @@ import { connectOne, connectOneRequired } from '~api/schemas/nestedOps' export const ZCreateSchema = z .object({ - id: prefixedId('user').default(generateId('user')), + id: prefixedId('user').optional(), email: z.string().email().toLowerCase(), password: z.string(), name: z.string().optional(), @@ -48,12 +48,13 @@ export const ZCreateSchema = z }) .optional(), }) - .transform(({ id, name, email, password, image, active, currentCity, ...data }) => { + .transform(({ id: providedId, name, email, password, image, active, currentCity, ...data }) => { const userType = connectOneRequired({ type: data.userType }) const langPref = connectOne({ localeCode: data.language }) const currentCountry = connectOne(data.currentCountry) const currentGovDist = connectOne(data.currentGovDist) const { lawPractice, otherLawPractice, servProvider, servProviderOther, location } = data + const id = providedId ?? generateId('user') const record = { id, name,