feat: Adding notifications endpoint
This commit is contained in:
@@ -15,6 +15,7 @@ const loads = require('./loads/routes.js');
|
||||
const proposals = require('./proposals/routes.js');
|
||||
const users = require('./users/routes.js');
|
||||
const vehicles = require('./vehicles/routes.js');
|
||||
const notifications = require('./notifications/routes.js');
|
||||
|
||||
router.use( jwtValidator.middleware );
|
||||
router.use( context.middleware );
|
||||
@@ -25,6 +26,7 @@ router.use('/branches', branches);
|
||||
router.use('/companies', companies);
|
||||
router.use('/load-attachments', loadAttachments );
|
||||
router.use('/loads', loads);
|
||||
router.use('/notifications', notifications);
|
||||
router.use('/proposals', proposals);
|
||||
router.use('/users', users);
|
||||
router.use('/vehicles', vehicles);
|
||||
|
||||
9
v1/src/apps/private/notifications/routes.js
Normal file
9
v1/src/apps/private/notifications/routes.js
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
const router = require('express').Router();
|
||||
const services= require('./services.js');
|
||||
|
||||
router.get('/', services.getNotifications );
|
||||
router.delete('/', services.deleteNotifications );
|
||||
router.delete('/:id', services.deleteById );
|
||||
|
||||
module.exports = router;
|
||||
57
v1/src/apps/private/notifications/services.js
Normal file
57
v1/src/apps/private/notifications/services.js
Normal file
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
|
||||
const Notifications = require( '../../../lib/Models/notifications.model' );
|
||||
|
||||
async function getNotifications(req, res, next) {
|
||||
try{
|
||||
const userId = req.context.userId;
|
||||
const list = await Notifications.find( {
|
||||
owner : userId,
|
||||
deleted : false
|
||||
} );
|
||||
return res.send( list );
|
||||
}catch(error){
|
||||
console.error( error );
|
||||
return res.status( 500 ).send({ error });
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteNotifications(req, res, next) {
|
||||
try{
|
||||
const userId = req.context.userId;
|
||||
const { list } = req.query;
|
||||
|
||||
const ret = await Notifications.deleteMany({
|
||||
_id : list,
|
||||
owner: userId
|
||||
});
|
||||
|
||||
return res.send( {
|
||||
msg : "Done"
|
||||
} );
|
||||
}catch(error){
|
||||
console.error( error );
|
||||
return res.status( 500 ).send({ error });
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteById(req, res, next) {
|
||||
try{
|
||||
const userId = req.context.userId;
|
||||
const notificationId = req.params.id;
|
||||
|
||||
const ret = await Notifications.deleteOne( {
|
||||
_id : notificationId,
|
||||
owner: userId
|
||||
} );
|
||||
|
||||
return res.send( {
|
||||
msg : "Done"
|
||||
} );
|
||||
}catch(error){
|
||||
console.error( error );
|
||||
return res.status( 500 ).send({ error });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getNotifications, deleteNotifications, deleteById };
|
||||
@@ -3,7 +3,7 @@
|
||||
const { getModel } = require( '../../../lib/Models' );
|
||||
const { getPagination } = require( '../../../lib/Misc' );
|
||||
const { GenericHandler } = require( '../../../lib/Handlers/Generic.handler' );
|
||||
const { onPatchEvent } = require('../../../lib/Handlers/Proposals.handler');
|
||||
const { onPostEvent, onPatchEvent } = require('../../../lib/Handlers/Proposals.handler');
|
||||
const Model = getModel('proposals');
|
||||
|
||||
const populate_list = [
|
||||
@@ -118,6 +118,8 @@ const postProposal = async(req, res) => {
|
||||
}
|
||||
const proposal = new Model( data );
|
||||
await proposal.save();
|
||||
|
||||
await onPostEvent(proposal.id, data);
|
||||
return res.send( proposal );
|
||||
}catch(error){
|
||||
console.error( error );
|
||||
|
||||
Reference in New Issue
Block a user