Skip to content

Commit

Permalink
remove socket and add pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamle2 committed Jun 3, 2020
1 parent bc2c32e commit 382f987
Show file tree
Hide file tree
Showing 10 changed files with 486 additions and 661 deletions.
30 changes: 18 additions & 12 deletions controllers/blood_event/eventController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ const eventId = require("../../utils/utils").generateId
const utils = require("../../utils/utils")
const constants = require("../../utils/constants")
const { validationResult } = require("express-validator/check");
const io = require('../socket/socket.js').getIo();
const notificationController = require("../notification/notificationController")

module.exports = {
createEvent: (req, res) => {
Expand Down Expand Up @@ -67,13 +65,6 @@ module.exports = {
error: "Error querying: " + err,
});
} else {
let result = notificationController.createNotification(constants.role.organizer, req.userData.id, req.body.noti_content)
if (result) {
console.log("INSERT NEW NOTIFICATION IN CREATING EVENT SUCCESSFULLY")
io.emit("create_event", "new event created")
}
else
console.log("INSERT NOTIFICATION IN CREATING EVENT FAILED")
return res.status(200).json({
message: "Your event has been created successfully",
event_id: event_id
Expand Down Expand Up @@ -227,9 +218,25 @@ module.exports = {
},
// needs to use limit and offset (pagnitation here)
getAllEvents: (req, res) => {
db.query("select * from event", function (err, result) {
let offset = null
let limit = null
console.log("REQ ")
if (req.query.offset === '' && req.query.limit === '') {
offset = 0
limit = 3
} else {
offset = parseInt(req.query.offset)
limit = parseInt(req.query.limit)
}
console.log("OFFSET IN GET ALL EVENTS: ", offset)
let query = "select * from event LIMIT ?, ?"
console.log("QUERY GET ALL EVENTS: ", query)
db.query(query, [offset, limit], function (err, result) {
if (err) {
return res.status(500).json({ error: "there is something wrong with the database" })
console.log("ERROR ????????????????????????????", err)
return res.status(500).json({
error: err
})
} else {
return res.status(200).json({ message: "success", data: result })
}
Expand All @@ -241,7 +248,6 @@ module.exports = {
console.log("ERROR: ", err)
return res.status(500).json({ error: "there is something wrong with the database" })
} else {
//io.to("ABCD").emit("test", "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG")
if (result[0].red_cross_name === null)
result[0].red_cross_name = "None"
return res.status(200).json({ message: "success", data: result[0] })
Expand Down
3 changes: 1 addition & 2 deletions controllers/blood_event/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const router = express.Router();
router.post("/create_event", authMiddleware, [
check("name").isLength({ min: 3, max: 99 }),
check("date").isInt(),
check("location").isLength({ min: 3, max: 99 }),
check("noti_content").isLength({ min: 3, max: 99 })
check("location").isLength({ min: 3, max: 99 })
],
controller.createEvent);

Expand Down
11 changes: 0 additions & 11 deletions controllers/notification/index.js

This file was deleted.

61 changes: 0 additions & 61 deletions controllers/notification/notificationController.js

This file was deleted.

16 changes: 0 additions & 16 deletions controllers/socket/socket.js

This file was deleted.

16 changes: 0 additions & 16 deletions init_db/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,6 @@ CREATE TABLE blood_store (
ENGINE = INNODB
DEFAULT CHARACTER SET = utf8;

CREATE TABLE notification (
notification_id CHAR(32) PRIMARY KEY UNIQUE NOT NULL,
red_cross_id CHAR(32) NULL,
organizer_id CHAR(32) NULL,
hospital_id CHAR(32) NULL,
donor_id CHAR(32) NULL,
noti_date INT(11) NULL,
content VARCHAR(99) NULL,
FOREIGN KEY (red_cross_id) REFERENCES red_cross(red_cross_id),
FOREIGN KEY (organizer_id) REFERENCES organizer(organizer_id),
FOREIGN KEY (hospital_id) REFERENCES hospital(hospital_id),
FOREIGN KEY (donor_id) REFERENCES donor(donor_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 Down
Loading

0 comments on commit 382f987

Please sign in to comment.