Skip to content

Commit

Permalink
feat: added holiday addition, deletion and get api
Browse files Browse the repository at this point in the history
  • Loading branch information
varijkapil13 committed Jan 16, 2019
1 parent d3293d6 commit 0bc7036
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
60 changes: 60 additions & 0 deletions server/controllers/holiday.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import model from '../models';

const {Holiday} = model;

class HolidayController {
static addHoliday(req, res) {
const {date, notes, from, to} = req.body;

return Holiday.create({
date,
notes,
from,
to
})
.then(holidayData =>
res.status(201).send({
success: true,
message: 'Holiday was successfully added',
holidayData
})
)
.catch(error => res.status(400).send(error));
}

static deleteHoliday(req, res) {
const holidayId = req.params.holidayId;

Holiday.findById(holidayId).then(holiday => {
if (!holiday) {
return res.status(400).send({
message: 'Avatar Not Found'
});
} else {
holiday
.destroy()
.then(() =>
res.status(200).send({
message: 'Avatar successfully deleted'
})
)
.catch(error => res.status(400).send(error));
}
});
}

static getAllHolidays(req, res) {
Holiday.findAll().then(holidays => {
return res
.status(200)
.send({
status: true,
message: 'Found holidays',
holidays
})
.catch(error => res.status(400).send(error));
});
}
}

export default HolidayController;
Empty file added server/controllers/leave.js
Empty file.
7 changes: 6 additions & 1 deletion server/routes/holiday.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import express from 'express';
import HolidayController from '../controllers/holiday';

const routes = express.Router();

export default routes;
routes.post('/', HolidayController.addHoliday);
routes.delete('/', HolidayController.deleteHoliday);
routes.get('/', HolidayController.getAllHolidays);

export default routes;

0 comments on commit 0bc7036

Please sign in to comment.