mirror of
https://github.com/logto-io/logto.git
synced 2025-01-27 21:39:16 -05:00
feat(core): patch /users/:userId
(#246)
This commit is contained in:
parent
c99c6b55aa
commit
77b520deba
2 changed files with 30 additions and 0 deletions
|
@ -94,6 +94,34 @@ export default function adminUserRoutes<T extends AuthedRouter>(router: T) {
|
|||
}
|
||||
);
|
||||
|
||||
router.patch(
|
||||
'/users/:userId',
|
||||
koaGuard({
|
||||
params: object({ userId: string().min(1) }),
|
||||
body: object({
|
||||
name: string().min(3).optional(),
|
||||
avatar: string().url().optional(),
|
||||
}),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const {
|
||||
params: { userId },
|
||||
body: { name, avatar },
|
||||
} = ctx.guard;
|
||||
|
||||
await findUserById(userId);
|
||||
|
||||
const user = await updateUserById(userId, {
|
||||
name,
|
||||
avatar,
|
||||
});
|
||||
|
||||
ctx.body = pick(user, ...userInfoSelectFields);
|
||||
|
||||
return next();
|
||||
}
|
||||
);
|
||||
|
||||
router.patch(
|
||||
'/users/:userId/roleNames',
|
||||
koaGuard({
|
||||
|
|
|
@ -5,6 +5,8 @@ export const userInfoSelectFields = Object.freeze([
|
|||
'username',
|
||||
'primaryEmail',
|
||||
'primaryPhone',
|
||||
'name',
|
||||
'avatar',
|
||||
'roleNames',
|
||||
'customData',
|
||||
] as const);
|
||||
|
|
Loading…
Add table
Reference in a new issue