From 92ec3510ccc6abd7aa7220a5ec6b3322bc4efae0 Mon Sep 17 00:00:00 2001 From: Alliyya Mo Date: Mon, 12 Nov 2018 16:50:25 -0500 Subject: [PATCH] Adding website for Events #59 --- .../migrations/001_create_initial_tables.sql | 6 ++--- api/src/migrations/002_create_sample_data.sql | 3 ++- api/src/mutations/event.js | 14 +++++++---- api/src/resolvers/searchResults.js | 23 +++++++++++-------- api/src/types/Event.js | 9 ++++---- 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/api/src/migrations/001_create_initial_tables.sql b/api/src/migrations/001_create_initial_tables.sql index 2a200ce..12f42ac 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) ); @@ -32,7 +32,7 @@ CREATE TABLE IF NOT EXISTS Event( current_capacity INT, location TEXT, picture_path TEXT, - + website TEXT, PRIMARY KEY (ID), FOREIGN KEY (creator_id) REFERENCES Doom_User (ID) ); @@ -49,7 +49,7 @@ CREATE TABLE IF NOT EXISTS Seminar( current_capacity INT, location 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..1cca552 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) 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/'); 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); @@ -37,6 +37,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); diff --git a/api/src/mutations/event.js b/api/src/mutations/event.js index ff70651..fcf2415 100644 --- a/api/src/mutations/event.js +++ b/api/src/mutations/event.js @@ -11,7 +11,8 @@ async function insertNewEvent(eventInput) { max_capacity, location, picture_path, - organizer_ids + organizer_ids, + website } = eventInput; const event_start_time = new Date(start_time); @@ -40,6 +41,7 @@ async function insertNewEvent(eventInput) { description = description || null; location = location || null; + website = website || null; picture_path = picture_path || null; organizer_ids = organizer_ids || []; @@ -47,8 +49,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) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?) RETURNING id;`; const vals = [ creator_id, @@ -60,7 +62,8 @@ async function insertNewEvent(eventInput) { max_capacity, location, picture_path, - current_capacity + current_capacity, + website ]; const res = await db.raw(`${queryString}`, vals); @@ -83,7 +86,8 @@ async function insertNewEvent(eventInput) { location, current_capacity, picture_path, - id + id, + website }; } diff --git a/api/src/resolvers/searchResults.js b/api/src/resolvers/searchResults.js index c9f4100..ddbde14 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 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 FROM ?? ${whereClause}`; vals.push("creator_id", "seminar"); @@ -83,7 +83,8 @@ 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 }; if (searchResult.creator_id) @@ -151,7 +152,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, `; var whereQueryString = `WHERE ??.user_id = ?`; if (!participationType) { @@ -163,12 +164,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 < 11; i++) { vals.push("event"); } vals.push( @@ -197,7 +198,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 < 11; i++) { vals.push("seminar"); } vals.push( @@ -240,7 +241,8 @@ 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 }; if (result.creator_id) eventOrSeminar.creator_id = result.creator_id; @@ -319,7 +321,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 +374,8 @@ 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 }; if (result.type === "event_type") diff --git a/api/src/types/Event.js b/api/src/types/Event.js index f407975..7820df2 100644 --- a/api/src/types/Event.js +++ b/api/src/types/Event.js @@ -13,17 +13,17 @@ type Event { capacity_type: capacity_type! max_capacity: Int current_capacity: Int - location: 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 { @@ -36,13 +36,14 @@ input EventInput { """ 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 + website: String }