1
0
forked from apxtri/apxtri
apxtri/routes/notifications.js

109 lines
3.8 KiB
JavaScript
Raw Normal View History

2023-12-07 12:04:19 +01:00
const express = require("express");
// Classes
const Notifications = require("../models/Notifications.js");
// Middlewares
const checkHeaders = require("../middlewares/checkHeaders");
const isAuthenticated = require("../middlewares/isAuthenticated");
const router = express.Router();
2023-12-29 13:38:47 +01:00
/**
* wait Sagar feedback for language and label description
* @ api {post} /api/notifications/backend - Notification Backend post
* @apiName notifBackend
* @apiDescription Send an api result {status,ref,msg,data} to get personnalize notification by header.xlang abd by data
* @apiGroup Notification
*
* @apiBody {integer} status an http status
* @apiBody {string} ref an existing model name
* @apiBody {string} msg a key word existing in referentiual
* */
router.post("/backend", (req, res) => {
})
2023-12-07 12:04:19 +01:00
/**
* @api {get} /notifications/:alias/:tribeId
* @apiName notiflist
* @apiDescription Get list of notifications for an alias and a tribe
2023-12-29 13:38:47 +01:00
* @apiGroup Notifications
2023-12-07 12:04:19 +01:00
*
* @apiParam {string} alias
* @apiParam {string} tribeId
* @apiSuccess {object} notif content
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {status:200,ref:"Notification",msg:"Messagelist",data:{notif:[{tribeId,msg:{from(email or uuid or alias):[{dt,msg}]}}]}
2023-12-29 13:38:47 +01:00
* bouture
2023-12-07 12:04:19 +01:00
**/
router.get("/:alias/:tribeId", (req, res) => {
2023-12-29 13:38:47 +01:00
const getnot = Notification.get(req.params.alias, req.params.tribeId);
2023-12-07 12:04:19 +01:00
res.status(getalias.status).send(getalias);
});
2023-12-29 13:38:47 +01:00
router.post("/registeranonymous", checkHeaders, (req, res) => {
['uuid','srckey','mlist'].forEach(k=>{
if (!req.body[k]){}
});
res.status().json({status:410, ref:"", msg:""})
let result;
if (req.body.email) {
result= Notifications.registertolist(
req.body.email,
"email",
req.session.header.xtribe,
req.body.mlist,
req.body.srckey,
req.body.uuid);
}
res(200).json({status:200})
})
/**
* @api {POST} /actions/contactanonymous -Contact anonymous
* @apiName contactanonymous
* @apiGroup Notifications
* @apiDescription Run action store in body.order and update mailinglist or create contact message
*
* @apiBody {string} order name of function for action in Actions.js example:registercontact ,
* @apiBody {string} srckey: where it come from and eventualy email template name to use to send email ,
* @apiBody {string} email to use
* @apiBody {string} route /actions/contactanonymous
* @apiBody {string} [mlist] filename to store email registration /contacts/mlist.json if not => filename is quest_/contacts/email.json with {email:{dt_create,dt_update, src:[list of source]}} or add message in /contacts/quest_{email}.json {timestamp:{message,name,email,dt_create,emailcontact}}
* @apiBody {string} others any other usefull key:value relevant for order action
*
* @apiSuccess {object} update/contacts/{mlist}.json successfull
* @apiSuccessExample {json} successfullmessage
* HTTP/1.1 200 OK
* {"status":200, "ref":"Contact", "msg":"success", "data":{"indexlist":[]}}
*
*/
router.post("/contactanonymous", checkHeaders, async (req, res) => {
const done = Actions[req.body.order]
? await Actions[req.body.order](req.body, req.session.header)
: { status: 406, ref: "Actions", msg: "bodyerror", data: req.body };
//console.log('routes contactanonymous ', req.body);
res.status(done.status).json(done);
});
/**
* Same as /copntactanonymous but for authenticated user => data are updated in persons/itm/alias.json
*/
router.post("/contact", checkHeaders, isAuthenticated, (req, res) => {
const done = Actions[req.body.order]
? Actions[req.body.order](req.body, req.session.header)
: { status: 406, ref: "Actions", msg: "bodyerror", data: req.body };
console.log(req.body);
res.status(done.status).json(done);
});
router.get("/contact", checkHeaders, isAuthenticated, (req, res) => {
res.status(200).json({ data: {} });
});
module.exports = router;