diff --git a/.DS_Store b/.DS_Store index 594edc0..25d4466 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/app/.DS_Store b/app/.DS_Store index 5f4bb07..3d1c5b3 100644 Binary files a/app/.DS_Store and b/app/.DS_Store differ diff --git a/app/controllers/calendar-event-recur.controller.js b/app/controllers/calendar-event-recur.controller.js new file mode 100644 index 0000000..0632c8f --- /dev/null +++ b/app/controllers/calendar-event-recur.controller.js @@ -0,0 +1,137 @@ +const { splitSite } = require("../middlewares"); +const db = require("../models"); +const CalendarEventRecur = db.calendar_event_recur; + +// Create a new Recurring Event Rule +exports.create = (req, res) => { + if (!req.body.rrule || !req.body.start_repeat_date) { + res.status(400).send({ message: "rrule and start_repeat_date are required!" }); + return; + } + const site = splitSite.findSiteNumber(req); + const recur = new CalendarEventRecur({ + title: req.body.title, + type: req.body.type, + description: req.body.description, + color: req.body.color, + status: req.body.status || 'active', + target_type: req.body.target_type, + target_uuid: req.body.target_uuid, + target_name: req.body.target_name, + event_location: req.body.event_location, + event_reminder_type: req.body.event_reminder_type, + meal_type: req.body.meal_type, + activity_category: req.body.activity_category, + ingredients: req.body.ingredients, + rrule: req.body.rrule, + start_repeat_date: req.body.start_repeat_date, + end_repeat_date: req.body.end_repeat_date, + indefinite_repeat: req.body.indefinite_repeat || false, + create_by: req.body.create_by, + create_date: req.body.create_date, + edit_by: req.body.edit_by, + edit_date: req.body.edit_date, + edit_history: req.body.edit_history, + site + }); + recur + .save(recur) + .then(data => { + res.send(data); + }) + .catch(err => { + res.status(500).send({ + message: err.message || "Some error occurred while creating the Recurring Event Rule." + }); + }); +}; + +// Get all active recurring event rules +exports.getAll = (req, res) => { + var condition = { status: 'active' }; + condition = splitSite.splitSiteGet(req, condition); + CalendarEventRecur.find(condition) + .then(data => { + res.send(data); + }) + .catch(err => { + res.status(500).send({ + message: err.message || "Some error occurred while retrieving Recurring Event Rules." + }); + }); +}; + +// Get one by ID +exports.getOne = (req, res) => { + const id = req.params.id; + CalendarEventRecur.findById(id) + .then(data => { + if (!data) + res.status(404).send({ message: "Not found Recurring Event Rule with id " + id }); + else res.send(data); + }) + .catch(err => { + res.status(500).send({ message: "Error retrieving Recurring Event Rule with id=" + id }); + }); +}; + +// Update by ID +exports.update = (req, res) => { + if (!req.body) { + return res.status(400).send({ message: "Data to update can not be empty!" }); + } + const id = req.params.id; + CalendarEventRecur.findByIdAndUpdate(id, req.body, { useFindAndModify: false }) + .then(data => { + if (!data) { + res.status(404).send({ + message: `Cannot update Recurring Event Rule with id=${id}. Maybe it was not found!` + }); + } else res.send({ success: true, message: "Recurring Event Rule was updated successfully." }); + }) + .catch(err => { + res.status(500).send({ + success: false, + message: "Error updating Recurring Event Rule with id=" + id + }); + }); +}; + +// Disable (set status to inactive) +exports.disable = (req, res) => { + const id = req.params.id; + CalendarEventRecur.findByIdAndUpdate(id, { ...req.body, status: 'inactive' }, { useFindAndModify: false }) + .then(data => { + if (!data) { + res.status(404).send({ + message: `Cannot disable Recurring Event Rule with id=${id}. Maybe it was not found!` + }); + } else res.send({ success: true, message: "Recurring Event Rule was disabled successfully." }); + }) + .catch(err => { + res.status(500).send({ + success: false, + message: "Error disabling Recurring Event Rule with id=" + id + }); + }); +}; + +// Delete by ID +exports.delete = (req, res) => { + const id = req.params.id; + CalendarEventRecur.findByIdAndRemove(id) + .then(data => { + if (!data) { + res.status(404).send({ + message: `Cannot delete Recurring Event Rule with id=${id}. Maybe it was not found!` + }); + } else { + res.send({ message: "Recurring Event Rule was deleted successfully!" }); + } + }) + .catch(err => { + res.status(500).send({ + message: "Could not delete Recurring Event Rule with id=" + id + }); + }); +}; diff --git a/app/models/calendar-event-recur.model.js b/app/models/calendar-event-recur.model.js new file mode 100644 index 0000000..9ec7d53 --- /dev/null +++ b/app/models/calendar-event-recur.model.js @@ -0,0 +1,48 @@ +module.exports = mongoose => { + var editHistorySchema = mongoose.Schema({ + employee: String, + date: Date + }); + var schema = mongoose.Schema( + { + // Event template data + title: String, + type: String, + description: String, + color: String, + status: String, + // value could be ['active', 'inactive'] + target_type: String, + target_uuid: String, + target_name: String, + event_location: String, + event_reminder_type: String, + meal_type: String, + activity_category: String, + ingredients: String, + // Recurrence fields + rrule: String, + // rrule could be 'FREQ=DAILY', 'FREQ=WEEKLY', 'FREQ=MONTHLY', 'FREQ=YEARLY' + start_repeat_date: Date, + end_repeat_date: Date, + indefinite_repeat: Boolean, + // Metadata + create_by: String, + create_date: Date, + edit_by: String, + edit_date: Date, + edit_history: [{ + type: editHistorySchema + }], + site: Number + }, + { collection: 'calendar_event_recur', timestamps: true } + ); + schema.method("toJSON", function() { + const { __v, _id, ...object } = this.toObject(); + object.id = _id; + return object; + }); + const CalendarEventRecur = mongoose.model("calendar_event_recur", schema); + return CalendarEventRecur; +}; diff --git a/app/models/index.js b/app/models/index.js index 4124096..7485788 100644 --- a/app/models/index.js +++ b/app/models/index.js @@ -19,6 +19,7 @@ db.center_phone = require("./center-phone.model")(mongoose); db.message_token = require("./message-token.model")(mongoose); db.sent_message = require("./sent-message.model")(mongoose); db.calendar_event = require("./calendar-event.model")(mongoose); +db.calendar_event_recur = require("./calendar-event-recur.model")(mongoose); db.doctemplate = require("./doctemplate.model")(mongoose); db.exceltemplate = require("./xlsxtemplate.model")(mongoose); db.timedata = require("./timedata.model")(mongoose); diff --git a/app/routes/calendar-event-recur.route.js b/app/routes/calendar-event-recur.route.js new file mode 100644 index 0000000..4e7f382 --- /dev/null +++ b/app/routes/calendar-event-recur.route.js @@ -0,0 +1,19 @@ +const { authJwt } = require("../middlewares"); +module.exports = app => { + const controller = require("../controllers/calendar-event-recur.controller.js"); + app.use((req, res, next) => { + res.header( + "Access-Control-Allow-Headers", + "x-access-token, Origin, Content-Type, Accept" + ); + next(); + }); + var router = require("express").Router(); + router.get("/", [authJwt.verifyToken], controller.getAll); + router.post("/", [authJwt.verifyToken], controller.create); + router.get("/:id", [authJwt.verifyToken], controller.getOne); + router.put("/:id", [authJwt.verifyToken], controller.update); + router.put("/:id/disable", [authJwt.verifyToken], controller.disable); + router.delete("/:id", [authJwt.verifyToken], controller.delete); + app.use('/api/event-recurrences', router); +}; diff --git a/app/views/asset-manifest.json b/app/views/asset-manifest.json index 32053ce..7ed4912 100644 --- a/app/views/asset-manifest.json +++ b/app/views/asset-manifest.json @@ -1,16 +1,16 @@ { "files": { "main.css": "/static/css/main.57cff37a.css", - "main.js": "/static/js/main.e64707d9.js", + "main.js": "/static/js/main.1a821513.js", "static/js/787.c4e7f8f9.chunk.js": "/static/js/787.c4e7f8f9.chunk.js", "static/media/landing.png": "/static/media/landing.d4c6072db7a67dff6a78.png", "index.html": "/index.html", "main.57cff37a.css.map": "/static/css/main.57cff37a.css.map", - "main.e64707d9.js.map": "/static/js/main.e64707d9.js.map", + "main.1a821513.js.map": "/static/js/main.1a821513.js.map", "787.c4e7f8f9.chunk.js.map": "/static/js/787.c4e7f8f9.chunk.js.map" }, "entrypoints": [ "static/css/main.57cff37a.css", - "static/js/main.e64707d9.js" + "static/js/main.1a821513.js" ] } \ No newline at end of file diff --git a/app/views/index.html b/app/views/index.html index db05b6d..48c109f 100644 --- a/app/views/index.html +++ b/app/views/index.html @@ -1 +1 @@ -
| ".concat(e.label," | ")})).join(""),"\n
|---|
| ".concat(t[e.key]||""," | ")})).join(""),"\n