fix(services): allow deletion of channel if there's more than 1 channel

This commit is contained in:
Divlo
2022-03-01 08:53:20 +01:00
parent f74cf25a68
commit d3a777c82a
6 changed files with 28 additions and 4 deletions

View File

@ -61,6 +61,14 @@ export const deleteChannelService: FastifyPluginAsync = async (fastify) => {
if (!member.isOwner) {
throw fastify.httpErrors.badRequest('You should be a member owner')
}
const channelCount = await prisma.channel.count({
where: { guildId: channelCheck.guildId }
})
if (channelCount <= 1) {
throw fastify.httpErrors.badRequest(
'The guild should have at least one channel'
)
}
const channel = await prisma.channel.delete({
where: { id: channelId }
})