fix(services): realtime edge cases

This commit is contained in:
Divlo
2022-03-01 23:00:49 +01:00
parent d3a777c82a
commit c23239c0da
16 changed files with 289 additions and 168 deletions

View File

@ -22,7 +22,10 @@ const deleteServiceSchema: FastifySchema = {
] as Array<{ [key: string]: [] }>,
params: parametersSchema,
response: {
200: Type.Object(channelSchema),
200: Type.Object({
...channelSchema,
defaultChannelId: channelSchema.id
}),
400: fastifyErrors[400],
401: fastifyErrors[401],
403: fastifyErrors[403],
@ -72,16 +75,26 @@ export const deleteChannelService: FastifyPluginAsync = async (fastify) => {
const channel = await prisma.channel.delete({
where: { id: channelId }
})
const defaultChannel = await prisma.channel.findFirst({
where: { guildId: member.guildId }
})
if (defaultChannel == null) {
throw fastify.httpErrors.internalServerError()
}
const item = {
...channel,
defaultChannelId: defaultChannel.id
}
await fastify.io.emitToMembers({
event: 'channels',
guildId: member.guildId,
payload: {
action: 'delete',
item: channel
item
}
})
reply.statusCode = 200
return channel
return item
}
})
}