Skip to content

Commit

Permalink
generate id if not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Mar 25, 2024
1 parent b41bd45 commit 6c056cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/api/router/user/mutation.adminCreate.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions packages/api/router/user/mutation.create.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6c056cf

Please sign in to comment.