fix(api): validate timestamps when creating events and allow setting a location
This commit is contained in:
parent
76e52d53f4
commit
51d02324bd
2 changed files with 31 additions and 1 deletions
|
@ -397,6 +397,12 @@ export const PATCH = auth(async (req, { params }) => {
|
||||||
}
|
}
|
||||||
updateData.end_time = endTimeValidation.getTime().toString();
|
updateData.end_time = endTimeValidation.getTime().toString();
|
||||||
}
|
}
|
||||||
|
if (new Date(start_time) >= new Date(end_time)) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ success: false, message: 'start_time must be before end_time' },
|
||||||
|
{ status: 400 },
|
||||||
|
);
|
||||||
|
}
|
||||||
if (location) updateData.location = location;
|
if (location) updateData.location = location;
|
||||||
if (status) {
|
if (status) {
|
||||||
const validStatuses = ['TENTATIVE', 'CONFIRMED', 'CANCELLED'];
|
const validStatuses = ['TENTATIVE', 'CONFIRMED', 'CANCELLED'];
|
||||||
|
|
|
@ -131,6 +131,8 @@ export const GET = auth(async (req) => {
|
||||||
* end_time:
|
* end_time:
|
||||||
* type: string
|
* type: string
|
||||||
* format: date-time
|
* format: date-time
|
||||||
|
* location:
|
||||||
|
* type: string
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: Event created successfully.
|
* description: Event created successfully.
|
||||||
|
@ -184,7 +186,7 @@ export const POST = auth(async (req) => {
|
||||||
);
|
);
|
||||||
|
|
||||||
const body = await req.json();
|
const body = await req.json();
|
||||||
const { title, description, start_time, end_time } = body;
|
const { title, description, start_time, end_time, location } = body;
|
||||||
|
|
||||||
if (!title || !start_time || !end_time) {
|
if (!title || !start_time || !end_time) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
|
@ -193,12 +195,34 @@ export const POST = auth(async (req) => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNaN(new Date(start_time).getTime())) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ success: false, message: 'Invalid start_time' },
|
||||||
|
{ status: 400 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNaN(new Date(end_time).getTime())) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ success: false, message: 'Invalid end_time' },
|
||||||
|
{ status: 400 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new Date(start_time) >= new Date(end_time)) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ success: false, message: 'start_time must be before end_time' },
|
||||||
|
{ status: 400 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const newEvent = await prisma.meeting.create({
|
const newEvent = await prisma.meeting.create({
|
||||||
data: {
|
data: {
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
start_time,
|
start_time,
|
||||||
end_time,
|
end_time,
|
||||||
|
location: location || '',
|
||||||
organizer_id: req.auth.user.id,
|
organizer_id: req.auth.user.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue