diff --git a/api/src/migrations/001_create_initial_tables.sql b/api/src/migrations/001_create_initial_tables.sql index 2a200ce..0b68480 100644 --- a/api/src/migrations/001_create_initial_tables.sql +++ b/api/src/migrations/001_create_initial_tables.sql @@ -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) ); @@ -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) ); @@ -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) ); diff --git a/api/src/migrations/002_create_sample_data.sql b/api/src/migrations/002_create_sample_data.sql index 3840d57..bb4ac37 100644 --- a/api/src/migrations/002_create_sample_data.sql +++ b/api/src/migrations/002_create_sample_data.sql @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/api/src/mutations/event.js b/api/src/mutations/event.js index 2e5719e..1f42f67 100644 --- a/api/src/mutations/event.js +++ b/api/src/mutations/event.js @@ -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; } @@ -31,6 +42,8 @@ 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 || []; @@ -38,8 +51,8 @@ async function insertNewEvent(eventInput) { 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, @@ -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); @@ -74,7 +89,9 @@ async function insertNewEvent(eventInput) { location, current_capacity, picture_path, - id + id, + website, + location_link }; } diff --git a/api/src/mutations/seminar.js b/api/src/mutations/seminar.js index e177d99..796a91b 100644 --- a/api/src/mutations/seminar.js +++ b/api/src/mutations/seminar.js @@ -1,5 +1,6 @@ const { db } = require("../db"); const { queryEventByID } = require("../resolvers/event"); +const { queryOrganizerByTypeID } = require("../resolvers/searchResults"); async function insertNewSeminar(seminarInput) { let { @@ -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") { @@ -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); @@ -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, @@ -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 (?, ?); `; @@ -106,7 +119,9 @@ async function insertNewSeminar(seminarInput) { location, picture_path, current_capacity, - id + id, + website, + location_link }; } diff --git a/api/src/resolvers/searchResults.js b/api/src/resolvers/searchResults.js index c9f4100..313f937 100644 --- a/api/src/resolvers/searchResults.js +++ b/api/src/resolvers/searchResults.js @@ -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 { @@ -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"); @@ -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) @@ -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) { @@ -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( @@ -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( @@ -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; @@ -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", @@ -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") diff --git a/api/src/types/Event.js b/api/src/types/Event.js index f407975..8260e9e 100644 --- a/api/src/types/Event.js +++ b/api/src/types/Event.js @@ -1,57 +1,59 @@ const Event = ` -type Event { - - id: Int! - creator_id: Int! - name: String! - description: String - - start_time: String! - end_time: String! - - """ If the capacity_type is FCFS_P or FCFS_P """ - capacity_type: capacity_type! - max_capacity: Int - current_capacity: Int - - location: String - - # still need to add photo - picture_path: String - - #Testing attaching announcements to an event - announcements: [Announcement!] - organizers: [User!] - seminars: [Seminar!] - -} - -input EventInput { - creator_id: Int! - name: String! - description: String - - """ Must be formatted as 2019-10-20 10:30 YYYY-MM-DD HH:MM""" - start_time: String! - - """ Must be formatted as 2019-10-20 10:30 YYYY-MM-DD HH:MM""" - end_time: String! - - """ If the capacity_type is FCFS_P or FCFS_P """ - capacity_type: capacity_type! - max_capacity: Int - organizer_ids: [Int!] - location: String - picture_path: String -} - - -input EventParticipationInput { - userid: Int! - eventid: Int! - participationType: participation_type! - -} + type Event { + id: Int! + creator_id: Int! + name: String! + description: String + + start_time: String! + end_time: String! + + """ If the capacity_type is FCFS_P or FCFS_P """ + capacity_type: capacity_type! + max_capacity: Int + current_capacity: Int + location: String + location_link: String + website: String + + # still need to add photo + picture_path: String + + #Testing attaching announcements to an event + announcements: [Announcement!] + organizers: [User!] + seminars: [Seminar!] + + } + + input EventInput { + creator_id: Int! + name: String! + description: String + + """ Must be formatted as 2019-10-20 10:30 YYYY-MM-DD HH:MM""" + start_time: String! + + """ Must be formatted as 2019-10-20 10:30 YYYY-MM-DD HH:MM""" + end_time: String! + + """ If the capacity_type is FCFS_P or FCFS_P """ + capacity_type: capacity_type! + max_capacity: Int + organizer_ids: [Int!] + location: String + location_link: String + picture_path: String + website: String + } + + + input EventParticipationInput { + userid: Int! + eventid: Int! + participationType: participation_type! + + } `; diff --git a/api/src/types/Seminar.js b/api/src/types/Seminar.js index fdf27ee..6cfdbb2 100644 --- a/api/src/types/Seminar.js +++ b/api/src/types/Seminar.js @@ -1,5 +1,5 @@ const Seminar = ` -type Seminar { + type Seminar { id: Int! event_id: Int! name: String! @@ -10,29 +10,31 @@ type Seminar { max_capacity: Int current_capacity: Int location: Int + location_link: String picture_path: Int - - #Testing attaching announcements to an seminar - announcements: [Announcement!] - organizers: [User!] - + website: String + announcements: [Announcement!] + organizers: [User!] + } - -input SeminarInput { - event_id: Int! - name: String! - description: String - """ Must be formatted as 2019-10-20 10:30 YYYY-MM-DD HH:MM""" - start_time: String! - """ Must be formatted as 2019-10-20 10:30 YYYY-MM-DD HH:MM""" - end_time: String! - capacity_type: capacity_type! - max_capacity: Int - organizer_ids: [Int!] - location: String - picture_path: String -} + input SeminarInput { + event_id: Int! + name: String! + description: String + """ Must be formatted as 2019-10-20 10:30 YYYY-MM-DD HH:MM""" + start_time: String! + + """ Must be formatted as 2019-10-20 10:30 YYYY-MM-DD HH:MM""" + end_time: String! + capacity_type: capacity_type! + max_capacity: Int + organizer_ids: [Int!] + location: String + location_link: String + picture_path: String + website: String + } input SeminarParticipationInput { userid: Int!