Skip to content

Instantly share code, notes, and snippets.

@jbis9051
Created November 14, 2019 16:46
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 jbis9051/be945697f24e0a06047ab01ef83dfaf1 to your computer and use it in GitHub Desktop.
Save jbis9051/be945697f24e0a06047ab01ef83dfaf1 to your computer and use it in GitHub Desktop.
return (
(body['adult-tickets'] && body['student-ticket']) // make sure that the number of tickets are there (we use this to calculate price)
&& (/^\d+$/.test(body["adult-tickets"]) && /^\d+$/.test(body["student-tickets"])) // make sure they are numbers
&& (body["adult-tickets"] = parseInt(body["adult-tickets"])) // parse em and make sure it worked
&& (body["student-tickets"] = parseInt(body["student-tickets"]))
&& (body["adult-tickets"] > 0 || body["student-tickets"] > 0) // check that either student or adult ticket forms were included
&& (body["adult_tickets"].length === body["adult-tickets"] || body["student_tickets"].length === body["student-tickets"]) // check that we have all the forms and no more
&& [body["adult_tickets"], body["student_tickets"]].every(
b => keys.every(e => Object.keys(b).includes(e) && b[e].length < 255)) // make sure all the keys in the above array are in the all of the inputs for each
&& [body["adult_tickets"], body["student_tickets"]]
.every(tickets =>
tickets.every(ticket =>
keys.every(key =>
Object.keys(ticket).includes(key) // make sure all the keys in the above array are in the all of the inputs for each
&& ticket[key].length < 255)
&& (ticket.gender === "male" || ticket.gender === "female") // and that gender is either male or female
)
&& states.includes(body.state)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment