fucking DELETE method for account is now working and existing

This commit is contained in:
cherif
2023-01-17 15:57:43 +01:00
parent 44f9f8e21b
commit c2812c0534
4 changed files with 32 additions and 7 deletions

View File

@@ -146,7 +146,8 @@ export class ChatService {
const user_db = await this.getUserByName(username);
printCaller("-- out ");
return user_db.currentRoom;
if (user_db)
return user_db.currentRoom;
}
async getRoomByName(room_name: string, fieldsToReturn: string[] = null): Promise<Chatroom>

View File

@@ -43,14 +43,14 @@ export class User {
@Column({ nullable: true })
secretTwoFactorAuth: string;
@OneToMany(type => Friendship , (friendship) => friendship.sender)
@OneToMany(type => Friendship , (friendship) => friendship.sender, {onDelete: 'CASCADE'})
sentFriendRequest: Friendship[];
@OneToMany(type => Friendship , (friendship) => friendship.receiver)
@OneToMany(type => Friendship , (friendship) => friendship.receiver, {onDelete: 'CASCADE'})
receivedFriendRequest: Friendship[];
@JoinColumn()
@OneToOne(() => UserStats, { cascade: true })
@OneToOne(() => UserStats, { cascade: true, onDelete: 'CASCADE' })
stats: UserStats;
// ROOMS :

View File

@@ -1,5 +1,5 @@
import {
Body, Controller, Delete, Get, NotFoundException,HttpStatus, Param, Patch, Post, Query, Redirect, Req, Res, UploadedFile, UseGuards, UseInterceptors
Body, Controller, Delete, Get, NotFoundException,HttpStatus, Next, Patch, Post, Query, Redirect, Req, Res, UploadedFile, UseGuards, UseInterceptors
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { Response } from 'express';
@@ -73,8 +73,14 @@ export class UsersController {
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
@Delete()
remove(@Req() req) {
return this.usersService.remove(req.user.id);
remove(@Req() req, @Res() response, @Next() next) {
this.usersService.remove(req.user.id);
req.logout(function(err) {
if (err) { return next(err); }
response.redirect('/');
});
req.session.cookie.maxAge = 0;
return {msg : 'Your account has been deleted'};
}

View File

@@ -108,6 +108,23 @@
avatar = await fetchAvatar(user.username);
}
const deleteAccount = async() => {
console.log("deleting account")
await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user`, {
method: "DELETE",
})
.then((response) => {
if (!response.ok) {
throw new Error("HTTP " + response.status);
}
console.log("account deleted")
push('/');
})
.catch((error) => {
console.log("catch unable to delete: ", error);
});
}
</script>
@@ -152,6 +169,7 @@
</form>
</Card>
</div>
<Button type="primary" on:click={() => deleteAccount()}>Delete Account</Button>
</div>
</main>