mirror of
https://github.com/logto-io/logto.git
synced 2025-03-31 22:51:25 -05:00
feat(core): delete users/:userid/custom-data
(#233)
This commit is contained in:
parent
46dd8f3b69
commit
c1c356c30a
2 changed files with 33 additions and 0 deletions
|
@ -108,3 +108,15 @@ export const deleteUserById = async (id: string) => {
|
|||
throw new DeletionError(Users.table, id);
|
||||
}
|
||||
};
|
||||
|
||||
export const clearUserCustomDataById = async (id: string) => {
|
||||
const { rowCount } = await pool.query<User>(sql`
|
||||
update ${table}
|
||||
set ${fields.customData}='{}'::jsonb
|
||||
where id=${id}
|
||||
`);
|
||||
|
||||
if (rowCount < 1) {
|
||||
throw new DeletionError(Users.table, id);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -9,6 +9,7 @@ import koaGuard from '@/middleware/koa-guard';
|
|||
import koaPagination from '@/middleware/koa-pagination';
|
||||
import { findRolesByRoleNames } from '@/queries/roles';
|
||||
import {
|
||||
clearUserCustomDataById,
|
||||
findAllUsers,
|
||||
findTotalNumberOfUsers,
|
||||
findUserById,
|
||||
|
@ -150,4 +151,24 @@ export default function adminUserRoutes<T extends AuthedRouter>(router: T) {
|
|||
return next();
|
||||
}
|
||||
);
|
||||
|
||||
router.delete(
|
||||
'/users/:userId/custom-data',
|
||||
koaGuard({
|
||||
params: object({ userId: string().min(1) }),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const {
|
||||
params: { userId },
|
||||
} = ctx.guard;
|
||||
|
||||
await findUserById(userId);
|
||||
|
||||
await clearUserCustomDataById(userId);
|
||||
|
||||
ctx.status = 200;
|
||||
|
||||
return next();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue