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) { export async function GetCalendarSettings(req: Request, res: Response) {
try { try {
const userSession = await getUserSession(req); const userSession = await getUserSession(req);
@ -50,11 +59,18 @@ export async function GetCalendarSettings(req: Request, res: Response) {
where: { where: {
user_id: userSession.user_id, user_id: userSession.user_id,
}, },
attributes: ["status"],
}); });
if (!userGoogleToken) { if (!userGoogleToken) {
return res.status(200).send({ 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) { if (!store) {
// user is not store owner - means he is an employee // user is not store owner - means he is an employee
res.status(200).send({ res.status(200).send({
status: userGoogleToken.status,
settings: user, settings: user,
}); });
return; return;
} }
// user is store owner // user is store owner
res.status(200).send({ res.status(200).send({
status: userGoogleToken.status,
storeSettings: store, storeSettings: store,
userSettings: user, userSettings: user,
}); });

View File

@ -9,6 +9,7 @@ interface UserGoogleTokensAttributes {
user_id: string; user_id: string;
access_token?: string; access_token?: string;
refresh_token?: string; refresh_token?: string;
status?: string;
expiry_date?: Date; expiry_date?: Date;
google_uuid?: string; google_uuid?: string;
created_at?: Date; created_at?: Date;
@ -22,6 +23,7 @@ class UserGoogleTokens
declare user_id: string; declare user_id: string;
declare access_token: string; declare access_token: string;
declare refresh_token: string; declare refresh_token: string;
declare status: string;
declare expiry_date: Date; declare expiry_date: Date;
declare google_uuid: string; declare google_uuid: string;
declare created_at: Date; declare created_at: Date;
@ -44,6 +46,10 @@ UserGoogleTokens.init(
type: DataTypes.STRING, type: DataTypes.STRING,
// allowNull defaults to true // allowNull defaults to true
}, },
status: {
type: DataTypes.STRING,
// allowNull defaults to true
},
expiry_date: { expiry_date: {
type: DataTypes.DATE, type: DataTypes.DATE,
// allowNull defaults to true // allowNull defaults to true