code: user,server,nextjs (2 files)

This commit is contained in:
2025-12-25 23:09:54 +00:00
parent bbd39efce5
commit b4f68096c5
2 changed files with 22 additions and 10 deletions

View File

@@ -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,
}
}

View File

@@ -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,
}
}