Skip to content

Commit 0230669

Browse files
fix(api): verify instance creation before creating settings to prevent foreign key constraint error
1 parent 4dcbb3a commit 0230669

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/api/controllers/instance.controller.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ export class InstanceController {
7272
status: instanceData.status,
7373
});
7474

75+
// Verifica se a Instance foi criada com sucesso antes de continuar
76+
const createdInstance = await this.prismaRepository.instance.findUnique({
77+
where: { id: instanceId },
78+
});
79+
80+
if (!createdInstance) {
81+
throw new BadRequestException('Failed to create instance in database');
82+
}
83+
7584
// Para WhatsApp Business, setInstance é async e precisa ser aguardado
7685
if (instanceData.integration === Integration.WHATSAPP_BUSINESS) {
7786
await (instance as any).setInstance({

0 commit comments

Comments
 (0)