mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-17 03:05:13 +00:00
Merge pull request #103 from SyncrowIOT/SP-449-be-module-misalignment
refactor delete user endpoint
This commit is contained in:
@ -1,10 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
Delete,
|
|
||||||
Get,
|
Get,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
Param,
|
|
||||||
Post,
|
Post,
|
||||||
Req,
|
Req,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
@ -51,20 +49,6 @@ export class UserAuthController {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
|
||||||
@UseGuards(SuperAdminRoleGuard)
|
|
||||||
@Delete('user/delete/:id')
|
|
||||||
async userDelete(@Param('id') id: string) {
|
|
||||||
await this.userAuthService.deleteUser(id);
|
|
||||||
return {
|
|
||||||
statusCode: HttpStatus.OK,
|
|
||||||
data: {
|
|
||||||
id,
|
|
||||||
},
|
|
||||||
message: 'User Deleted Successfully',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('user/send-otp')
|
@Post('user/send-otp')
|
||||||
async sendOtp(@Body() otpDto: UserOtpDto) {
|
async sendOtp(@Body() otpDto: UserOtpDto) {
|
||||||
const otpCode = await this.userAuthService.generateOTP(otpDto);
|
const otpCode = await this.userAuthService.generateOTP(otpDto);
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import { RoleTypeRepository } from './../../../libs/common/src/modules/role-type/repositories/role.type.repository';
|
|
||||||
import { UserRoleRepository } from './../../../libs/common/src/modules/user/repositories/user.repository';
|
|
||||||
import { UserRepository } from '../../../libs/common/src/modules/user/repositories';
|
import { UserRepository } from '../../../libs/common/src/modules/user/repositories';
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
@ -31,8 +29,6 @@ export class UserAuthService {
|
|||||||
private readonly helperHashService: HelperHashService,
|
private readonly helperHashService: HelperHashService,
|
||||||
private readonly authService: AuthService,
|
private readonly authService: AuthService,
|
||||||
private readonly emailService: EmailService,
|
private readonly emailService: EmailService,
|
||||||
private readonly userRoleRepository: UserRoleRepository,
|
|
||||||
private readonly roleTypeRepository: RoleTypeRepository,
|
|
||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@ -128,14 +124,6 @@ export class UserAuthService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteUser(uuid: string) {
|
|
||||||
const user = await this.findOneById(uuid);
|
|
||||||
if (!user) {
|
|
||||||
throw new BadRequestException('User not found');
|
|
||||||
}
|
|
||||||
return await this.userRepository.update({ uuid }, { isActive: false });
|
|
||||||
}
|
|
||||||
|
|
||||||
async findOneById(id: string): Promise<UserEntity> {
|
async findOneById(id: string): Promise<UserEntity> {
|
||||||
return await this.userRepository.findOne({ where: { uuid: id } });
|
return await this.userRepository.findOne({ where: { uuid: id } });
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
|
Delete,
|
||||||
Get,
|
Get,
|
||||||
HttpException,
|
HttpException,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
@ -18,6 +19,7 @@ import {
|
|||||||
UpdateTimezoneDataDto,
|
UpdateTimezoneDataDto,
|
||||||
} from '../dtos';
|
} from '../dtos';
|
||||||
import { CheckProfilePictureGuard } from 'src/guards/profile.picture.guard';
|
import { CheckProfilePictureGuard } from 'src/guards/profile.picture.guard';
|
||||||
|
import { SuperAdminRoleGuard } from 'src/guards/super.admin.role.guard';
|
||||||
|
|
||||||
@ApiTags('User Module')
|
@ApiTags('User Module')
|
||||||
@Controller({
|
@Controller({
|
||||||
@ -140,4 +142,17 @@ export class UserController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@UseGuards(SuperAdminRoleGuard)
|
||||||
|
@Delete('/:userUuid')
|
||||||
|
async userDelete(@Param('userUuid') userUuid: string) {
|
||||||
|
await this.userService.deleteUser(userUuid);
|
||||||
|
return {
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
data: {
|
||||||
|
userUuid,
|
||||||
|
},
|
||||||
|
message: 'User Deleted Successfully',
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import { UserRepository } from '@app/common/modules/user/repositories';
|
|||||||
import { RegionRepository } from '@app/common/modules/region/repositories';
|
import { RegionRepository } from '@app/common/modules/region/repositories';
|
||||||
import { TimeZoneRepository } from '@app/common/modules/timezone/repositories';
|
import { TimeZoneRepository } from '@app/common/modules/timezone/repositories';
|
||||||
import { removeBase64Prefix } from '@app/common/helper/removeBase64Prefix';
|
import { removeBase64Prefix } from '@app/common/helper/removeBase64Prefix';
|
||||||
|
import { UserEntity } from '@app/common/modules/user/entities';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserService {
|
export class UserService {
|
||||||
@ -237,4 +238,14 @@ export class UserService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async findOneById(id: string): Promise<UserEntity> {
|
||||||
|
return await this.userRepository.findOne({ where: { uuid: id } });
|
||||||
|
}
|
||||||
|
async deleteUser(uuid: string) {
|
||||||
|
const user = await this.findOneById(uuid);
|
||||||
|
if (!user) {
|
||||||
|
throw new BadRequestException('User not found');
|
||||||
|
}
|
||||||
|
return await this.userRepository.update({ uuid }, { isActive: false });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user