diff --git a/src/controllers/calendarController.ts b/src/controllers/calendarController.ts index 077b27f..3ae6056 100644 --- a/src/controllers/calendarController.ts +++ b/src/controllers/calendarController.ts @@ -36,6 +36,15 @@ export async function GetStoreId(req: Request, res: Response) { } } +enum CalendarStatus { + NOT_CONNECTED = "NOT_CONNECTED", // this is a custom status + // the following statuses are from termin planner + PENDING = "PENDING", + OK = "OK", + NOPERM = "NOPERM", + ERROR = "ERROR", +} + export async function GetCalendarSettings(req: Request, res: Response) { try { const userSession = await getUserSession(req); @@ -50,11 +59,18 @@ export async function GetCalendarSettings(req: Request, res: Response) { where: { user_id: userSession.user_id, }, + attributes: ["status"], }); if (!userGoogleToken) { return res.status(200).send({ - connected: false, + status: CalendarStatus.NOT_CONNECTED, + }); + } + + if (userGoogleToken.status !== CalendarStatus.OK) { + return res.status(200).send({ + status: userGoogleToken.status, }); } @@ -90,12 +106,14 @@ export async function GetCalendarSettings(req: Request, res: Response) { if (!store) { // user is not store owner - means he is an employee res.status(200).send({ + status: userGoogleToken.status, settings: user, }); return; } // user is store owner res.status(200).send({ + status: userGoogleToken.status, storeSettings: store, userSettings: user, }); diff --git a/src/models/userGoogleTokens.ts b/src/models/userGoogleTokens.ts index 51e07ae..d4cef79 100644 --- a/src/models/userGoogleTokens.ts +++ b/src/models/userGoogleTokens.ts @@ -9,6 +9,7 @@ interface UserGoogleTokensAttributes { user_id: string; access_token?: string; refresh_token?: string; + status?: string; expiry_date?: Date; google_uuid?: string; created_at?: Date; @@ -22,6 +23,7 @@ class UserGoogleTokens declare user_id: string; declare access_token: string; declare refresh_token: string; + declare status: string; declare expiry_date: Date; declare google_uuid: string; declare created_at: Date; @@ -44,6 +46,10 @@ UserGoogleTokens.init( type: DataTypes.STRING, // allowNull defaults to true }, + status: { + type: DataTypes.STRING, + // allowNull defaults to true + }, expiry_date: { type: DataTypes.DATE, // allowNull defaults to true