From ec89709ad4a8d1e82af9ecc29e4ee3f06d54a1b6 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 11 Feb 2024 13:55:56 +0100 Subject: [PATCH] request when creating user --- src/controllers/usersController.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/controllers/usersController.ts b/src/controllers/usersController.ts index fda74c9..07ca760 100644 --- a/src/controllers/usersController.ts +++ b/src/controllers/usersController.ts @@ -176,16 +176,31 @@ export async function AddEmployee(req: Request, res: Response) { }; } + await User.create(newUser); + const googleCalendarConnected = await isTerminPlanerGoogleCalendarConnected( store.owner_user_id ); // only request terminplaner if google calendar is connected if (googleCalendarConnected) { - await terminPlanerRequest("/api/v1/addUser", "POST", { userId: userId }); - } + try { + await terminPlanerRequest("/api/v1/addUser", "POST", { + userId: userId, + }); - await User.create(newUser); + return res.status(200).send({ msg: "success" }); + } catch (err) { + // remove user from database if terminplaner request failed + await User.destroy({ + where: { + user_id: userId, + }, + }); + + return res.status(500).send({ err: "invalid request" }); + } + } res.status(200).send({ msg: "success" }); } catch (error) {