Skip to content

Commit

Permalink
Seminar mutation (#78) (#81)
Browse files Browse the repository at this point in the history
* Validates seminar start/end datetimes with each other and corresponding event #59, closes #46

* Ignore frontend package-lock file
  • Loading branch information
Tamara Charchoghlyan authored Nov 12, 2018
1 parent f41c6a6 commit 61aa782
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
api/node_modules/
api/package-lock.json
frontend/package-lock.json
.DS_store
34 changes: 34 additions & 0 deletions api/src/mutations/seminar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { db } = require("../db");
const { queryEventByID } = require("../resolvers/event");

async function insertNewSeminar(seminarInput) {
let {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 61aa782

Please sign in to comment.