51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
/*jshint esversion: 6 */
|
|
const path = require('path');
|
|
const express = require('express');
|
|
const router = express.Router();
|
|
const cameraService = require(path.resolve(__dirname, './camera.service'));
|
|
|
|
router.post('/create', _create);
|
|
router.get('/cameras', getAll);
|
|
router.get('/', getById);
|
|
router.put('/', update);
|
|
router.delete('/', _delete);
|
|
router.post('/osd', _osd);
|
|
|
|
module.exports = router;
|
|
|
|
function _create(req, res, next) {
|
|
cameraService.create(req.body)
|
|
.then((camera) => res.json(camera))
|
|
.catch(err => next(err));
|
|
}
|
|
|
|
function update(req, res, next) {
|
|
cameraService.update(req.body.id)
|
|
.then((camera) => res.json(camera))
|
|
.catch(err => next(err));
|
|
}
|
|
|
|
function getAll(req, res, next) {
|
|
cameraService.getAll()
|
|
.then((cameras) => res.json(cameras))
|
|
.catch(err => next(err));
|
|
}
|
|
|
|
function getById(req, res, next) {
|
|
cameraService.getById(req.body.id)
|
|
.then((camera) => res.json(camera))
|
|
.catch(err => next(err));
|
|
}
|
|
|
|
function _delete(req, res, next) {
|
|
cameraService.delete(req.body.id)
|
|
.then((id) => res.json(id))
|
|
.catch(err => next(err));
|
|
}
|
|
|
|
function _osd(req, res, next) {
|
|
cameraService.osd(req.body)
|
|
.then((socket) => res.json(socket))
|
|
.catch(err => next(err));
|
|
}
|