Skip to content

Commit

Permalink
solve conflict from master
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamle2 committed Jun 1, 2020
2 parents a144ca6 + 057bd5d commit ba6cf59
Show file tree
Hide file tree
Showing 9 changed files with 888 additions and 360 deletions.
476 changes: 245 additions & 231 deletions controllers/auth/authController.js

Large diffs are not rendered by default.

181 changes: 114 additions & 67 deletions controllers/blood_form/bloodFormController.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,129 @@
const db = require("../../database/index");
const generateId = require("../../utils/utils").generateId;
const constants = require("../../utils/constants");
const {validationResult} = require("express-validator/check");
const { validationResult } = require("express-validator/check");

module.exports = {
getBloodForm: (req, res) => {
//CHECK ERROR INPUT
let errors = validationResult(req);
if (!errors.isEmpty()) return res.status(422).json({errors: errors.array()});
getBloodForm: (req, res) => {
//CHECK ERROR INPUT
let errors = validationResult(req);
if (!errors.isEmpty())
return res.status(422).json({ errors: errors.array() });

//CHECK USER DATA
console.log("bloodFormController | getBloodForm | req user data: ", req.userData);
if (req.userData.role !== constants.role.donor) return res.status(403).json({error: "Forbidden !! You are not allowed to call this function"});
//CHECK USER DATA
console.log(
"bloodFormController | getBloodForm | req user data: ",
req.userData
);
if (req.userData.role !== constants.role.donor)
return res
.status(403)
.json({
error: "Forbidden !! You are not allowed to call this function",
});

//EVERYTHING IS OK
db.query("select * from blood where donor_id = ?", [req.userData.id], function (err, result) {
//CHECK SQL ERROR
if (err) return res.status(500).json({error: err})
//EVERYTHING IS OK
db.query(
"select * from blood where donor_id = ?",
[req.userData.id],
function (err, result) {
//CHECK SQL ERROR
if (err) return res.status(500).json({ error: err });

//RETURN DATA
return res.status(200).json({message: "success", data: result})
})
//RETURN DATA
return res.status(200).json({ message: "success", data: result });
}
);
},
postBloodForm: (req, res) => {
//CHECK ERROR INPUT
let errors = validationResult(req);
if (!errors.isEmpty())
return res.status(422).json({ errors: errors.array() });

},
postBloodForm: (req, res) => {
//CHECK ERROR INPUT
let errors = validationResult(req);
if (!errors.isEmpty()) return res.status(422).json({errors: errors.array()});
//CHECK USER DATA
console.log(
"bloodFormController | postBloodForm | req user data: ",
req.userData
);
if (req.userData.role !== constants.role.donor)
return res
.status(403)
.json({
error: "Forbidden !! You are not allowed to call this function",
});

//CHECK USER DATA
console.log("bloodFormController | postBloodForm | req user data: ", req.userData);
if (req.userData.role !== constants.role.donor) return res.status(403).json({error: "Forbidden !! You are not allowed to call this function"});
//CHECK IF EVENT EXISTS
db.query(
"select * from event where event_id = ?",
[[req.body.event_id]],
function (err, result) {
console.log(
"bloodFormController | postBloodForm | result query event: " +
JSON.stringify(result)
);
//CHECK SQL ERROR
if (err) return res.status(500).json({ error: err });
if (result.length === 0)
return res.status(423).json({ error: "event does not exists" });

//CHECK IF EVENT EXISTS
db.query("select * from event where event_id = ?", [[req.body.event_id]], function (err, result) {
console.log("bloodFormController | postBloodForm | result query event: " + JSON.stringify(result));
//SAVE EVENT_ID
req.event_id = result[0].event_id;
req.name = result[0].name;
req.event_date = result[0].event_date;
req.location = result[0].location;

//CHECK IF ALREADY INSERTED REQUEST
db.query(
"select event_id from blood where event_id = ? && donor_id = ?",
[[req.body.event_id], [req.userData.id]],
function (err, result) {
//CHECK SQL ERROR
if (err) return res.status(500).json({error: err});
if (result.length === 0) return res.status(423).json({error: "event does not exists"});
if (err) return res.status(500).json({ error: err });
if (result.length !== 0)
return res
.status(424)
.json({ error: "request for this event already exist" });

//SAVE EVENT_ID
req.event_id = result[0].event_id;
req.name = result[0].name;
req.event_date = result[0].event_date;
req.location = result[0].location;
//EVERYTHING IS OK, START INSERT DATA: CREATE DATA TO INSERT
let blood_id = generateId();
let event_id = req.event_id;
let donor_id = req.userData.id;
let donate_date = Date.now() / 1000;
let amount = constants.standard_blood_donation_amount;
let status = constants.approved;
let event_date = req.event_date;
let name = req.name;
let location = req.location;
let values = [
blood_id,
event_id,
donor_id,
donate_date,
amount,
status,
event_date,
name,
location,
];

//CHECK IF ALREADY INSERTED REQUEST
db.query("select event_id from blood where event_id = ? && donor_id = ?", [[req.body.event_id], [req.userData.id]], function (err, result) {
//RUN SQL TO STORE BLOOD DONATION FORM INTO THE DATABASE
db.query(
"insert into blood(blood_id,event_id,donor_id,donate_date,amount,status,event_date,name,location) values ?",
[[values]],
function (err, result) {
//CHECK SQL ERROR
if (err) return res.status(500).json({error: err});
if (result.length !== 0) return res.status(424).json({error: "request for this event already exist"});

//EVERYTHING IS OK, START INSERT DATA: CREATE DATA TO INSERT
let blood_id = generateId();
let event_id = req.event_id;
let donor_id = req.userData.id;
let donate_date = Date.now() / 1000;
let amount = constants.standard_blood_donation_amount;
let status = constants.approved;
let event_date = req.event_date;
let name = req.name;
let location = req.location;
let values = [blood_id, event_id, donor_id, donate_date, amount, status, event_date, name, location];

//RUN SQL TO STORE BLOOD DONATION FORM INTO THE DATABASE
db.query("insert into blood values ?", [[values]], function (err, result) {
//CHECK SQL ERROR
if (err) return res.status(500).json({error: err});
return res.status(200).json(
{
message: "success",
event_id: event_id,
blood_id: blood_id
});
})
});
});


}
};
if (err) return res.status(500).json({ error: err });
return res.status(200).json({
message: "success",
event_id: event_id,
blood_id: blood_id,
});
}
);
}
);
}
);
},
};
46 changes: 43 additions & 3 deletions controllers/redcross/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,25 @@ const { check } = require("express-validator/check");

const router = express.Router();

router.get("/getpendingEvents", authMiddleware, controller.getpendingEvents);
router.get("/getpendingOrders", controller.getpendingOrders);

router.put(
"/acceptedorder/:id",
check("id").isLength({ min: 32, max: 32 }),
authMiddleware,
controller.acceptOrders
);

router.put(
"/rejectorder/:id",
check("id").isLength({ min: 32, max: 32 }),
authMiddleware,
controller.rejectOrders
);
router.get("/getpendingEvents", authMiddleware, controller.getpendingEvents);
router.get("/getDonors", authMiddleware, controller.getDonors);
router.get("/getHospitals", authMiddleware, controller.getHospitals);
router.get("/getOrganizers", authMiddleware, controller.getOrganizers);
router.put(
"/acceptedevent/:id",
check("id").isLength({ min: 32, max: 32 }),
Expand All @@ -21,14 +38,37 @@ router.put(
authMiddleware,
controller.rejectEvents
);

router.put(
"/rejectdonation/:id",
check("id").isLength({ min: 32, max: 32 }),
authMiddleware,
controller.rejectDonation
);
router.get("/getstore", authMiddleware, controller.getStore);
router.get("/getbloodDonation", authMiddleware, controller.getbloodDonation);
router.get("/get_approved_events", controller.getAllApprovedEvents);
router.get(
"/getUntestedBloodDonation",
authMiddleware,
controller.getUntestedBloodDonation
);
router.post(
"/store/:id",
authMiddleware,
check("id").isLength({ min: 32, max: 32 }),
controller.store
);

router.post(
"/reactivate/:id",
authMiddleware,
check("id").isLength({ min: 32, max: 32 }),
controller.reactivateAccount
);
router.post(
"/banned/:id",
authMiddleware,
check("id").isLength({ min: 32, max: 32 }),
controller.bannedAccount
);
router.post("/testBlood/:id", authMiddleware, controller.testBlood);
module.exports = router;
Loading

0 comments on commit ba6cf59

Please sign in to comment.