import Holiday from '../models/holiday.model';

function load(req, res, next, id) {
    Holiday.get(id)
        .then((holiday) => {
            req.holiday = holiday;
            next();
            return null;
        })
        .catch(e => next(e));
}

function get(req, res) {
    return res.json(req.holiday);
}

function create(req, res, next) {
    const holiday = new Holiday({
        name: req.body.name,
        description: req.body.description,
        date: req.body.date,
    });

    holiday.save()
        .then(savedHoliday => res.json(savedHoliday))
        .catch(e => next(e));
}

function update(req, res, next) {
    const holiday = req.holiday;
    holiday.name = req.body.name;
    holiday.description = req.body.description;
    holiday.date = req.body.date;


    holiday.save()
        .then(savedHoliday => res.json(savedHoliday))
        .catch(e => next(e));
}

function list(req, res, next) {
    const { limit = 50, skip = 0 } = req.query;
    Holiday.list({ limit, skip })
        .then(holidays => res.json(holidays))
        .catch(e => next(e));
}

function remove(req, res, next) {
    const holiday = req.holiday;
    holiday.remove()
        .then(deletedHoliday => res.json(deletedHoliday))
        .catch(e => next(e));
}


export default { load, get, create, update, list, remove };

@@ -39,16 +39,59 @@
 .model';
+%0Aimport Audit from '../models/audit.model';
 %0A%0Afuncti
@@ -558,32 +558,38 @@
 )%0A        .then(
+async 
 savedHoliday =%3E 
@@ -579,32 +579,292 @@
  savedHoliday =%3E
+ %7B%0A            const audit = new Audit(%7B%0A                author: req.token.id,%0A                details: %60Created Holiday: $%7BsavedHoliday.name%7D%7C$%7BsavedHoliday.description%7D($%7BsavedHoliday.date%7D)%60%0A            %7D);%0A            await audit.save();%0A            return
  res.json(savedH
@@ -862,32 +862,43 @@
 on(savedHoliday)
+;%0A        %7D
 )%0A        .catch
@@ -1134,16 +1134,22 @@
   .then(
+async 
 savedHol
@@ -1147,32 +1147,395 @@
  savedHoliday =%3E
+ %7B%0A            const audit = new Audit(%7B%0A                author: req.token.id,%0A                details: %60Updated Holiday:%0A                    $%7Breq.body.name%7D%7C$%7Breq.body.description%7D%7C$%7Breq.body.date%7D with%0A                    $%7BsavedHoliday.name%7D%7C$%7BsavedHoliday.description%7D($%7BsavedHoliday.date%7D)%60%0A            %7D);%0A            await audit.save();%0A            return
  res.json(savedH
@@ -1533,32 +1533,43 @@
 on(savedHoliday)
+;%0A        %7D
 )%0A        .catch
@@ -1882,16 +1882,22 @@
   .then(
+async 
 deletedH
@@ -1905,16 +1905,302 @@
 liday =%3E
+ %7B%0A            const audit = new Audit(%7B%0A                author: req.token.id,%0A                details: %60Deleted Holiday:%0A                    $%7BdeletedHoliday.name%7D%7C$%7BdeletedHoliday.description%7D($%7BdeletedHoliday.date%7D)%60%0A            %7D);%0A            await audit.save();%0A            return
  res.jso
@@ -2216,16 +2216,27 @@
 Holiday)
+;%0A        %7D
 )%0A      
@@ -2262,17 +2262,16 @@
 e));%0A%7D%0A%0A
-%0A
 export d

add audit logs for legal holidays create/update/delete