Skip to content

Commit

Permalink
feat: new rest api
Browse files Browse the repository at this point in the history
- use regular REST routes
  • Loading branch information
cgawron committed Oct 17, 2024
1 parent 229aa17 commit 93ec39b
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 23 deletions.
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"nodemailer": "^6.4.14",
"remark": "15.0.1",
"remark-html": "16.0.1",
"tsdav": "^2.1.2",
"validator": "^13.12.0"
},
"devDependencies": {
Expand Down
12 changes: 6 additions & 6 deletions backend/src/controller/event_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ export const getAvailableTimes = (req: Request, res: Response): void => {
});

function calculateBlocked(events, event, timeMin, timeMax) {
const days = {};
const eventsPerDay = {};
const blocked = new IntervalSet([{ start: timeMin, end: timeMin }, { start: timeMax, end: timeMax }]);
events.forEach(evt => {
console.log('event: %o', evt);
if (!evt.start.dateTime) {
return;
}
const day = startOfDay(new Date(evt.start.dateTime)).toISOString();
if (day in days) {
days[day] += 1;
if (day in eventsPerDay) {
eventsPerDay[day] += 1;
} else {
days[day] = 1;
eventsPerDay[day] = 1;
}
});
for (const day in days) {
if (days[day] >= event.maxPerDay) {
for (const day in eventsPerDay) {
if (eventsPerDay[day] >= event.maxPerDay) {
blocked.addRange({ start: new Date(day), end: addDays(new Date(day), 1) });
}
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/controller/user_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const putUser = (req: Request, res: Response): void => {
* @param {response} res
*/
export const getUserByUrl = (req: Request, res: Response): void => {
const user_url = req.query.url;
const user_url = req.params.url || req.query.url;
UserModel.findOne({ user_url: <string>user_url })

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a
user-provided value
.
.select("_id email name picture_url user_url welcome")
.exec()
Expand Down
6 changes: 0 additions & 6 deletions client/cypress/fixtures/calendarList.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
"comment": "gzip"
}
],
"headers": {
"x-goog-api-client": "gdcl/7.0.1 gl-node/18.20.4",
"Accept-Encoding": "gzip",
"User-Agent": "google-api-nodejs-client/7.0.1 (gzip)",
"Authorization": "Bearer ya29.a0AcM612xf6HxDLrtzihWDcobYv77tDABBNZNwcu5XLwk5BzBXHZu-Ye4S0YxrCSt83JWC8FccCnXK_1iTBWGoIH3UKdto0T-gYMFl0fp5_JzAd5kLMuiAARQSe0a0-y7Jyt8CPMmPVTxxwaI5oFoVATPVTt6puxwXQsc7g-e9TwaCgYKAcwSARMSFQHGX2Mis5a6O2i8pMPSovpLdBf3Pw0177"
},
"params": {},
"retry": true,
"responseType": "unknown"
Expand Down
5 changes: 1 addition & 4 deletions client/cypress/fixtures/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@
],
"updatedAt": "2024-10-05T15:09:00.077Z",
"user_url": "christian-gawron",
"push_calendar": "t6hldgptmgr36ctkm1720bvcfg@group.calendar.google.com",
"google_tokens": {
"access_token": "ya29.a0AcM612xTO2HcmaSxOzyMlf3hje-CL8WGmBrfUtM_mrOTWOfj6gbFgFtr6jSRI4GGmwK9fCS4paZroX9Wq3JPt-Q0oC0Hbx2WUSpufG2gU98Y2ZkK0TcVNhi72vFkr60vU7ROpi55csAHmgQM8onpGfy51x8iGdZDdH1KSBg1aCgYKAZcSARMSFQHGX2Mi0IhuHlo5kYzESZHe0G5l-w0175"
}
"push_calendar": "t6hldgptmgr36ctkm1720bvcfg@group.calendar.google.com"
}
10 changes: 5 additions & 5 deletions client/src/helpers/services/event_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function saveUserEvent(
userid: string
) {
const response = await axios.post(
`${import.meta.env.REACT_APP_API_URL}/events/addEvent`,
`${import.meta.env.REACT_APP_API_URL}/events/event`,
{ ...event, user: userid },
{
withCredentials: true,
Expand All @@ -17,7 +17,7 @@ export async function saveUserEvent(

export async function deleteEvent(id: string) {
const response = await axios.delete(
`${import.meta.env.REACT_APP_API_URL}/events/deleteEvent/${id}`,
`${import.meta.env.REACT_APP_API_URL}/events/event/${id}`,
{
withCredentials: true,
}
Expand All @@ -28,7 +28,7 @@ export async function deleteEvent(id: string) {

export async function getEventByID(id: string) {
const response = await axios.get(
`${import.meta.env.REACT_APP_API_URL}/events/getEvent/${id}`,
`${import.meta.env.REACT_APP_API_URL}/events/event/${id}`,
{
withCredentials: true,
}
Expand All @@ -43,7 +43,7 @@ export async function updateEvent(
) {
console.log('available: %o', event.available);
const response = await axios.put(
`${import.meta.env.REACT_APP_API_URL}/events/updateEvent/${id}`,
`${import.meta.env.REACT_APP_API_URL}/events/event/${id}`,
{
data: event
},
Expand Down Expand Up @@ -81,7 +81,7 @@ export function getAvailableTimes(timeMin: Date, timeMax: Date, url: string, use

export async function getUsersEvents() {
const response = await axios.get(
`${import.meta.env.REACT_APP_API_URL}/events/getEvents`,
`${import.meta.env.REACT_APP_API_URL}/events/event`,
{
withCredentials: true,
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/helpers/services/user_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function updateUser(user: any) {

export async function getUserByUrl(url: string) {
return axios.get(
`${import.meta.env.REACT_APP_API_URL}/users/findUserByUrl`,
`${import.meta.env.REACT_APP_API_URL}/users/user/${url}`,
{
params: { url: url },
}
Expand Down
38 changes: 38 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6935,6 +6935,7 @@ __metadata:
supertest: "npm:^7.0.0"
ts-jest: "npm:^29.2.5"
ts-node: "npm:^10.9.1"
tsdav: "npm:^2.1.2"
typescript: "npm:^5.6.2"
validator: "npm:^13.12.0"
vitest: "npm:^2.1.3"
Expand Down Expand Up @@ -6962,6 +6963,13 @@ __metadata:
languageName: node
linkType: hard

"base-64@npm:1.0.0":
version: 1.0.0
resolution: "base-64@npm:1.0.0"
checksum: 10/d10b64a1fc9b2c5a5f39f1ce1e6c9d1c5b249222bbfa3a0604c592d90623caf74419983feadd8a170f27dc0c3389704f72faafa3e645aeb56bfc030c93ff074a
languageName: node
linkType: hard

"base64-js@npm:^1.3.0, base64-js@npm:^1.3.1":
version: 1.5.1
resolution: "base64-js@npm:1.5.1"
Expand Down Expand Up @@ -19515,6 +19523,13 @@ __metadata:
languageName: node
linkType: hard

"sax@npm:^1.2.4":
version: 1.4.1
resolution: "sax@npm:1.4.1"
checksum: 10/b1c784b545019187b53a0c28edb4f6314951c971e2963a69739c6ce222bfbc767e54d320e689352daba79b7d5e06d22b5d7113b99336219d6e93718e2f99d335
languageName: node
linkType: hard

"scheduler@npm:^0.23.2":
version: 0.23.2
resolution: "scheduler@npm:0.23.2"
Expand Down Expand Up @@ -21178,6 +21193,18 @@ __metadata:
languageName: node
linkType: hard

"tsdav@npm:^2.1.2":
version: 2.1.2
resolution: "tsdav@npm:2.1.2"
dependencies:
base-64: "npm:1.0.0"
cross-fetch: "npm:4.0.0"
debug: "npm:4.3.7"
xml-js: "npm:1.6.11"
checksum: 10/133b4a0ae3fea51034a2aa63d01dae1dec317102e4d12b87944e7a8e5a8ea6fe6cc3722949d6a4eff9fe147df4960975e8ee57772a5b6d4bd9530abe99089e96
languageName: node
linkType: hard

"tslib@npm:^1.8.1, tslib@npm:^1.9.0, tslib@npm:^1.9.3":
version: 1.14.1
resolution: "tslib@npm:1.14.1"
Expand Down Expand Up @@ -22577,6 +22604,17 @@ __metadata:
languageName: node
linkType: hard

"xml-js@npm:1.6.11":
version: 1.6.11
resolution: "xml-js@npm:1.6.11"
dependencies:
sax: "npm:^1.2.4"
bin:
xml-js: ./bin/cli.js
checksum: 10/55ce342a47bf14a138a3fcea0c9e325b81484cfc1a8aac78df13b4d6ca01f20e32820572bc3e927cd9b61b9da9cdee4657cb2f304e460343d8d85d6a3659d749
languageName: node
linkType: hard

"xmlcreate@npm:^2.0.4":
version: 2.0.4
resolution: "xmlcreate@npm:2.0.4"
Expand Down

0 comments on commit 93ec39b

Please sign in to comment.