mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-26 23:04:57 +00:00
code: user,server,nextjs (2 files)
This commit is contained in:
@@ -12,12 +12,18 @@ export async function dbalAddUser(user: Omit<User, 'id' | 'createdAt'>): Promise
|
||||
// Map app role types to DBAL role types
|
||||
// Note: DBAL User type only has basic fields (id, username, email, role, createdAt, updatedAt)
|
||||
// Extended fields like profilePicture, bio, etc. are not in DBAL User type
|
||||
const dbalRole = user.role as 'user' | 'admin' | 'god' | 'supergod'
|
||||
const dbalRole = user.role === 'public'
|
||||
? 'user'
|
||||
: (user.role as 'user' | 'admin' | 'god' | 'supergod')
|
||||
|
||||
const created = await dbal.users.create({
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
role: dbalRole,
|
||||
profilePicture: user.profilePicture,
|
||||
bio: user.bio,
|
||||
tenantId: user.tenantId,
|
||||
isInstanceOwner: user.isInstanceOwner,
|
||||
})
|
||||
|
||||
// Map DBAL User to app User, preserving extra fields
|
||||
@@ -26,10 +32,10 @@ export async function dbalAddUser(user: Omit<User, 'id' | 'createdAt'>): Promise
|
||||
username: created.username,
|
||||
email: created.email,
|
||||
role: created.role as any,
|
||||
profilePicture: user.profilePicture,
|
||||
bio: user.bio,
|
||||
profilePicture: created.profilePicture ?? user.profilePicture,
|
||||
bio: created.bio ?? user.bio,
|
||||
createdAt: created.createdAt instanceof Date ? created.createdAt.getTime() : Number(created.createdAt),
|
||||
tenantId: user.tenantId,
|
||||
isInstanceOwner: user.isInstanceOwner,
|
||||
tenantId: created.tenantId ?? user.tenantId,
|
||||
isInstanceOwner: created.isInstanceOwner ?? user.isInstanceOwner,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,13 @@ export async function dbalUpdateUser(userId: string, updates: Partial<User>): Pr
|
||||
const dbalUpdates: any = {}
|
||||
if (updates.username) dbalUpdates.username = updates.username
|
||||
if (updates.email) dbalUpdates.email = updates.email
|
||||
if (updates.role) dbalUpdates.role = updates.role
|
||||
if (updates.role) {
|
||||
dbalUpdates.role = updates.role === 'public' ? 'user' : updates.role
|
||||
}
|
||||
if (updates.profilePicture !== undefined) dbalUpdates.profilePicture = updates.profilePicture
|
||||
if (updates.bio !== undefined) dbalUpdates.bio = updates.bio
|
||||
if (updates.tenantId !== undefined) dbalUpdates.tenantId = updates.tenantId
|
||||
if (updates.isInstanceOwner !== undefined) dbalUpdates.isInstanceOwner = updates.isInstanceOwner
|
||||
|
||||
const updated = await dbal.users.update(userId, dbalUpdates)
|
||||
|
||||
@@ -23,10 +29,10 @@ export async function dbalUpdateUser(userId: string, updates: Partial<User>): Pr
|
||||
username: updated.username,
|
||||
email: updated.email,
|
||||
role: updated.role as any,
|
||||
profilePicture: updates.profilePicture,
|
||||
bio: updates.bio,
|
||||
profilePicture: updated.profilePicture ?? updates.profilePicture,
|
||||
bio: updated.bio ?? updates.bio,
|
||||
createdAt: updated.createdAt instanceof Date ? updated.createdAt.getTime() : Number(updated.createdAt),
|
||||
tenantId: updates.tenantId,
|
||||
isInstanceOwner: updates.isInstanceOwner,
|
||||
tenantId: updated.tenantId ?? updates.tenantId,
|
||||
isInstanceOwner: updated.isInstanceOwner ?? updates.isInstanceOwner,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user