mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-15 17:21:35 +10:00
[Feature] Implement Self-Serve Account Deletion
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Delete, Get, HttpCode, Post, UseGuards } from '@nestjs/common';
|
||||
import { Body, Controller, Delete, Get, HttpCode, Patch, Post, UseGuards } from '@nestjs/common';
|
||||
|
||||
import { User } from '@/decorators/user.decorator';
|
||||
import { User as UserEntity } from '@/users/entities/user.entity';
|
||||
@ -7,6 +7,7 @@ import { AuthService } from './auth.service';
|
||||
import { ForgotPasswordDto } from './dto/forgot-password.dto';
|
||||
import { RegisterDto } from './dto/register.dto';
|
||||
import { ResetPasswordDto } from './dto/reset-password.dto';
|
||||
import { UpdateProfileDto } from './dto/update-profile.dto';
|
||||
import { JwtAuthGuard } from './guards/jwt.guard';
|
||||
import { LocalAuthGuard } from './guards/local.guard';
|
||||
|
||||
@ -57,6 +58,14 @@ export class AuthController {
|
||||
return this.authService.resetPassword(resetPasswordDto);
|
||||
}
|
||||
|
||||
@HttpCode(200)
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Patch('update-profile')
|
||||
updateProfile(@User('id') userId: number, @Body() updateProfileDto: UpdateProfileDto) {
|
||||
console.log({ userId, updateProfileDto });
|
||||
return this.authService.updateProfile(userId, updateProfileDto);
|
||||
}
|
||||
|
||||
@HttpCode(200)
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete()
|
||||
|
||||
@ -6,12 +6,14 @@ import { compareSync, hashSync } from 'bcryptjs';
|
||||
import { OAuth2Client } from 'google-auth-library';
|
||||
|
||||
import { PostgresErrorCode } from '@/database/errorCodes.enum';
|
||||
import { ResumeService } from '@/resume/resume.service';
|
||||
import { CreateGoogleUserDto } from '@/users/dto/create-google-user.dto';
|
||||
import { User } from '@/users/entities/user.entity';
|
||||
import { UsersService } from '@/users/users.service';
|
||||
|
||||
import { RegisterDto } from './dto/register.dto';
|
||||
import { ResetPasswordDto } from './dto/reset-password.dto';
|
||||
import { UpdateProfileDto } from './dto/update-profile.dto';
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
@ -68,6 +70,10 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
updateProfile(id: number, newData: UpdateProfileDto) {
|
||||
return this.usersService.update(id, { name: newData.name });
|
||||
}
|
||||
|
||||
forgotPassword(email: string) {
|
||||
return this.usersService.generateResetToken(email);
|
||||
}
|
||||
|
||||
7
server/src/auth/dto/update-profile.dto.ts
Normal file
7
server/src/auth/dto/update-profile.dto.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { IsNotEmpty, IsString, MinLength } from 'class-validator';
|
||||
|
||||
export class UpdateProfileDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
name: string;
|
||||
}
|
||||
@ -7,7 +7,7 @@ const sampleData: Partial<Resume> = {
|
||||
phone: '+1 800 1200 3820',
|
||||
birthdate: '1995-08-06',
|
||||
photo: {
|
||||
url: `https://i.imgur.com/40gTnCx.jpg`,
|
||||
url: `https://i.imgur.com/O7iT9ke.jpg`,
|
||||
filters: {
|
||||
size: 128,
|
||||
shape: 'rounded-square',
|
||||
|
||||
@ -71,6 +71,12 @@ export class ResumeController {
|
||||
return this.resumeService.update(+id, updateResumeDto, userId);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete('/all')
|
||||
removeAllByUser(@User('id') userId: number) {
|
||||
return this.resumeService.removeAllByUser(userId);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string, @User('id') userId: number) {
|
||||
|
||||
@ -176,8 +176,12 @@ export class ResumeService {
|
||||
return this.resumeRepository.save<Resume>(updatedResume);
|
||||
}
|
||||
|
||||
async remove(id: number, userId: number) {
|
||||
await this.resumeRepository.delete({ id, user: { id: userId } });
|
||||
remove(id: number, userId: number) {
|
||||
return this.resumeRepository.delete({ id, user: { id: userId } });
|
||||
}
|
||||
|
||||
removeAllByUser(userId: number) {
|
||||
return this.resumeRepository.delete({ user: { id: userId } });
|
||||
}
|
||||
|
||||
async duplicate(id: number, userId: number) {
|
||||
|
||||
Reference in New Issue
Block a user