Skip to content

Commit

Permalink
Merge pull request #26 from skku-npc/dev/calendar-api
Browse files Browse the repository at this point in the history
Fix calendar event schema
  • Loading branch information
threedalpeng authored Feb 27, 2021
2 parents c7a5015 + 1c0a499 commit 07684e7
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions backend/routes/calendar/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ async function getEvents(req, res) {
const lastDay = new Date(year, month);
events = await prisma.event.findMany({
where: {
startDate: {
start: {
lt: lastDay,
},
endDate: {
end: {
gte: firstDay,
},
},
Expand All @@ -35,10 +35,10 @@ async function getEvents(req, res) {
const lastDay = new Date(year + 1, 0);
events = await prisma.event.findMany({
where: {
startDate: {
start: {
lt: lastDay,
},
endDate: {
end: {
gte: firstDay,
},
},
Expand All @@ -58,8 +58,8 @@ async function createNewEvent(req, res) {
const eventCreated = await prisma.event.create({
data: {
...req.body,
startDate: new Date(req.body.startDate),
endDate: new Date(req.body.endDate),
start: new Date(req.body.start),
end: new Date(req.body.end),
},
});
res.status(201).send(eventCreated);
Expand All @@ -78,11 +78,7 @@ async function removeEventById(req, res) {
});
res.status(200).send(eventRemoved);
} catch (e) {
if (e.code === 'P2016') {
res.status(404).send(e);
} else {
res.status(400).send(e);
}
res.status(400).send(e);
}
}

Expand All @@ -97,11 +93,7 @@ async function updateEventById(req, res) {
});
res.status(200).send(eventUpdated);
} catch (e) {
if (e.code === 'P2016') {
res.status(404).send(e);
} else {
res.status(400).send(e);
}
res.status(400).send(e);
}
}

Expand Down

0 comments on commit 07684e7

Please sign in to comment.