fix(services): realtime edge cases
This commit is contained in:
@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user