KI-AGENT: Aktiviere importierten Mandanten für Zieladmin
This commit is contained in:
@@ -246,6 +246,7 @@ export default async function adminRoutes(server: FastifyInstance) {
|
||||
const [currentUser] = await server.db
|
||||
.select({
|
||||
id: authUsers.id,
|
||||
email: authUsers.email,
|
||||
is_admin: authUsers.is_admin,
|
||||
})
|
||||
.from(authUsers)
|
||||
@@ -971,6 +972,38 @@ export default async function adminRoutes(server: FastifyInstance) {
|
||||
|
||||
const exportData = req.body as TenantFullExport;
|
||||
const result = await importTenantFullExport(server, exportData);
|
||||
const fallbackName = deriveNameFromEmail(currentUser.email);
|
||||
|
||||
await server.db
|
||||
.insert(authTenantUsers)
|
||||
.values({
|
||||
tenant_id: result.tenantId,
|
||||
user_id: currentUser.id,
|
||||
created_by: currentUser.id,
|
||||
})
|
||||
.onConflictDoNothing();
|
||||
|
||||
const [existingAdminProfile] = await server.db
|
||||
.select({ id: authProfiles.id })
|
||||
.from(authProfiles)
|
||||
.where(and(
|
||||
eq(authProfiles.tenant_id, result.tenantId),
|
||||
eq(authProfiles.user_id, currentUser.id)
|
||||
))
|
||||
.limit(1);
|
||||
|
||||
if (!existingAdminProfile) {
|
||||
await server.db
|
||||
.insert(authProfiles)
|
||||
.values({
|
||||
tenant_id: result.tenantId,
|
||||
user_id: currentUser.id,
|
||||
first_name: fallbackName.first_name,
|
||||
last_name: fallbackName.last_name,
|
||||
email: currentUser.email,
|
||||
active: true,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
|
||||
Reference in New Issue
Block a user