2019-10-17 16:59:18 +00:00
|
|
|
const routes = require('express').Router();
|
|
|
|
|
|
|
|
|
|
const { isAdministratorUser, isLoggedUser } = require('../../middlewares/accessValidator');
|
|
|
|
|
const SchemaValidator = require('../../middlewares/schemaValidator');
|
|
|
|
|
const PaginateMiddleware = require('../../middlewares/paginate');
|
|
|
|
|
const FieldMiddleware = require('../../middlewares/fields');
|
|
|
|
|
const notificationController = require('./notification.controller');
|
|
|
|
|
const { deviceTokenInputType, notificationSendType } = require('./notification.validations');
|
|
|
|
|
|
|
|
|
|
const generalInvalidFields = [
|
|
|
|
|
'createdAt', 'updatedAt',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
routes.get('/notifications',
|
|
|
|
|
isAdministratorUser,
|
|
|
|
|
FieldMiddleware.middleware({
|
|
|
|
|
invalidFields: generalInvalidFields
|
|
|
|
|
}),
|
|
|
|
|
PaginateMiddleware.middleware(),
|
|
|
|
|
notificationController.find({
|
|
|
|
|
scopes: ['defaultScope']
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
routes.get('/notifications/:id',
|
|
|
|
|
isAdministratorUser,
|
|
|
|
|
FieldMiddleware.middleware({
|
|
|
|
|
invalidFields: generalInvalidFields
|
|
|
|
|
}),
|
|
|
|
|
notificationController.findOne({
|
|
|
|
|
scopes: ['defaultScope']
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
routes.post('/notifications',
|
|
|
|
|
isAdministratorUser,
|
|
|
|
|
SchemaValidator(notificationSendType, true),
|
|
|
|
|
notificationController.sendNotification({
|
|
|
|
|
scopes: ['defaultScope']
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/* Borrar cuando ya no aparezca la versión 1.0.10 */
|
|
|
|
|
routes.post('/notifications/register',
|
|
|
|
|
isLoggedUser,
|
|
|
|
|
SchemaValidator(deviceTokenInputType, true),
|
2019-10-21 10:12:16 +00:00
|
|
|
notificationController.registerDevice()
|
2019-10-17 16:59:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
routes.post('/notifications/devices',
|
|
|
|
|
isLoggedUser,
|
|
|
|
|
SchemaValidator(deviceTokenInputType, true),
|
2019-10-21 10:12:16 +00:00
|
|
|
notificationController.registerDevice()
|
2019-10-17 16:59:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
module.exports = routes;
|