fix not being able to delete orphaned content

This commit is contained in:
MeowcaTheoRange 2024-04-25 17:14:53 -05:00
parent 5db0a9edc3
commit 4f6298d380

View file

@ -166,29 +166,23 @@ export async function DELETE(request: NextRequest, {params}: {params: {content:s
status: 400 status: 400
}); });
let jamParent = await db let jamParentOwner, jamParent = await db
.selectFrom('jams') .selectFrom('jams')
.where('jams.id', '=', deletingContent.jam_id) .where('jams.id', '=', deletingContent.jam_id)
.select('author_id') .select('author_id')
.executeTakeFirst(); .executeTakeFirst();
if (jamParent == null) return new Response('', { if (jamParent != null) {
status: 500 jamParentOwner = await db
});
let jamParentOwner = await db
.selectFrom('users') .selectFrom('users')
.where('users.id', '=', jamParent.author_id) .where('users.id', '=', jamParent.author_id)
.select('id') .select('id')
.executeTakeFirst(); .executeTakeFirst();
}
if (jamParentOwner == null) return new Response('', {
status: 500
});
if ( if (
!existingUser?.admin !existingUser?.admin
&& jamParentOwner.id != existingUser.id && (jamParentOwner?.id != existingUser.id)
&& deletingContent.author_id != existingUser.id && deletingContent.author_id != existingUser.id
) return new Response('you are NOT that guy.', { ) return new Response('you are NOT that guy.', {
status: 401 status: 401