Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
chore: user management api additions (#4231)
Balu Babu014020875397
diff --git a/packages/hoppscotch-backend/src/admin/admin.service.ts b/packages/hoppscotch-backend/src/admin/admin.service.tsindex a55524a87..db0fba1c1 100644--- a/packages/hoppscotch-backend/src/admin/admin.service.ts+++ b/packages/hoppscotch-backend/src/admin/admin.service.ts@@ -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);diff --git a/packages/hoppscotch-backend/src/infra-token/infra-token.controller.ts b/packages/hoppscotch-backend/src/infra-token/infra-token.controller.tsindex 67b12e5c9..77ddbc025 100644--- a/packages/hoppscotch-backend/src/infra-token/infra-token.controller.ts+++ b/packages/hoppscotch-backend/src/infra-token/infra-token.controller.ts@@ -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',diff --git a/packages/hoppscotch-backend/src/infra-token/request-response.dto.ts b/packages/hoppscotch-backend/src/infra-token/request-response.dto.tsindex 9bacfbf12..8e71b0e61 100644--- a/packages/hoppscotch-backend/src/infra-token/request-response.dto.ts+++ b/packages/hoppscotch-backend/src/infra-token/request-response.dto.ts@@ -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;+}