Skip to content

Commit

Permalink
Fix calendar event schema
Browse files Browse the repository at this point in the history
  • Loading branch information
threedalpeng committed Feb 25, 2021
1 parent f7690bd commit 1c0a499
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 1c0a499

Please sign in to comment.