mirror of
https://github.com/stonith404/pingvin-share.git
synced 2025-01-29 01:28:59 -05:00
fix: delete share files if user gets deleted
This commit is contained in:
parent
0b07bfbc14
commit
e71f6cd159
2 changed files with 14 additions and 1 deletions
|
@ -2,9 +2,10 @@ import { Module } from "@nestjs/common";
|
|||
import { EmailModule } from "src/email/email.module";
|
||||
import { UserController } from "./user.controller";
|
||||
import { UserSevice } from "./user.service";
|
||||
import { FileModule } from "src/file/file.module";
|
||||
|
||||
@Module({
|
||||
imports: [EmailModule],
|
||||
imports: [EmailModule, FileModule],
|
||||
providers: [UserSevice],
|
||||
controllers: [UserController],
|
||||
})
|
||||
|
|
|
@ -4,6 +4,7 @@ import * as argon from "argon2";
|
|||
import * as crypto from "crypto";
|
||||
import { EmailService } from "src/email/email.service";
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
import { FileService } from "../file/file.service";
|
||||
import { CreateUserDTO } from "./dto/createUser.dto";
|
||||
import { UpdateUserDto } from "./dto/updateUser.dto";
|
||||
|
||||
|
@ -12,6 +13,7 @@ export class UserSevice {
|
|||
constructor(
|
||||
private prisma: PrismaService,
|
||||
private emailService: EmailService,
|
||||
private fileService: FileService,
|
||||
) {}
|
||||
|
||||
async list() {
|
||||
|
@ -74,6 +76,16 @@ export class UserSevice {
|
|||
}
|
||||
|
||||
async delete(id: string) {
|
||||
const user = await this.prisma.user.findUnique({
|
||||
where: { id },
|
||||
include: { shares: true },
|
||||
});
|
||||
if (!user) throw new BadRequestException("User not found");
|
||||
|
||||
await Promise.all(
|
||||
user.shares.map((share) => this.fileService.deleteAllFiles(share.id)),
|
||||
);
|
||||
|
||||
return await this.prisma.user.delete({ where: { id } });
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue