fix(api): make delete user with images actually delete their images from the datasource
This commit is contained in:
parent
5965c2e237
commit
06d1c0bc3b
1 changed files with 11 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
import { NextApiReq, NextApiRes, withZipline } from 'middleware/withZipline';
|
||||
import prisma from 'lib/prisma';
|
||||
import Logger from 'lib/logger';
|
||||
import datasource from 'lib/ds';
|
||||
|
||||
async function handler(req: NextApiReq, res: NextApiRes) {
|
||||
const user = await req.user();
|
||||
|
@ -18,6 +19,16 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
|||
if (!deleteUser) return res.forbid('user doesn\'t exist');
|
||||
|
||||
if (req.body.delete_images) {
|
||||
const files = await prisma.image.findMany({
|
||||
where: {
|
||||
userId: deleteUser.id,
|
||||
},
|
||||
});
|
||||
|
||||
for (let i = 0; i !== files.length; ++i) {
|
||||
await datasource.delete(files[i].file);
|
||||
}
|
||||
|
||||
const { count } = await prisma.image.deleteMany({
|
||||
where: {
|
||||
userId: deleteUser.id,
|
||||
|
|
Loading…
Reference in a new issue