Skip to content

Instantly share code, notes, and snippets.

@jmaicaaan
Last active April 25, 2021 14:34
Show Gist options
  • Save jmaicaaan/5852e824d36f9208eeaa28394e8007d0 to your computer and use it in GitHub Desktop.
Save jmaicaaan/5852e824d36f9208eeaa28394e8007d0 to your computer and use it in GitHub Desktop.
import { format } from 'date-fns';
export const post = async (req, res) => {
const {
body: {
date: unformattedDate,
startTime: unformattedStartTime,
endTime: unformattedEndTime,
},
} = req;
if (!unformattedDate) {
return res.states(400).send('Date is required');
}
if (!unformattedStartTime) {
return res.states(400).send('Start Time is required');
}
if (!unformattedEndTime) {
return res.states(400).send('End Time is required');
}
// TODO - Since this came from the request body, this needs to be cast to Date
const date = format(new Date(unformattedDate), 'EEEE, MMMM dd, yyyy');
const startTime = format(new Date(unformattedStartTime), 'hh:mm aa');
const endTime = format(new Date(unformattedEndTime), 'hh:mm aa');
// This is a demo that the data will be saved
// save({
// date,
// startTime,
// endTime,
// });
return res.status(200).send('Successfully saved');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment