Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .claspignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@
.git/**
node_modules/**
src/**
frontend/**
backend/**
packages/**
24 changes: 18 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,36 @@
set -e

echo "Building backend..."
pushd backend
pushd packages/backend
#if node_modules doesn't exist, npm install
if [ ! -d "node_modules" ]; then
npm install
fi
npm run build
popd
echo "Backend built successfully!"
pushd frontend

pushd packages/frontend
if [ ! -d "node_modules" ]; then
npm install
fi
npm run build
popd
echo "Frontend built successfully!"
mkdir -p dist
rm -rf dist/*
cp backend/dist/* dist/
cp frontend/dist/* dist/

pushd packages/cli
if [ ! -d "node_modules" ]; then
npm install
fi
npm run build
popd
echo "CLI built successfully!"

rm -rf packages/cli/dist/google_apps_script/
mkdir -p packages/cli/dist/google_apps_script/

cp packages/backend/dist/* packages/cli/dist/google_apps_script/
cp packages/frontend/dist/* packages/cli/dist/google_apps_script/
mv packages/cli/dist/appsscript.json packages/cli/dist/google_apps_script/

echo "Build complete!"
File renamed without changes.
4 changes: 1 addition & 3 deletions backend/package.json → packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"push": "clasp push",
"deploy": "npm run build && npm run push"
"build": "tsc"
},
"keywords": [],
"author": "",
Expand Down
62 changes: 32 additions & 30 deletions backend/src/app.ts → packages/backend/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
const CALENDAR = "primary";
const TIME_ZONE = "America/New_York";
// America/Los_Angeles
// America/Denver
// America/Chicago
// Europe/London
// Europe/Berlin
const WORKDAYS = [1, 2, 3, 4, 5];
const WORKHOURS = {
start: 9,
end: 13,
declare function getConfiguration(): {
calendar: string;
time_zone: string;
workdays: [number];
workhours: { start: number; end: number };
days_in_advance: 28;
timeslot_duration: number;
};
const DAYS_IN_ADVANCE = 28;
//high numbered days in advance cause significant loading time slow down
const TIMESLOT_DURATION = 30;

const TSDURMS = TIMESLOT_DURATION * 60000;

function doGet(): GoogleAppsScript.HTML.HtmlOutput {
return HtmlService.createHtmlOutputFromFile("dist/index")
return HtmlService.createHtmlOutputFromFile("index")
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
.addMetaTag("viewport", "width=device-width, initial-scale=1");
}
Expand All @@ -26,17 +17,20 @@ function fetchAvailability(): {
timeslots: string[];
durationMinutes: number;
} {
const configuration = getConfiguration();
const TSDURMS = configuration.timeslot_duration * 60000;

const nearestTimeslot = new Date(
Math.floor(new Date().getTime() / TSDURMS) * TSDURMS
Math.floor(new Date().getTime() / TSDURMS) * TSDURMS,
);
const calendarId = CALENDAR;
const calendarId = configuration.calendar;
const now = nearestTimeslot;
const end = new Date(
Date.UTC(
now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDate() + DAYS_IN_ADVANCE
)
now.getUTCDate() + configuration.days_in_advance,
),
);

const response = Calendar.Freebusy!.query({
Expand All @@ -61,34 +55,42 @@ function fetchAvailability(): {
const start = new Date(t);
const end = new Date(t + TSDURMS);
const startTZ = new Date(
Utilities.formatDate(start, TIME_ZONE, "yyyy-MM-dd'T'HH:mm:ss")
Utilities.formatDate(
start,
configuration.time_zone,
"yyyy-MM-dd'T'HH:mm:ss",
),
);
if (startTZ.getHours() < WORKHOURS.start) continue;
if (startTZ.getHours() >= WORKHOURS.end) continue;
if (WORKDAYS.indexOf(startTZ.getDay()) < 0) continue;
if (startTZ.getHours() < configuration.workhours.start) continue;
if (startTZ.getHours() >= configuration.workhours.end) continue;
if (configuration.workdays.indexOf(startTZ.getDay()) < 0) continue;
if (events.some((event) => event.start < end && event.end > start)) {
continue;
}
timeslots.push(start.toISOString());
}
return { timeslots, durationMinutes: TIMESLOT_DURATION };
return { timeslots, durationMinutes: configuration.timeslot_duration };
}

function bookTimeslot(
timeslot: string,
name: string,
email: string,
phone: string,
note: string
note: string,
): string {
const configuration = getConfiguration();

Logger.log(`Booking timeslot: ${timeslot} for ${name}`);
const calendarId = CALENDAR;
const calendarId = configuration.calendar;
const startTime = new Date(timeslot);
if (isNaN(startTime.getTime())) {
throw new Error("Invalid start time");
}
const endTime = new Date(startTime.getTime());
endTime.setUTCMinutes(startTime.getUTCMinutes() + TIMESLOT_DURATION);
endTime.setUTCMinutes(
startTime.getUTCMinutes() + configuration.timeslot_duration,
);

Logger.log(`Timeslot start: ${startTime}, end: ${endTime}`);

Expand Down Expand Up @@ -120,7 +122,7 @@ function bookTimeslot(
guests: email,
sendInvites: true,
status: "confirmed",
}
},
);
Logger.log(`Event created: ${event.getId()}`);
return `Timeslot booked successfully`;
Expand Down
File renamed without changes.
Loading