calendar status

main
alex 2024-01-26 22:07:53 +01:00
parent 680a062315
commit c09245eaef
2 changed files with 25 additions and 1 deletions

View File

@ -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,
});

View File

@ -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