Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamle2 committed Jun 8, 2020
2 parents 3d6a457 + c06c157 commit 5c3872d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 85 deletions.
64 changes: 8 additions & 56 deletions controllers/redcross/redcrossController.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,29 +307,7 @@ module.exports = {
return res.status(500).json({
err: err,
});
else {
let sql =
"update blood set ? where status = ? and blood_id = ?";
let values = [
{
status: constants.stored,
amount: constants.standard_blood_donation_amount,
},
constants.active,
req.params.id,
];
db.query(sql, values, function (err, resp2) {
if (err)
return res.status(500).json({
err: err,
});
else
return res.status(200).json({
message: "stored blood",
data: resp2,
});
});
}
else return store(req, res);
});
} else {
let sql =
Expand All @@ -344,29 +322,7 @@ module.exports = {
return res.status(500).json({
err: err,
});
else {
let sql =
"update blood set ? where status = ? and blood_id = ?";
let values = [
{
status: constants.stored,
amount: constants.standard_blood_donation_amount,
},
constants.active,
req.params.id,
];
db.query(sql, values, function (err, resp2) {
if (err)
return res.status(500).json({
err: err,
});
else
return res.status(200).json({
message: "stored blood",
data: resp2,
});
});
}
else return store(req, res);
});
}
});
Expand Down Expand Up @@ -727,13 +683,8 @@ module.exports = {
});
} else {
let sql =
"update blood set status = ? where (status = ? or status = ?) and blood_id = ?";
let values = [
constants.rejected,
constants.pending,
constants.active,
req.params.id,
];
"update blood set status = ? where status = ? and blood_id = ?";
let values = [constants.rejected, constants.approved, req.params.id];
db.query(sql, values, function (err, result) {
if (err)
return res.status(500).json({
Expand Down Expand Up @@ -892,11 +843,12 @@ module.exports = {
return res.status(500).json({
err: err,
});
else
else {
return res.status(200).json({
message: "tested blood",
data: result,
message: "tested and stored blood",
data: resp2,
});
}
});
}
});
Expand Down
49 changes: 20 additions & 29 deletions init_db/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ CREATE TABLE hospital (
ENGINE = INNODB
DEFAULT CHARACTER SET = utf8;

CREATE TABLE blood_store (
store_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL,
red_cross_id CHAR(32) NOT NULL,
bloodType VARCHAR(5) NOT NULL,
amount DOUBLE PRECISION NULL,
FOREIGN KEY (red_cross_id) REFERENCES red_cross(red_cross_id)
)
ENGINE = INNODB
DEFAULT CHARACTER SET = utf8;

CREATE TABLE event (
event_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL,
red_cross_id CHAR(32) NULL,
Expand All @@ -70,32 +60,33 @@ CREATE TABLE event (
ENGINE = INNODB
DEFAULT CHARACTER SET = utf8;

CREATE TABLE blood (
blood_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL,
event_id CHAR(32) NOT NULL,
donor_id CHAR(32) NOT NULL,
donate_date INT(11) NOT NULL,
CREATE TABLE blood_order (
order_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL,
hospital_id CHAR(32) NOT NULL,
red_cross_id CHAR(32) NULL,
order_date DATETIME NOT NULL,
amount DOUBLE PRECISION NULL,
blood_type VARCHAR(5) NULL,
status VARCHAR(10) NULL,
event_date INT(11) NOT NULL,
name VARCHAR(99) NOT NULL,
location VARCHAR(99) NOT NULL,
blood_type VARCHAR(5) NULL,

FOREIGN KEY (event_id) REFERENCES event(event_id),
FOREIGN KEY (donor_id) REFERENCES donor(donor_id)
FOREIGN KEY (hospital_id) REFERENCES hospital(hospital_id),
FOREIGN KEY (red_cross_id) REFERENCES red_cross(red_cross_id)
)
ENGINE = INNODB
DEFAULT CHARACTER SET = utf8;

CREATE TABLE blood_order (
order_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL,
hospital_id CHAR(32) NOT NULL,
order_date INT(11) NOT NULL,
CREATE TABLE blood (
blood_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL,
event_id CHAR(32) NOT NULL,
donor_id CHAR(32) NOT NULL,
order_id CHAR(32) NULL,
red_cross_id CHAR(32) NULL,
donate_date INT(11) NOT NULL,
amount DOUBLE PRECISION NULL,
blood_type VARCHAR(5) NULL,
status VARCHAR(10) NULL,
FOREIGN KEY (hospital_id) REFERENCES hospital(hospital_id)
FOREIGN KEY (event_id) REFERENCES event(event_id),
FOREIGN KEY (donor_id) REFERENCES donor(donor_id),
FOREIGN KEY (order_id) REFERENCES blood_order(order_id),
FOREIGN KEY (red_cross_id) REFERENCES red_cross(red_cross_id)
)
ENGINE = INNODB
DEFAULT CHARACTER SET = utf8;
DEFAULT CHARACTER SET = utf8;

0 comments on commit 5c3872d

Please sign in to comment.