0
Fork 0
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:
Xiao Yijun 2022-02-16 18:06:08 +08:00 committed by GitHub
parent 56c9f00440
commit d69bbeebb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

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

View file

@ -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<