0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

feat(core): update user suspended (#2326)

This commit is contained in:
wangsijie 2022-11-11 13:39:48 +08:00 committed by GitHub
parent 6de2fdcf11
commit 3bcd29ec89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View file

@ -318,6 +318,18 @@ describe('adminUserRoutes', () => {
expect(updateUserById).not.toHaveBeenCalled();
});
it('PATCH /users/:userId/is-suspended', async () => {
const mockedUserId = 'foo';
const response = await userRequest
.patch(`/users/${mockedUserId}/is-suspended`)
.send({ isSuspended: true });
expect(updateUserById).toHaveBeenCalledWith(mockedUserId, { isSuspended: true });
expect(response.status).toEqual(200);
expect(response.body).toEqual({
...mockUserResponse,
});
});
it('DELETE /users/:userId', async () => {
const userId = 'fooUser';
const response = await userRequest.delete(`/users/${userId}`);

View file

@ -2,7 +2,7 @@ import { emailRegEx, passwordRegEx, phoneRegEx, usernameRegEx } from '@logto/cor
import { arbitraryObjectGuard, userInfoSelectFields } from '@logto/schemas';
import { has } from '@silverhand/essentials';
import pick from 'lodash.pick';
import { literal, object, string } from 'zod';
import { boolean, literal, object, string } from 'zod';
import { isTrue } from '@/env-set/parameters';
import RequestError from '@/errors/RequestError';
@ -242,6 +242,30 @@ export default function adminUserRoutes<T extends AuthedRouter>(router: T) {
}
);
router.patch(
'/users/:userId/is-suspended',
koaGuard({
params: object({ userId: string() }),
body: object({ isSuspended: boolean() }),
}),
async (ctx, next) => {
const {
params: { userId },
body: { isSuspended },
} = ctx.guard;
await findUserById(userId);
const user = await updateUserById(userId, {
isSuspended,
});
ctx.body = pick(user, ...userInfoSelectFields);
return next();
}
);
router.delete(
'/users/:userId',
koaGuard({