Skip to content

Instantly share code, notes, and snippets.

@MadaraUchiha
Created August 16, 2017 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MadaraUchiha/eb13b3c29b26e7f53a1d849beaf0ddd0 to your computer and use it in GitHub Desktop.
Save MadaraUchiha/eb13b3c29b26e7f53a1d849beaf0ddd0 to your computer and use it in GitHub Desktop.
export async function reserve(req, res) {
try {
const locker = await Locker.find({
where: {
_id: req.params.id
}
});
await handleEntityNotFound(res, true)(locker);
const reservation = req.body.reservation || {};
if (!reservation.tmpToken) {
reservation.tmpToken = req.cookies.tmpToken;
}
const canDoReservation = await checkCanDoReservation({ locker, reservation });
const { tmpToken } = await doReserving(canDoReservation);
res.cookie('tmpToken', tmpToken, { maxAge: 600000, httpOnly: true });
return await respondWithResult(res)({ tmpToken });
} catch (e) {
return await handleError(res, 204);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment