From 61aa78269221caf09b09eb3f2c3ce1d7730444c0 Mon Sep 17 00:00:00 2001 From: Tamara Charchoghlyan Date: Mon, 12 Nov 2018 13:44:03 -0500 Subject: [PATCH] Seminar mutation (#78) (#81) * Validates seminar start/end datetimes with each other and corresponding event #59, closes #46 * Ignore frontend package-lock file --- .gitignore | 1 + api/src/mutations/seminar.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/.gitignore b/.gitignore index 7f2b7f6..b14817a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ api/node_modules/ api/package-lock.json +frontend/package-lock.json .DS_store \ No newline at end of file diff --git a/api/src/mutations/seminar.js b/api/src/mutations/seminar.js index f42edda..e177d99 100644 --- a/api/src/mutations/seminar.js +++ b/api/src/mutations/seminar.js @@ -1,4 +1,5 @@ const { db } = require("../db"); +const { queryEventByID } = require("../resolvers/event"); async function insertNewSeminar(seminarInput) { let { @@ -34,6 +35,39 @@ async function insertNewSeminar(seminarInput) { organizer_ids = organizer_ids || []; + // console.log(getEventByID(event_id)); + + const temp = await queryEventByID(event_id); + const event_start_time = temp.start_time; + const event_end_time = temp.end_time; + const sem_start_time = new Date(start_time); + const sem_end_time = new Date(end_time); + + if (sem_start_time > sem_end_time) { + console.log("Invalid Start Time: Seminar cannot start after Seminar ends"); + return new Error( + "Unable to create a Seminar: Invalid Start Time: Seminar cannot start after Seminar ends" + ); + } + if (sem_start_time < event_start_time) { + console.log("Invalid Start Time: Seminar cannot start before Event starts"); + return new Error( + "Unable to create a Seminar: Invalid Start Time: Seminar cannot start before Event starts" + ); + } + if (sem_start_time > event_end_time) { + console.log("Invalid Start Time: Seminar cannot start after Event ends"); + return new Error( + "Unable to create a Seminar: Invalid Start Time: Seminar cannot start after Event ends" + ); + } + if (sem_end_time > event_end_time) { + console.log("Invalid End Time: Seminar cannot end after Event ends"); + return new Error( + "Unable to create a Seminar: Invalid End Time: Seminar cannot end after Event ends" + ); + } + const queryString = `INSERT INTO Seminar (event_id, name, description, start_time, end_time, capacity_type, max_capacity, location, picture_path,current_capacity)