0
Fork 0
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:
Xiao Yijun 2022-02-17 14:10:26 +08:00 committed by GitHub
parent 46dd8f3b69
commit c1c356c30a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View file

@ -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);
}
};

View file

@ -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();
}
);
}