modif for docapi
This commit is contained in:
@@ -30,47 +30,59 @@ Notifications.get = (alias, tribeId) => {
|
||||
/**
|
||||
* Get statistic of registering email phone
|
||||
*/
|
||||
Notifications.statmaillist=(tribe)=>{
|
||||
const statinfo={}
|
||||
let csv="email/phone;name;srckey\n"
|
||||
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=>{
|
||||
csv+=`"${c}";"${name}";"${mlst[c].srckeys.join('-')}"\n`
|
||||
mlst[c].srckeys.forEach(s=>{
|
||||
if (!statinfo[s]) statinfo[s]={}
|
||||
if (!statinfo[s][name]) statinfo[s][name]=0
|
||||
statinfo[s][name]++
|
||||
})
|
||||
})
|
||||
})
|
||||
Notifications.statmaillist = (tribe) => {
|
||||
const statinfo = {};
|
||||
let csv = "email/phone;name;srckey\n";
|
||||
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) => {
|
||||
csv += `"${c}";"${name}";"${mlst[c].srckeys.join("-")}"\n`;
|
||||
mlst[c].srckeys.forEach((s) => {
|
||||
if (!statinfo[s]) statinfo[s] = {};
|
||||
if (!statinfo[s][name]) statinfo[s][name] = 0;
|
||||
statinfo[s][name]++;
|
||||
});
|
||||
});
|
||||
});
|
||||
// fichier csv stocker en local en attendant d'avoir un back pour stocker la reponse dans data.csv
|
||||
fs.outputFileSync(`../../${tribe}/mailinglst.csv`,csv,"utf-8");
|
||||
return {status:200,ref:"Notifications",msg:"statistics",data:statinfo}
|
||||
}
|
||||
fs.outputFileSync(`../../${tribe}/mailinglst.csv`, csv, "utf-8");
|
||||
return {
|
||||
status: 200,
|
||||
ref: "Notifications",
|
||||
msg: "statistics",
|
||||
data: statinfo,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Register an typekey(email) or (phone) key into mailinglist for a tribe
|
||||
*
|
||||
*
|
||||
*/
|
||||
Notifications.registertolist = (key, typekey, tribe, mlist, srckey, uuid) => {
|
||||
key = key.toLowerCase();
|
||||
typekey= (typekey=="telephone")? "telephonefr":typekey;
|
||||
typekey = typekey == "telephone" ? "telephonefr" : typekey;
|
||||
if (!Checkjson.testformat(key, typekey))
|
||||
return {
|
||||
status: 400,
|
||||
ref: "Notifications",
|
||||
msg: "formaterror",
|
||||
data: { fielderr: typekey, format: typekey }
|
||||
data: { fielderr: typekey, format: typekey },
|
||||
};
|
||||
|
||||
const destin = `../../${tribe}/objects/maillinglists/${typekey}_${mlist}.json`;
|
||||
if (!fs.existsSync(destin)){
|
||||
console.log(`######## Attention tentative d'ecriture non autorisé,le fichier n'existe pas ${destin} créer le à la main vide {}`)
|
||||
return {status:406,ref:"Notifications",msg:"destinnotallow",data:{destin}}
|
||||
if (!fs.existsSync(destin)) {
|
||||
console.log(
|
||||
`######## Attention tentative d'ecriture non autorisé,le fichier n'existe pas ${destin} créer le à la main vide {}`
|
||||
);
|
||||
return {
|
||||
status: 406,
|
||||
ref: "Notifications",
|
||||
msg: "destinnotallow",
|
||||
data: { destin },
|
||||
};
|
||||
}
|
||||
|
||||
const filestorage = fs.existsSync(destin) ? fs.readJsonSync(destin) : {};
|
||||
@@ -81,28 +93,30 @@ Notifications.registertolist = (key, typekey, tribe, mlist, srckey, uuid) => {
|
||||
filestorage[key].srckeys.push(srckey);
|
||||
if (!filestorage[key].uuids.includes(uuid))
|
||||
filestorage[key].uuids.push(uuid);
|
||||
}else{
|
||||
filestorage[key]={}
|
||||
filestorage[key].dt_create=dayjs().toISOString();
|
||||
filestorage[key].srckeys=[srckey];
|
||||
filestorage[key].uuids=[uuid]
|
||||
} else {
|
||||
filestorage[key] = {};
|
||||
filestorage[key].dt_create = dayjs().toISOString();
|
||||
filestorage[key].srckeys = [srckey];
|
||||
filestorage[key].uuids = [uuid];
|
||||
}
|
||||
fs.outputJSONSync(destin, filestorage);
|
||||
return {status:200,ref:"Notifications",msg:"registersuccess",data:{key, typekey, tribe, mlist, srckey, uuid}}
|
||||
}
|
||||
return {
|
||||
status: 200,
|
||||
ref: "Notifications",
|
||||
msg: "registersuccess",
|
||||
data: { key, typekey, tribe, mlist, srckey, uuid },
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Unsubscribe an eamil or phone from a mailinglist for a tribe
|
||||
*/
|
||||
Notifications.unregisterfromlist = (key, typekey, tribe,mlist) => {
|
||||
Notifications.unregisterfromlist = (key, typekey, tribe, mlist) => {
|
||||
key = key.toLowerCase();
|
||||
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Message to send to an alias from an anonymous or not
|
||||
*/
|
||||
Notifications.sendcontact = (body, header) => {
|
||||
|
||||
}
|
||||
Notifications.sendcontact = (body, header) => {};
|
||||
Notifications.sendsms = async (data, tribeId) => {
|
||||
/**
|
||||
* Never use need wallet in mailjet to test
|
||||
@@ -138,11 +152,7 @@ Notifications.sendsms = async (data, tribeId) => {
|
||||
};
|
||||
}
|
||||
let confsms = conf.sms;
|
||||
if (
|
||||
fs.existsSync(
|
||||
`../../itm/${req.session.header.xtribe}.json`
|
||||
)
|
||||
) {
|
||||
if (fs.existsSync(`../../itm/${req.session.header.xtribe}.json`)) {
|
||||
const conftrib = fs.readJSONSync(
|
||||
`../../itm/${req.session.header.xtribe}.json`
|
||||
);
|
||||
@@ -195,6 +205,49 @@ Notifications.sendsms = async (data, tribeId) => {
|
||||
*/
|
||||
};
|
||||
|
||||
Notifications.manageemail = (data, template, tribe) => {
|
||||
/**
|
||||
* Manage email publipostage
|
||||
* data must contain emailsto
|
||||
* data optionaly can contain Cc,Bcc as array of emails and attachments as array of filename (into the server)
|
||||
* Await the 1st email
|
||||
*/
|
||||
|
||||
if (!data.emailsto || data.emailsto.length == 0) {
|
||||
return {
|
||||
status: 406,
|
||||
ref: "Notifications",
|
||||
msg: "emailsmissing",
|
||||
data: data,
|
||||
};
|
||||
}
|
||||
if (typeof data.emailsto === "string") data.emailsto = [data.emailsto];
|
||||
const tplemail = require(path.resolve(template));
|
||||
let sendit;
|
||||
data.emailsto.forEach(async (e, i) => {
|
||||
if (Checkjson.testformat(e, "email")) {
|
||||
const dat = {};
|
||||
dat.to = e;
|
||||
dat.subject = Mustache.render(tplemail.subject, data);
|
||||
dat.html = Mustache.render(tplemail.subject, data);
|
||||
dat.text = Mustache.render(tplemail.text, data);
|
||||
dat.Cc = data.Cc ? tplemail.Cc.push(data.Cc) : tplemail.Cc;
|
||||
dat.Bcc = data.Bcc ? tplemail.Bcc.push(data.Bcc) : tplemail.Bcc;
|
||||
dat.attachments = tplemail.attachments.push(data.attachments);
|
||||
const sendit = Notifications.sendmail(data, tribe);
|
||||
if (i == 0) {
|
||||
sendit = await Notifications.sendmail(data, tribe);
|
||||
if (sendit.status != 200) return sendit;
|
||||
} else {
|
||||
Notifications.sendmail(data, tribe);
|
||||
}
|
||||
} else {
|
||||
// not a well formated email
|
||||
}
|
||||
});
|
||||
return sendit;
|
||||
};
|
||||
|
||||
Notifications.sendmail = async (data, tribe) => {
|
||||
/**
|
||||
* See https://nodemailer.com/message/ for available fields to add
|
||||
@@ -205,7 +258,7 @@ Notifications.sendmail = async (data, tribe) => {
|
||||
* @param {string} data.text
|
||||
* @param {string} [data.Cc] list of email in copy
|
||||
* @param {string} [data.Bcc] list of email in hidden copy
|
||||
* @param {string} [data.attachments] array of
|
||||
* @param {string} [data.attachments] array of
|
||||
* {filename:'filename.txt',content:'txt'},
|
||||
* {filename:'img.svg',path:"https://....svg", contentType:'image/svg'}
|
||||
* {filename:'img.svg',path:"https://....svg", contentType :'text/plain'}
|
||||
@@ -264,8 +317,9 @@ Notifications.sendmail = async (data, tribe) => {
|
||||
let missingfile = [];
|
||||
data.filelist.forEach((fo) => {
|
||||
if (fs.existsSync(fo.pathfile)) {
|
||||
|
||||
} else { missingfile.push(fo.pathfile); }
|
||||
} else {
|
||||
missingfile.push(fo.pathfile);
|
||||
}
|
||||
});
|
||||
if (missingfile.lenght > 0)
|
||||
return {
|
||||
|
Reference in New Issue
Block a user