diff --git a/models/Notifications.js b/models/Notifications.js index 03dea3c..6053424 100644 --- a/models/Notifications.js +++ b/models/Notifications.js @@ -27,7 +27,28 @@ Notifications.get = (alias, tribeId) => { data: { notif: [{ tribeId, msg }] }, }; }; +/** + * Get statistic of registering email phone + */ +Notifications.statmaillist=(tribe)=>{ + const statinfo={} + const src=`../../${tribe}/objects/maillinglists/*.json` + console.log(path.resolve(src)) + glob.sync(src).forEach(f=>{ + const name=path.basename(f,".json"); + const mlst=fs.readJSONSync(f) + Object.keys(mlst).forEach(c=>{ + mlst[c].srckeys.forEach(s=>{ + if (!statinfo[s]) statinfo[s]={} + if (!statinfo[s][name]) statinfo[s][name]=0 + statinfo[s][name]++ + }) + //console.log(c) recupere les contact tel ou email + }) + }) + return {status:200,ref:"Notifications",msg:"statistics",data:statinfo} +} /** * Register an typekey(email) or (phone) key into mailinglist for a tribe diff --git a/routes/notifications.js b/routes/notifications.js index 5059b7f..6b7172b 100644 --- a/routes/notifications.js +++ b/routes/notifications.js @@ -106,6 +106,47 @@ router.get("/unregister/:tribe/:mlist/:typekey/:srckey/:data/:validation", check res.status(result.status).json(result) }) +/** + * @api {GET} adminapi/notifications/stat/maillinglst/:tribe --Statistic maillinglst + * @apiName statmaillinglst + * @apiGroup Notifications + * @apiDescription Mailling list statistique + * @apiParams {string} tribe an existing tribe + * + * @apiSuccess {object} with data results + * @apiSuccessExample {json} successfullmessage + * HTTP/1.1 200 OK + * { + * "status": 200, + * "ref": "Notifications", + * "msg": "statistics", + * "data": { + * "teasingwebpage": { + * "email_stayinformboth": 1, + * "email_stayinformseeker": 6 + * }, + * "gorillamkt": { + * "email_trouvemonjobrecruiter": 7, + * "email_trouvemonjobseeker": 142, + * "telephonefr_trouvemonjobrecruiter": 4, + * "telephonefr_trouvemonjobseeker": 103 + * }, + * "forumantony": { + * "email_trouvemonjobseeker": 18, + * "telephonefr_trouvemonjobseeker": 151 + * } + * } + *} + * + */ +router.get("/stat/maillinglst/:tribe", checkHeaders, async (req, res) => { + console.log('passe là'); + const resstat=Notifications.statmaillist(req.params.tribe) + res.status(resstat.status).json(resstat); +}); + + + /** * @api {POST} adminapi/notifications/contactanonymous/:tribe -Contact anonymous * @apiName contactanonymous