mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
feat(core): patch /user/:userId/custom-data
(#232)
This commit is contained in:
parent
56c9f00440
commit
d69bbeebb2
2 changed files with 26 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
|||
import { userInfoSelectFields } from '@logto/schemas';
|
||||
import { customDataGuard, userInfoSelectFields } from '@logto/schemas';
|
||||
import pick from 'lodash.pick';
|
||||
import { InvalidInputError } from 'slonik';
|
||||
import { object, string } from 'zod';
|
||||
|
@ -126,4 +126,28 @@ export default function adminUserRoutes<T extends AuthedRouter>(router: T) {
|
|||
return next();
|
||||
}
|
||||
);
|
||||
|
||||
router.patch(
|
||||
'/users/:userId/custom-data',
|
||||
koaGuard({
|
||||
params: object({ userId: string().min(1) }),
|
||||
body: object({ customData: customDataGuard }),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const {
|
||||
params: { userId },
|
||||
body: { customData },
|
||||
} = ctx.guard;
|
||||
|
||||
await findUserById(userId);
|
||||
|
||||
const user = await updateUserById(userId, {
|
||||
customData,
|
||||
});
|
||||
|
||||
ctx.body = pick(user, ...userInfoSelectFields);
|
||||
|
||||
return next();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ export const userInfoSelectFields = Object.freeze([
|
|||
'primaryEmail',
|
||||
'primaryPhone',
|
||||
'roleNames',
|
||||
'customData',
|
||||
] as const);
|
||||
|
||||
export type UserInfo<Keys extends keyof CreateUser = typeof userInfoSelectFields[number]> = Pick<
|
||||
|
|
Loading…
Reference in a new issue