feat(admin): archive users and their profiles permanently
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { FastifyInstance } from "fastify"
|
||||
import { eq, and } from "drizzle-orm"
|
||||
import { eq, and, isNull } from "drizzle-orm"
|
||||
|
||||
import {
|
||||
authUsers,
|
||||
@@ -83,7 +83,8 @@ export default async function userRoutes(server: FastifyInstance) {
|
||||
.where(
|
||||
and(
|
||||
eq(authProfiles.user_id, id),
|
||||
eq(authProfiles.tenant_id, req.user.tenant_id)
|
||||
eq(authProfiles.tenant_id, req.user.tenant_id),
|
||||
isNull(authProfiles.archived_at)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -99,6 +100,7 @@ export default async function userRoutes(server: FastifyInstance) {
|
||||
}
|
||||
|
||||
const updateData: any = { ...data }
|
||||
for (const key of ["archived_at", "user_id", "tenant_id", "id"]) delete updateData[key]
|
||||
|
||||
// bekannte Date-Felder prüfen
|
||||
if (data.entry_date !== undefined)
|
||||
@@ -116,9 +118,10 @@ export default async function userRoutes(server: FastifyInstance) {
|
||||
const [updatedProfile] = await server.db
|
||||
.update(authProfiles)
|
||||
.set(updateData)
|
||||
.where(eq(authProfiles.id, profile.id))
|
||||
.where(and(eq(authProfiles.id, profile.id), isNull(authProfiles.archived_at)))
|
||||
.returning()
|
||||
|
||||
if (!updatedProfile) return reply.code(404).send({ error: "Profile not found in tenant" })
|
||||
return { profile: updatedProfile }
|
||||
|
||||
} catch (err: any) {
|
||||
|
||||
Reference in New Issue
Block a user