[Feature] Implement Self-Serve Account Deletion

This commit is contained in:
Amruth Pillai
2023-01-19 00:11:15 +01:00
parent 5024c19f87
commit ff101dbfac
14 changed files with 235 additions and 14 deletions

View File

@ -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()

View File

@ -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);
}

View File

@ -0,0 +1,7 @@
import { IsNotEmpty, IsString, MinLength } from 'class-validator';
export class UpdateProfileDto {
@IsString()
@IsNotEmpty()
name: string;
}

View File

@ -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',

View File

@ -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) {

View File

@ -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) {