chore: user management api additions (#4231)
* feat: added route to delete users in user management api's * chore: added lastLoggedOn and lastActiveOn fields to user response type * chore: changed return type * chore: changed target to prod for hopp-old-backend service
This commit is contained in:
@@ -427,7 +427,7 @@ export class AdminService {
|
||||
* Remove a user account by UID
|
||||
* @param userUid User UID
|
||||
* @returns an Either of boolean or error
|
||||
* @deprecated use removeUserAccounts instead
|
||||
*
|
||||
*/
|
||||
async removeUserAccount(userUid: string) {
|
||||
const user = await this.userService.findUserById(userUid);
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
UpdateUserAdminStatusResponse,
|
||||
CreateUserInvitationRequest,
|
||||
CreateUserInvitationResponse,
|
||||
DeleteUserResponse,
|
||||
} from './request-response.dto';
|
||||
import * as E from 'fp-ts/Either';
|
||||
import * as O from 'fp-ts/Option';
|
||||
@@ -208,6 +209,35 @@ export class InfraTokensController {
|
||||
});
|
||||
}
|
||||
|
||||
@Delete('users/:uid')
|
||||
@ApiOkResponse({
|
||||
description: 'Delete a user from the instance',
|
||||
type: DeleteUserResponse,
|
||||
})
|
||||
@ApiBadRequestResponse({ type: ExceptionResponse })
|
||||
@ApiNotFoundResponse({ type: ExceptionResponse })
|
||||
async deleteUser(@Param('uid') uid: string) {
|
||||
const deletedUser = await this.adminService.removeUserAccount(uid);
|
||||
|
||||
if (E.isLeft(deletedUser)) {
|
||||
const statusCode =
|
||||
(deletedUser.left as string) === USER_NOT_FOUND
|
||||
? HttpStatus.NOT_FOUND
|
||||
: HttpStatus.BAD_REQUEST;
|
||||
|
||||
throwHTTPErr({ message: deletedUser.left, statusCode });
|
||||
}
|
||||
|
||||
return plainToInstance(
|
||||
DeleteUserResponse,
|
||||
{ message: deletedUser.right },
|
||||
{
|
||||
excludeExtraneousValues: true,
|
||||
enableImplicitConversion: true,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@Patch('users/:uid/admin-status')
|
||||
@ApiOkResponse({
|
||||
description: 'Update user admin status',
|
||||
|
||||
@@ -79,6 +79,14 @@ export class GetUserResponse {
|
||||
@ApiProperty()
|
||||
@Expose()
|
||||
isAdmin: boolean;
|
||||
|
||||
@ApiProperty()
|
||||
@Expose()
|
||||
lastLoggedOn: Date;
|
||||
|
||||
@ApiProperty()
|
||||
@Expose()
|
||||
lastActiveOn: Date;
|
||||
}
|
||||
|
||||
// PATCH v1/infra/users/:uid
|
||||
@@ -113,3 +121,10 @@ export class ExceptionResponse {
|
||||
@Expose()
|
||||
statusCode: number;
|
||||
}
|
||||
|
||||
// Delete v1/infra/users/:uid
|
||||
export class DeleteUserResponse {
|
||||
@ApiProperty()
|
||||
@Expose()
|
||||
message: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user