customer-dashboard-api/src/utils/terminPlaner.ts

48 lines
1.1 KiB
TypeScript

import axios from "axios";
import logger from "../logger/logger";
import UserGoogleTokens from "../models/userGoogleTokens";
import { TERMIN_PLANNER_URL } from "./constants";
export async function terminPlanerRequest(
url: string,
method: string,
body: any
) {
return await axios({
url: `${TERMIN_PLANNER_URL}${url}`,
method: method,
data: {
...body,
pass: process.env.TERMIN_PLANNER_AUTHORIZATION_PASSWORD as string,
},
});
}
// check if user has connected with google calendar
export async function isTerminPlanerGoogleCalendarConnected(
userId: string,
attributes?: string[]
) {
try {
const userGoogleToken = await UserGoogleTokens.findOne({
where: {
user_id: userId,
},
attributes: attributes,
});
return userGoogleToken;
} catch (error) {
logger.warn("isTerminPlanerGoogleCalendarConnected err:", error as string);
return null;
}
}
export async function terminPlanerRequestChangeFutureBookingDays(
storeId: string
) {
return await terminPlanerRequest("/api/v1/changeFutureBookingDays", "post", {
storeId: storeId,
});
}