Skip to content

Commit

Permalink
Event sem bugs (#92)
Browse files Browse the repository at this point in the history
* throws error if start time of event proceeds end time

* Closes #79, Added announcement root resolver and fixed queryAnnouncementByTypeID to return  all parts of announcements

* Adding website for Events #59

* Adding website for seminar #59

* Adding Location link to event/seminars closes #73

* Closes #90, adds the event organizers as organizers to seminar
  • Loading branch information
alliyya authored and Tamara Charchoghlyan committed Nov 14, 2018
1 parent c4d8cbe commit 3a13107
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 108 deletions.
8 changes: 5 additions & 3 deletions api/src/migrations/001_create_initial_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS Doom_User(
picture_path TEXT,
password_hash TEXT NOT NULL,
confirmed BOOL DEFAULT FALSE,

website TEXT,
PRIMARY KEY (ID)
);

Expand All @@ -31,8 +31,9 @@ CREATE TABLE IF NOT EXISTS Event(
max_capacity INT,
current_capacity INT,
location TEXT,
location_link TEXT,
picture_path TEXT,

website TEXT,
PRIMARY KEY (ID),
FOREIGN KEY (creator_id) REFERENCES Doom_User (ID)
);
Expand All @@ -48,8 +49,9 @@ CREATE TABLE IF NOT EXISTS Seminar(
max_capacity INT,
current_capacity INT,
location TEXT,
location_link TEXT,
picture_path TEXT,

website TEXT,
PRIMARY KEY (ID),
FOREIGN KEY (event_id) REFERENCES Event (ID)
);
Expand Down
8 changes: 6 additions & 2 deletions api/src/migrations/002_create_sample_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ insert into doom_user (first_name, last_name, email, privacy_settings, password_


-- 3 events
insert into Event (creator_id, name, start_time, end_time, capacity_type, max_capacity, current_capacity) values (3,'CUSEC',TIMESTAMP '2019-10-23 8:30:00+02', TIMESTAMP '2019-11-27 10:30:00+02', 'FCFS_E',6,0);
insert into Event (creator_id, name, start_time, end_time, capacity_type, max_capacity, current_capacity, website, location_link) values (3,'CUSEC',TIMESTAMP '2019-10-23 8:30:00+02', TIMESTAMP '2019-11-27 10:30:00+02', 'FCFS_E',6,0,'http://2018.cusec.net/','https://goo.gl/maps/w38KNq2BNLB2');
insert into Event (creator_id, name, start_time, end_time, capacity_type, max_capacity, current_capacity) values (2,'Animefest',TIMESTAMP '2019-10-21 12:30:00+02', TIMESTAMP '2019-11-29 10:30:00+02', 'FCFS_P',3,2);
insert into Event (creator_id, name, start_time, end_time, capacity_type) values (1,'Doomsday convention',TIMESTAMP '2018-10-30 1:00:00', TIMESTAMP '2018-11-02 10:30:00', 'FFA');
insert into Event (creator_id, name, start_time, end_time, capacity_type,max_capacity, current_capacity) values (6,'Avenger Meetup',TIMESTAMP '2019-05-03 10:30:00', TIMESTAMP '2019-11-24 10:30:00', 'FCFS_E',5,0);
Expand All @@ -24,11 +24,13 @@ insert into Event_Organizer (user_id, event_id) values (2,2);
insert into Event_Organizer (user_id, event_id) values (1,3);
insert into Event_Organizer (user_id, event_id) values (6,4);
insert into Event_Organizer (user_id, event_id) values (7,4);
insert into Event_Organizer (user_id, event_id) values (1,4);
insert into Event_Organizer (user_id, event_id) values (3,4);
insert into Event_Organizer (user_id, event_id) values (5,5);


-- 3 Seminars
insert into Seminar (event_id, name, start_time, end_time, capacity_type) values (3,'Preparing for your doom',TIMESTAMP '2019-10-20 10:30:00+02', TIMESTAMP '2019-11-20 12:30:00+02', 'FFA');
insert into Seminar (event_id, name, start_time, end_time, capacity_type,website,location_link) values (3,'Preparing for your doom',TIMESTAMP '2019-10-20 10:30:00+02', TIMESTAMP '2019-11-20 12:30:00+02', 'FFA','https://en.wikipedia.org/wiki/Doctor_Doom','https://goo.gl/maps/kN7Z9ziagyC2');
insert into Seminar (event_id, name, start_time, end_time, capacity_type, max_capacity, current_capacity) values (2,'How to Weeb',TIMESTAMP '2019-10-22 12:30:00+02', TIMESTAMP '2019-11-22 13:30:00+02', 'FCFS_E',2,2);
insert into Seminar (event_id, name, start_time, end_time, capacity_type, max_capacity, current_capacity) values (1,'Hackathon',TIMESTAMP '2019-10-24 8:30:00+02', TIMESTAMP '2019-11-24 10:30:00+02', 'FCFS_P',6,0);
insert into Seminar (event_id, name, start_time, end_time, capacity_type, max_capacity, current_capacity) values (3,'Alpha Demo',TIMESTAMP '2018-10-31 14:50:00', TIMESTAMP '2018-10-31 15:00:00', 'FCFS_P',5,0);
Expand All @@ -37,6 +39,7 @@ insert into Seminar_Organizer (user_id, seminar_id) values (2,2);
insert into Seminar_Organizer (user_id, seminar_id) values (3,1);
insert into Seminar_Organizer (user_id, seminar_id) values (4,3);

insert into Event_Participation (user_id, event_id, attending) values (10,1,True);
insert into Event_Participation (user_id, event_id, attending) values (2,2,True);
insert into Event_Participation (user_id, event_id, attending) values (5,2,True);
insert into Event_Participation (user_id, event_id, attending) values (3,2,True);
Expand All @@ -50,6 +53,7 @@ insert into Event_Participation (user_id, event_id, attending) values (9,4,True)
insert into Event_Participation (user_id, event_id, following) values (10,4,True);


insert into Seminar_Participation (user_id, seminar_id, attending) values (10,1,True);
insert into Seminar_Participation (user_id, seminar_id, attending) values (2,2,True);
insert into Seminar_Participation (user_id, seminar_id, attending) values (5,2,True);
insert into Seminar_Participation (user_id, seminar_id, following) values (3,2,True);
Expand Down
27 changes: 22 additions & 5 deletions api/src/mutations/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@ async function insertNewEvent(eventInput) {
max_capacity,
location,
picture_path,
organizer_ids
organizer_ids,
website,
location_link
} = eventInput;

const event_start_time = new Date(start_time);
const event_end_time = new Date(end_time);
if (event_start_time > event_end_time) {
console.log("Invalid Start Time: Event cannot start after Event ends");
return new Error(
"Unable to create a Event: Invalid Start Time: Event cannot start after Event ends"
);
}

if (capacity_type === "FFA") {
max_capacity = null;
}
Expand All @@ -31,15 +42,17 @@ async function insertNewEvent(eventInput) {
description = description || null;

location = location || null;
location_link = location_link || null;
website = website || null;
picture_path = picture_path || null;

organizer_ids = organizer_ids || [];
organizer_ids.push(creator_id);

const queryString = `INSERT INTO Event
(creator_id, name, description, start_time, end_time, capacity_type,
max_capacity, location, picture_path, current_capacity)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id;`;
max_capacity, location, picture_path, current_capacity, website, location_link)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id;`;

const vals = [
creator_id,
Expand All @@ -51,7 +64,9 @@ async function insertNewEvent(eventInput) {
max_capacity,
location,
picture_path,
current_capacity
current_capacity,
website,
location_link
];

const res = await db.raw(`${queryString}`, vals);
Expand All @@ -74,7 +89,9 @@ async function insertNewEvent(eventInput) {
location,
current_capacity,
picture_path,
id
id,
website,
location_link
};
}

Expand Down
43 changes: 29 additions & 14 deletions api/src/mutations/seminar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { db } = require("../db");
const { queryEventByID } = require("../resolvers/event");
const { queryOrganizerByTypeID } = require("../resolvers/searchResults");

async function insertNewSeminar(seminarInput) {
let {
Expand All @@ -12,7 +13,9 @@ async function insertNewSeminar(seminarInput) {
max_capacity,
location,
picture_path,
organizer_ids
organizer_ids,
website,
location_link
} = seminarInput;

if (capacity_type === "FFA") {
Expand All @@ -30,16 +33,22 @@ async function insertNewSeminar(seminarInput) {
current_capacity = 0;
max_capacity = max_capacity || null;
location = location || null;
location_link = location_link || null;
website = website || null;
description = description || null;
picture_path = picture_path || null;

// Populating organizer IDs to include the creator and organizers of the parent Event
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 organizers = await queryOrganizerByTypeID(event_id);
organizers.forEach(user => {
organizer_ids.push(user.id);
});
organizer_ids = new Set(organizer_ids);
organizer_ids = Array.from(organizer_ids);

// Validating the start time, end time
const parentEvent = await queryEventByID(event_id);
const sem_start_time = new Date(start_time);
const sem_end_time = new Date(end_time);

Expand All @@ -49,29 +58,30 @@ async function insertNewSeminar(seminarInput) {
"Unable to create a Seminar: Invalid Start Time: Seminar cannot start after Seminar ends"
);
}
if (sem_start_time < event_start_time) {
if (sem_start_time < parentEvent.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) {
if (sem_start_time > parentEvent.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) {
if (sem_end_time > parentEvent.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"
);
}

// Inserting seminar into table
const queryString = `INSERT INTO Seminar
(event_id, name, description, start_time, end_time, capacity_type,
max_capacity, location, picture_path,current_capacity)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id;`;
max_capacity, location, picture_path,current_capacity,website,location_link)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id;`;

const vals = [
event_id,
Expand All @@ -83,12 +93,15 @@ async function insertNewSeminar(seminarInput) {
max_capacity,
location,
picture_path,
current_capacity
current_capacity,
website,
location_link
];

const res = await db.raw(`${queryString}`, vals);
const { id } = res.rows[0];

// Adding organizers to the organizer table
for (var i = 0; i < organizer_ids.length; i++) {
const queryString = `INSERT INTO Seminar_Organizer
(user_id,seminar_id) VALUES (?, ?); `;
Expand All @@ -106,7 +119,9 @@ async function insertNewSeminar(seminarInput) {
location,
picture_path,
current_capacity,
id
id,
website,
location_link
};
}

Expand Down
26 changes: 16 additions & 10 deletions api/src/resolvers/searchResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function searchEventsAndSeminars(
description AS description, start_time AS start_time,
end_time AS end_time, capacity_type AS capacity_type,
max_capacity AS max_capacity, current_capacity AS current_capacity,
location AS location, picture_path AS picture_path
location AS location, picture_path AS picture_path, website AS website, location_link AS location_link
FROM ??`;
vals.push("event_id", "event");
} else {
Expand Down Expand Up @@ -51,7 +51,7 @@ async function searchEventsAndSeminars(
description AS description, start_time AS start_time,
end_time AS end_time, capacity_type AS capacity_type,
max_capacity AS max_capacity, current_capacity AS current_capacity,
location AS location, picture_path AS picture_path
location AS location, picture_path AS picture_path, website AS website, location_link AS location_link
FROM ??
${whereClause}`;
vals.push("creator_id", "seminar");
Expand Down Expand Up @@ -83,7 +83,9 @@ async function searchEventsAndSeminars(
max_capacity: searchResult.max_capacity,
current_capacity: searchResult.current_capacity,
location: searchResult.location,
picture_path: searchResult.picture_path
picture_path: searchResult.picture_path,
website: searchResult.website,
location_link: searchResult.location_link
};

if (searchResult.creator_id)
Expand Down Expand Up @@ -151,7 +153,7 @@ async function getMySchedule(
??.description AS description, ??.start_time AS start_time,
??.end_time AS end_time, ??.capacity_type AS capacity_type,
??.max_capacity AS max_capacity, ??.current_capacity AS current_capacity,
??.location AS location, ??.picture_path AS picture_path,`;
??.location AS location, ??.picture_path AS picture_path, ??.website AS website, ??.location_link AS location_link, `;
var whereQueryString = `WHERE ??.user_id = ?`;

if (!participationType) {
Expand All @@ -163,12 +165,12 @@ async function getMySchedule(
}

if (!type || type.toLowerCase() === "event") {
// do both types. Start w/ event and UION ALL w/ seminar
// do both types. Start w/ event and UNION ALL w/ seminar
queryString = `
${selectQueryString} "event".creator_id AS creator_id, NULL AS event_id
FROM ?? JOIN ?? ON (??.?? = ??.id) ${whereQueryString}`;

for (let i = 0; i < 10; i++) {
for (let i = 0; i < 12; i++) {
vals.push("event");
}
vals.push(
Expand Down Expand Up @@ -197,7 +199,7 @@ async function getMySchedule(
${queryString} ${selectQueryString} NULL AS creator_id, "seminar".event_id AS event_id
FROM ?? JOIN ?? ON (??.?? = ??.id) ${whereQueryString}`;

for (let i = 0; i < 10; i++) {
for (let i = 0; i < 12; i++) {
vals.push("seminar");
}
vals.push(
Expand Down Expand Up @@ -240,7 +242,9 @@ async function getMySchedule(
max_capacity: result.max_capacity,
current_capacity: result.current_capacity,
location: result.location,
picture_path: result.picture_path
picture_path: result.picture_path,
website: result.website,
location_link: result.location_link
};

if (result.creator_id) eventOrSeminar.creator_id = result.creator_id;
Expand Down Expand Up @@ -319,7 +323,7 @@ async function getMyManagingSchedule(
WHERE user_id = ?`;

if (!type || type.toLowerCase() === "event") {
// do both types. Start w/ event and UION ALL w/ seminar
// do both types. Start w/ event and UNION ALL w/ seminar
vals.push(
"event_type",
"event_organizer",
Expand Down Expand Up @@ -372,7 +376,9 @@ async function getMyManagingSchedule(
max_capacity: result.max_capacity,
current_capacity: result.current_capacity,
location: result.location,
picture_path: result.picture_path
picture_path: result.picture_path,
website: result.website,
location_link: result.location_link
};

if (result.type === "event_type")
Expand Down
Loading

0 comments on commit 3a13107

Please sign in to comment.