-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adjust db attribute names, fix some bugs at auth and add schedule event
- Loading branch information
1 parent
5d42c01
commit 6dc68c9
Showing
10 changed files
with
208 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const db = require("../../database/index"); | ||
const eventId = require("../../utils/utils").generateId | ||
const constants = require("../../utils/constants") | ||
|
||
module.exports = { | ||
createEvent: (req, res) => { | ||
console.log("request user data: ", req.userData) | ||
// only organizer can create event | ||
if (req.userData.role !== "organizer") { | ||
return res.status(403).json({ | ||
message: "Forbidden !! You are not allowed to call this function" | ||
}) | ||
} else { | ||
// need to find the id of the red cross since user can only remember name | ||
let sql = "select red_cross_id from red_cross where name = ?" | ||
let values = [[req.body.red_cross_name]] | ||
db.query(sql, [values], function (err, result) { | ||
console.log("result after querying: ", result[0].red_cross_id) | ||
if (result.length === 0) { | ||
return res.status(404).json({ | ||
message: "Cannot find the red cross name", | ||
}); | ||
} else if (err) { | ||
return res.status(503).json({ | ||
message: "There is something wrong when querying", | ||
}); | ||
} else { | ||
|
||
let event_id = eventId() | ||
let values = | ||
req.body.role = | ||
[ | ||
[ | ||
event_id, | ||
result[0].red_cross_id, | ||
req.userData.id, // id of the organizer when using token | ||
req.body.date, | ||
req.body.name, | ||
req.body.location, | ||
constants.pending | ||
] | ||
] | ||
let sql = "insert into event values ?" | ||
db.query(sql, [values], function (err, user) { | ||
if (err || user.length === 0) { | ||
return res.status(400).json({ | ||
message: "Error querying: " + err, | ||
}); | ||
} else { | ||
console.log("USER: ", user) | ||
return res.status(200).json({ | ||
message: "Your event has been created successfully", | ||
event_id: event_id | ||
}); | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
}, | ||
|
||
updateEvent: (req, res) => { | ||
|
||
}, | ||
deleteEvent: (req, res) => { | ||
|
||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const express = require("express"); | ||
|
||
const controller = require("./eventController.js"); | ||
const authMiddleware = require("../../middlewares/authMiddleware.js"); | ||
|
||
const router = express.Router(); | ||
|
||
router.post("/create_event", authMiddleware, controller.createEvent); | ||
|
||
router.post("/update_event", authMiddleware, controller.updateEvent); | ||
|
||
router.post("/delete_event", authMiddleware, controller.deleteEvent); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ USE mydb; | |
|
||
CREATE TABLE donor ( | ||
donor_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL, | ||
donor_name VARCHAR(30) NULL, | ||
name VARCHAR(99) NOT NULL, | ||
password VARCHAR(100) NOT NULL, | ||
email VARCHAR(30) NOT NULL, | ||
address VARCHAR(50) NULL, | ||
|
@@ -18,8 +18,8 @@ CREATE TABLE donor ( | |
DEFAULT CHARACTER SET = utf8; | ||
|
||
CREATE TABLE red_cross ( | ||
redcross_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL, | ||
redcross_name VARCHAR(30) NULL, | ||
red_cross_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL, | ||
name VARCHAR(99) NOT NULL, | ||
password VARCHAR(100) NOT NULL, | ||
email VARCHAR(30) NOT NULL, | ||
address VARCHAR(50) NULL | ||
|
@@ -29,7 +29,7 @@ CREATE TABLE red_cross ( | |
|
||
CREATE TABLE organizer ( | ||
organizer_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL, | ||
organizer_name VARCHAR(30) NULL, | ||
name VARCHAR(99) NOT NULL, | ||
password VARCHAR(100) NOT NULL, | ||
email VARCHAR(30) NOT NULL, | ||
address VARCHAR(50) NULL | ||
|
@@ -39,68 +39,63 @@ CREATE TABLE organizer ( | |
|
||
CREATE TABLE hospital ( | ||
hospital_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL, | ||
redcross_id CHAR(32) UNIQUE NOT NULL, | ||
hospital_name VARCHAR(30) NULL, | ||
red_cross_id CHAR(32) UNIQUE NOT NULL, | ||
name VARCHAR(99) NOT NULL, | ||
password VARCHAR(100) NOT NULL, | ||
email VARCHAR(30) NOT NULL, | ||
address VARCHAR(50) NULL, | ||
FOREIGN KEY (redcross_id) REFERENCES red_cross(redcross_id) | ||
FOREIGN KEY (red_cross_id) REFERENCES red_cross(red_cross_id) | ||
) | ||
ENGINE = INNODB | ||
DEFAULT CHARACTER SET = utf8; | ||
|
||
CREATE TABLE blood_store ( | ||
store_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL, | ||
redcross_id CHAR(32) UNIQUE NOT NULL, | ||
red_cross_id CHAR(32) UNIQUE NOT NULL, | ||
bloodType VARCHAR(5) NOT NULL, | ||
amount DOUBLE PRECISION NULL, | ||
FOREIGN KEY (redcross_id) REFERENCES red_cross(redcross_id) | ||
FOREIGN KEY (red_cross_id) REFERENCES red_cross(red_cross_id) | ||
) | ||
ENGINE = INNODB | ||
DEFAULT CHARACTER SET = utf8; | ||
|
||
CREATE TABLE notification ( | ||
notification_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL, | ||
redcross_id CHAR(32) UNIQUE NOT NULL, | ||
red_cross_id CHAR(32) UNIQUE NOT NULL, | ||
organizer_id CHAR(32) UNIQUE NOT NULL, | ||
noti_date DATETIME NULL, | ||
content VARCHAR(50) NULL, | ||
FOREIGN KEY (redcross_id) REFERENCES red_cross(redcross_id), | ||
FOREIGN KEY (red_cross_id) REFERENCES red_cross(red_cross_id), | ||
FOREIGN KEY (organizer_id) REFERENCES organizer(organizer_id) | ||
) | ||
ENGINE = INNODB | ||
DEFAULT CHARACTER SET = utf8; | ||
|
||
CREATE TABLE event ( | ||
event_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL, | ||
redcross_id CHAR(32) UNIQUE NOT NULL, | ||
red_cross_id CHAR(32) UNIQUE NOT NULL, | ||
organizer_id CHAR(32) UNIQUE NOT NULL, | ||
event_date DATETIME NULL, | ||
event_name VARCHAR(30) NULL, | ||
location VARCHAR(50) NULL, | ||
status VARCHAR(10) NULL, | ||
FOREIGN KEY (redcross_id) REFERENCES red_cross(redcross_id), | ||
event_date DATETIME NOT NULL, | ||
name VARCHAR(99) NOT NULL, | ||
location VARCHAR(50) NOT NULL, | ||
status VARCHAR(10) NOT NULL, | ||
FOREIGN KEY (red_cross_id) REFERENCES red_cross(red_cross_id), | ||
FOREIGN KEY (organizer_id) REFERENCES organizer(organizer_id) | ||
) | ||
ENGINE = INNODB | ||
DEFAULT CHARACTER SET = utf8; | ||
|
||
CREATE TABLE blood ( | ||
blood_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL, | ||
redcross_id CHAR(32) UNIQUE NOT NULL, | ||
red_cross_id CHAR(32) UNIQUE NOT NULL, | ||
event_id CHAR(32) UNIQUE NOT NULL, | ||
donor_id CHAR(32) UNIQUE NOT NULL, | ||
donate_date DATETIME NULL, | ||
amount DOUBLE PRECISION NULL, | ||
status VARCHAR(10) NULL, | ||
FOREIGN KEY (redcross_id) REFERENCES red_cross(redcross_id), | ||
FOREIGN KEY (red_cross_id) REFERENCES red_cross(red_cross_id), | ||
FOREIGN KEY (event_id) REFERENCES event(event_id), | ||
FOREIGN KEY (donor_id) REFERENCES donor(donor_id) | ||
) | ||
ENGINE = INNODB | ||
DEFAULT CHARACTER SET = utf8; | ||
|
||
insert into red_cross values ('axswitkxfjguws', 'Red Cross', '$2a$08$e1vJwED9DFpXzwgd15LxruIvnBluHtu8px17S6ucv2k7NuRW8fHUq', '[email protected]', "DH BKHN"); | ||
insert into donor values ('txstitkxfjguwa', 'Ricardo Milos', '$2a$08$e1vJwED9DFpXzwgd15LxruIvnBluHtu8px17S6ucv2k7NuRW8fHUq', '[email protected]', NULL, NULL, NULL); | ||
insert into organizer values ('bxswitkxfjguwa', 'BK', '$2a$08$e1vJwED9DFpXzwgd15LxruIvnBluHtu8px17S6ucv2k7NuRW8fHUq', '[email protected]', NULL); | ||
insert into hospital values ('gxswitkxfjguwa','axswitkxfjguws', 'Hospital', '$2a$08$e1vJwED9DFpXzwgd15LxruIvnBluHtu8px17S6ucv2k7NuRW8fHUq', '[email protected]', NULL); | ||
DEFAULT CHARACTER SET = utf8; |
Oops, something went wrong.