<commit_before>"use strict";
var express         = require("express"),
    crud            = require("./helpers/crud.js"),
    auth            = require("./helpers/auth.js"),
    list            = require("./helpers/list.js");

var events = module.exports = express.Router({ mergeParams: true });

// Helpers to DRY up CRUD controllers: see helpers/crud.js
// Fields we want to output in JSON responses (in addition to ID)
var keys = module.exports.keys = ["date", "location", "name", "description", "eventLength"];
var filterInput = crud.filterInputGenerator(keys),
    formatObjectCode = crud.formatObjectGenerator(keys),
    formatObject = formatObjectCode(200),
    formatList = crud.formatListGenerator(keys, "events"),
    returnData = crud.returnData,
    returnListData = crud.returnListData;

events.post("/", auth.authorize("write"), filterInput, function (req, res, next) {
    req.patient.createEvent(req.data, returnData(res, next));
}, formatObjectCode(201));


events.get("/:eventid", auth.authorize("read"), function (req, res, next) {
    req.patient.findEventById(req.params.eventid, returnData(res, next));
}, formatObject);

events.delete("/:eventid", auth.authorize("write"), function (req, res, next) {
    req.patient.findEventByIdAndDelete(req.params.eventid, returnData(res, next));
}, formatObject);

events.put("/:eventid", auth.authorize("write"), filterInput, function (req, res, next) {
    req.patient.findEventByIdAndUpdate(req.params.eventid, req.data, returnData(res, next));
}, formatObject);

var paramParser = list.parseListParameters(["id", "name"], ["name", "start_date", "end_date"]);
events.get("/", auth.authorize("read"), paramParser, list.parseDateFilters, function (req, res, next) {
    req.patient.queryEvents(req.listParameters, req.user, req.patient, returnListData(res, next));
}, formatList);<commit_msg>Allow sorting events by date<commit_after>"use strict";
var express         = require("express"),
    crud            = require("./helpers/crud.js"),
    auth            = require("./helpers/auth.js"),
    list            = require("./helpers/list.js");

var events = module.exports = express.Router({ mergeParams: true });

// Helpers to DRY up CRUD controllers: see helpers/crud.js
// Fields we want to output in JSON responses (in addition to ID)
var keys = module.exports.keys = ["date", "location", "name", "description", "eventLength"];
var filterInput = crud.filterInputGenerator(keys),
    formatObjectCode = crud.formatObjectGenerator(keys),
    formatObject = formatObjectCode(200),
    formatList = crud.formatListGenerator(keys, "events"),
    returnData = crud.returnData,
    returnListData = crud.returnListData;

events.post("/", auth.authorize("write"), filterInput, function (req, res, next) {
    req.patient.createEvent(req.data, returnData(res, next));
}, formatObjectCode(201));


events.get("/:eventid", auth.authorize("read"), function (req, res, next) {
    req.patient.findEventById(req.params.eventid, returnData(res, next));
}, formatObject);

events.delete("/:eventid", auth.authorize("write"), function (req, res, next) {
    req.patient.findEventByIdAndDelete(req.params.eventid, returnData(res, next));
}, formatObject);

events.put("/:eventid", auth.authorize("write"), filterInput, function (req, res, next) {
    req.patient.findEventByIdAndUpdate(req.params.eventid, req.data, returnData(res, next));
}, formatObject);

var paramParser = list.parseListParameters(["id", "name", "date"], ["name", "start_date", "end_date"]);
events.get("/", auth.authorize("read"), paramParser, list.parseDateFilters, function (req, res, next) {
    req.patient.queryEvents(req.listParameters, req.user, req.patient, returnListData(res, next));
}, formatList);
{'fraction_non_alphanumeric': 0.1652826145191535, 'fraction_numerical': 0.0032145727297080095, 'mean_word_length': 4.852664576802508, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3679222', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1123, 'n_words': 250}