2023-01-22 09:53:09 +00:00
const fs = require ( 'fs-extra' ) ;
const path = require ( 'path' ) ;
const formidable = require ( 'formidable' ) ;
const jsonfile = require ( 'jsonfile' ) ;
const mustache = require ( 'mustache' ) ;
const moment = require ( 'moment' ) ;
const UUID = require ( 'uuid' ) ;
const pdf = require ( "pdf-creator-node" ) ;
const nodemailer = require ( 'nodemailer' ) ;
const smtpTransport = require ( 'nodemailer-smtp-transport' ) ;
const axios = require ( 'axios' ) ;
const { GoogleSpreadsheet } = require ( 'google-spreadsheet' ) ;
const config = require ( '../tribes/townconf.js' ) ;
2023-02-10 10:48:45 +00:00
const checkdata = require ( ` ../nationchains/socialworld/contracts/checkdata.js ` ) ;
2023-01-22 09:53:09 +00:00
const Outputs = { } ;
Outputs . ggsheet2json = async ( req , header ) => {
/ *
req . ggsource = key name of the ggsheet into clientconf
req . sheets = [ list of sheet names to import ]
into / ggsheets / ggsource . json = { resultfolder , productIdSpreadsheet ,
googleDriveCredentials }
* /
if ( ! fs . existsSync ( ` ${ config . tribes } / ${ header . xworkon } / ${ req . ggsource } ` ) ) {
// Misconfiguration
return {
status : 404 ,
payload : {
data : { } ,
info : [ 'Misconfiguration' ] ,
moreinfo : ` ${ header . xworkon } / ${ req . ggsource } missing file check gitlabdocumentation ` ,
model : 'Outputs'
}
} ;
}
const confgg = fs . readJsonSync ( ` ${ config . tribes } / ${ header . xworkon } / ${ req . ggsource } ` , 'utf-8' )
//const ggconnect = clientconf.ggsheet[ req.ggsource ]
//googleDriveCredentials;
2023-02-21 20:51:11 +00:00
//logger.info( ggconnect )
2023-01-22 09:53:09 +00:00
doc = new GoogleSpreadsheet ( confgg . productIdSpreadsheet ) ;
await doc . useServiceAccountAuth ( confgg . googleDriveCredentials ) ;
await doc . loadInfo ( ) ;
let result = [ ] ;
let invalidfor = "" ;
2023-02-21 20:51:11 +00:00
//logger.info( "sheets", req.sheets );
2023-01-22 09:53:09 +00:00
for ( const sheetName of req . sheets ) {
2023-02-21 20:51:11 +00:00
logger . info ( 'loading: ' , sheetName ) ;
2023-01-22 09:53:09 +00:00
if ( ! doc . sheetsByTitle [ sheetName ] ) {
invalidfor += " " + sheetName ;
} else {
sheet = doc . sheetsByTitle [ sheetName ]
await sheet . loadHeaderRow ( ) ;
const records = await sheet . getRows ( { offset : 1 } )
records . forEach ( record => {
let offer = { }
for ( let index = 0 ; index < record . _sheet . headerValues . length ; index ++ ) {
offer [ record . _sheet . headerValues [ index ] ] = record [ record . _sheet . headerValues [ index ] ] ;
}
result . push ( offer ) ;
} ) ;
}
}
const idfile = UUID . v4 ( ) ;
fs . outputJsonSync ( ` ${ config . tribes } / ${ header . xworkon } / ${ confgg . resultfolder } / ${ idfile } .json ` , result , 'utf8' ) ;
if ( invalidfor == "" ) {
return {
status : 200 ,
payload : {
data : ` ${ confgg . resultfolder } / ${ idfile } .json ` ,
info : [ 'Successfull' ] ,
model : 'Outputs'
}
}
} else {
return {
status : 207 ,
payload : {
data : ` ${ confgg . resultfolder } / ${ idfile } .json ` ,
info : [ 'PartialySuccessfull' ] ,
moreinfo : ` Following sheetNames does not exist : ${ invalidfor } ` ,
model : 'Outputs'
}
}
} ;
} ;
// REVOIR TOUT CE QU'IL Y A EN DESSOUS et ré-écrire avec la logique de ggsheet2json phil 25/10/2021
///////////////////////////////////////////////////
const sleep = ( milliseconds = 500 ) => new Promise ( resolve => setTimeout ( resolve , milliseconds ) ) ;
/ *
Process any data to a specific output :
emailer => generate a finale text file to send
csv => export json file to csv data
pdf => generate a customized document
* /
Outputs . envoiemail = async ( msg , nowait , nbfois ) => {
2023-02-21 20:51:11 +00:00
// logger.info('{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}');
// logger.info('msg to send', msg);
logger . info ( 'nbfois' , nbfois ) ;
2023-01-22 09:53:09 +00:00
let transporter = nodemailer . createTransport ( msg . smtp ) ;
if ( ! nowait ) {
2023-02-21 20:51:11 +00:00
logger . info ( 'attente 1er msg avant d envoyer les autres' ) ;
2023-01-22 09:53:09 +00:00
const transport = await transporter . verify ( ) ;
2023-02-21 20:51:11 +00:00
logger . info ( 'transport' , transport ) ;
2023-01-22 09:53:09 +00:00
if ( transport . error ) {
2023-02-21 20:51:11 +00:00
logger . info ( 'Probleme de smtp' , error ) ;
2023-01-22 09:53:09 +00:00
return {
status : 500 ,
payload : {
info : ''
}
} ;
} else {
let rep = await transporter . sendMail ( msg ) ;
2023-02-21 20:51:11 +00:00
logger . info ( 'rep sendMail' , rep ) ;
2023-01-22 09:53:09 +00:00
if ( rep . accepted && rep . accepted . length > 0 && rep . rejected . length == 0 ) {
fs . appendFileSync ( ` ${ config . tribes } / ${ msg . headers [ 'x-client-nd-id' ] } /logs/ ${ msg . headers [ 'x-campaign-id' ] } _success.txt ` , moment ( new Date ( ) )
. format ( 'YYYYMMDD HH:mm:ss' ) + ' - Success after waiting 1st email to send ' + msg . to + '\n' , 'utf-8' ) ;
return {
status : '200' ,
payload : {
info : [ 'send1stemailok' ] ,
model : 'Outputs'
}
} ;
}
// status à tester si necessaire de detecter une erreur
// if (rep.rejectedErrors) {
fs . appendFileSync ( ` ${ config . tribes } / ${ msg . headers [ 'x-client-nd-id' ] } /logs/ ${ msg . headers [ 'x-campaign-id' ] } _error.txt ` , moment ( new Date ( ) )
. format ( 'YYYYMMDD HH:mm:ss' ) + ' - err after waiting result\n ' + msg . to , 'utf-8' ) ;
return {
status : '500' ,
payload : {
info : [ 'rejectedError' ] ,
model : 'Outputs'
}
} ;
}
} else {
transporter . sendMail ( msg , async ( err , info ) => {
if ( err ) {
if ( nbfois < 4 ) {
2023-02-21 20:51:11 +00:00
logger . info ( 'nouvelle tentative ' , nbfois ) ;
2023-01-22 09:53:09 +00:00
await sleep ( 600000 ) ; // attends 60sec pour faire une niéme tentative
Outputs . envoiemail ( msg , true , nbfois + 1 ) ;
} else {
// logerror in file
2023-02-21 20:51:11 +00:00
logger . info ( 'err' , err )
2023-01-22 09:53:09 +00:00
fs . appendFileSync ( ` ${ config . tribes } / ${ msg . headers [ 'x-client-nd-id' ] } /logs/ ${ msg . headers [ 'x-campaign-id' ] } _error.txt ` , moment ( new Date ( ) )
. format ( 'YYYYMMDD HH:mm:ss' ) + ' - err after 4 tries to ' + info . rejected . join ( ',' ) + '\n' , 'utf-8' ) ;
2023-02-21 20:51:11 +00:00
// logger.info('msg.to not well sent', msg.to);
2023-01-22 09:53:09 +00:00
}
} else {
2023-02-21 20:51:11 +00:00
logger . info ( 'info' , info )
// logger.info('msg.to well sent', msg.to);
2023-01-22 09:53:09 +00:00
fs . appendFileSync ( ` ${ config . tribes } / ${ msg . headers [ 'x-client-nd-id' ] } /logs/ ${ msg . headers [ 'x-campaign-id' ] } _success.txt ` , moment ( new Date ( ) )
. format ( 'YYYYMMDD HH:mm:ss' ) + ' - Success after ' + nbfois + ' tries to ' + info . accepted . join ( ',' ) + '\n' , 'utf-8' ) ;
}
} ) ;
}
// return something to not wait the rest of email
return {
status : '200' ,
payload : {
info : [ 'send1stemailok' ] ,
model : 'Outputs'
}
} ;
} ;
Outputs . generemsg = async ( msg , header ) => {
/ *
wait msg sent and return result sent
* /
// Recupere les parametre smtp du domainName à utiliser
2023-02-21 20:51:11 +00:00
logger . info ( 'pass Outputs.generemsg' )
2023-01-22 09:53:09 +00:00
try {
const confclientexpediteur = jsonfile . readFileSync ( ` ${ config . tribes } / ${ msg . tribeidperso . tribeidexpediteur } /clientconf.json ` ) ;
2023-02-21 20:51:11 +00:00
//logger.info('expediteur', confclientexpediteur);
2023-01-22 09:53:09 +00:00
msg . smtp = confclientexpediteur . smtp ;
/ * c o n s t c o n f c l i e n t = j s o n f i l e . r e a d F i l e S y n c (
` ${ config . tribes } / ${ msg . tribeidperso . tribeid } /clientconf.json `
) ; * /
} catch ( err ) {
2023-02-21 20:51:11 +00:00
logger . info ( 'la conf smtp du client n\'est pas definie' ) ;
2023-01-22 09:53:09 +00:00
return {
status : 404 ,
payload : {
info : [ 'smtpnotdefined' ] ,
model : 'Outputs'
}
} ;
}
2023-02-21 20:51:11 +00:00
logger . info ( msg ) ;
2023-01-22 09:53:09 +00:00
if ( ! msg . template . sendascontent && msg . template . htmlfile ) {
try {
msg . template . html = fs . readFileSync ( config . sharedData + '/' + msg . template . htmlfile + '/contentinline.mustache' , 'utf-8' ) ;
msg . template . text = fs . readFileSync ( config . sharedData + '/' + msg . template . htmlfile + '/contenttxt.mustache' , 'utf-8' ) ;
} catch ( err ) {
2023-02-21 20:51:11 +00:00
logger . info ( 'WARNING, html file template missing ' + config . sharedData + '/' + msg . template . htmlfile ) ;
logger . info ( err ) ;
2023-01-22 09:53:09 +00:00
return {
status : 404 ,
payload : {
info : [ 'fileUnknown' ] ,
model : 'UploadFiles' ,
moreinfo : 'Template unavailable, check ' + config . sharedData + '/' + msg . template . htmlfile + '/contentinline.mustache and contenttxt.mustache'
}
} ;
}
}
if ( msg . template . html . length == 0 ) {
2023-02-21 20:51:11 +00:00
logger . info ( 'template.html est vide' )
2023-01-22 09:53:09 +00:00
return {
status : 404 ,
payload : {
info : [ 'ERRnotemplate' ] ,
model : 'Outputs' ,
moreinfo : 'No template email check '
}
} ;
}
// mustache any data into
2023-02-21 20:51:11 +00:00
// logger.info(msg);
2023-01-22 09:53:09 +00:00
const msg2send = { } ;
msg2send . smtp = msg . smtp ;
msg2send . from = msg . tribeidperso . from ;
if ( msg . tribeidperso . cc ) msg2send . cc = msg . tribeidperso . cc ;
if ( msg . tribeidperso . bcc ) msg2send . bcc = msg . tribeidperso . bcc ;
if ( msg . tribeidperso . replyTo ) msg2send . replyTo = msg . tribeidperso . replyTo ;
msg2send . headers = {
'x-campaign-id' : msg . tribeidperso . messageId ,
'x-client-nd-id' : msg . tribeidperso . tribeid ,
'x-template-nd-id' : msg . tribeidperso . templateId
} ;
// we get in datacust= {tribeidperso: with clientconf,destperso: personnalise data to send for email}
2023-02-21 20:51:11 +00:00
// logger.info(msg);
logger . info ( 'nb de message to send:' , msg . destperso . length ) ;
//logger.info(msg.destperso);
2023-01-22 09:53:09 +00:00
//msg.destperso.forEach(async (perso, pos) => {
let pos ;
let pass1ermsg = false ;
for ( pos = 0 ; pos < msg . destperso . length ; pos ++ ) {
const datacust = {
tribeidperso : msg . tribeidperso ,
destperso : msg . destperso [ pos ]
} ;
// Evaluation of each field if mustache exist
const datacusteval = { } ;
Object . keys ( datacust . tribeidperso )
. forEach ( k => {
if ( typeof datacust . tribeidperso [ k ] === 'string' || datacust . tribeidperso [ k ] instanceof String ) {
datacusteval [ k ] = mustache . render ( datacust . tribeidperso [ k ] , datacust )
} else {
datacusteval [ k ] = datacust . tribeidperso [ k ] ;
}
} )
Object . keys ( datacust . destperso )
. forEach ( k => {
if ( typeof datacust . destperso [ k ] === 'string' || datacust . destperso [ k ] instanceof String ) {
datacusteval [ k ] = mustache . render ( datacust . destperso [ k ] , datacust )
} else {
datacusteval [ k ] = datacust . destperso [ k ] ;
}
} )
msg2send . to = msg . destperso [ pos ] . email ;
2023-02-21 20:51:11 +00:00
logger . info ( 'msg2send.to ' + msg2send . to + ' pos:' + pos ) ;
// logger.info('avec datacusteval ', datacusteval)
2023-01-22 09:53:09 +00:00
msg2send . subject = mustache . render ( msg . template . subject , datacusteval ) ;
msg2send . text = mustache . render ( msg . template . text , datacusteval ) ;
msg2send . html = mustache . render ( msg . template . html , datacusteval ) ;
let nowait = true ;
if ( config . emailerurl == 'http://devapia.maildigit.fr:3015' ) {
fs . writeFileSync ( 'devdata/tmp/test.html' , msg2send . html , 'utf-8' ) ;
2023-02-21 20:51:11 +00:00
logger . info ( 'lancement email sur dev, pour controler le mail générer voir ds ./config.js il faut changer config.emailerurl avec https://mail.maildigit.fr pour envoyer le mail ' )
2023-01-22 09:53:09 +00:00
return {
status : 200 ,
payload : {
info : [ 'msgsentok' ] ,
model : 'Outputs' ,
moreinfo : "parametrer sur emailer de dev et pas de production"
}
}
}
if ( pos == 0 ) {
nowait = false ;
/ * w e a r e w a i t i n g t h e f i r s t e m a i l w a s s e n t o k t h e n w e s e n d a l l o t h e r
check NEEDDATA / OVH / workspace / emailerovh to send emailer with nodemailer and nodemailer - smtp - transport
* /
2023-02-21 20:51:11 +00:00
// logger.info('envoie msg', msg);
//logger.info(msg2send);
2023-01-22 09:53:09 +00:00
const ret = await Outputs . envoiemail ( msg2send , nowait , 0 ) ;
2023-02-21 20:51:11 +00:00
logger . info ( 'ret 1er msg' , ret ) ;
2023-01-22 09:53:09 +00:00
if ( ret . status == 200 ) {
pass1ermsg = true ;
} ;
} else if ( pass1ermsg ) {
2023-02-21 20:51:11 +00:00
logger . info ( '###############################################' )
logger . info ( "envoie msg numero: " + pos + " email: " + msg2send . to )
//logger.info(msg2send)
2023-01-22 09:53:09 +00:00
Outputs . envoiemail ( msg2send , nowait , 0 ) ;
/ * O u t p u t s . e n v o i e m a i l ( m s g 2 s e n d , n o w a i t , 0 ) . t h e n ( r e p = > {
2023-02-21 20:51:11 +00:00
logger . info ( "envoie email" + pos )
2023-01-22 09:53:09 +00:00
} ) . catch ( err => {
2023-02-21 20:51:11 +00:00
logger . info ( err ) ;
2023-01-22 09:53:09 +00:00
} ) ; * /
} ;
} ;
if ( pass1ermsg ) {
return {
status : 200 ,
payload : {
info : [ 'msgsentok' ] ,
model : 'Outputs'
}
} ;
} else {
return {
status : 500 ,
payload : {
info : [ 'msgsentko' ] ,
model : 'Ouputs' ,
moreinfo : "1er msg non envoyé car erreur"
}
}
}
} ;
Outputs . sendMailcampain = async ( msg , headersmsg ) => {
/ *
Permet de lancer une campagne de mail personnalisé en mode web service
avec axios config . emailerurl https : //mail qui peut être sur un autre serveur que celui en cours
Attention headermsg doit être retraduit avec les champs envoyé par un navigateur
Si le serveur en cours appelle cette fonction les champs du header doivent changer
voir config . js node _env . exposedHeaders
Pour un exemple de msg voir u exemple type de message envoyé dans un tribeid / domain / clientconf . json
avec l 'envoi d' email
* /
2023-02-21 20:51:11 +00:00
//logger.info(msg)
2023-01-22 09:53:09 +00:00
// On ajoute le contenu du template directement dans la demande
if ( msg . template . sendascontent && msg . template . htmlfile ) {
try {
2023-02-21 20:51:11 +00:00
logger . info ( 'test' , msg . template . sendascontent )
2023-01-22 09:53:09 +00:00
msg . template . html = fs . readFileSync ( config . sharedData + '/' + msg . template . htmlfile + '/contentinline.mustache' , 'utf-8' ) ;
msg . template . text = fs . readFileSync ( config . sharedData + '/' + msg . template . htmlfile + '/contenttxt.mustache' , 'utf-8' ) ;
} catch ( err ) {
2023-02-21 20:51:11 +00:00
logger . info ( 'WARNING, html file template missing ' + config . sharedData + '/' + msg . template . htmlfile ) ;
//logger.info(err);
2023-01-22 09:53:09 +00:00
return {
status : 404 ,
payload : {
info : [ 'fileUnknown' ] ,
model : 'UploadFiles' ,
moreinfo : 'Template unavailable, check ' + config . sharedData + '/' + msg . template . htmlfile + '/contentinline.mustache and contenttxt.mustache'
}
} ;
}
delete msg . template . htmlfile ;
if ( msg . template . html . length == 0 ) {
return {
status : 404 ,
payload : {
info : [ 'ERRnotemplate' ] ,
model : 'Outputs' ,
moreinfo : 'No template email check '
}
} ;
}
}
2023-02-21 20:51:11 +00:00
logger . info ( 'envoie sur' , ` ${ config . emailerurl } /outputs/msg ` )
//logger.info(msg)
2023-01-22 09:53:09 +00:00
// on check si les key de headermsg sont des key traduite via exposedHeaders
// (cas ou c'est l'application qui envoie un email)
if ( headersmsg . xtribeid ) {
Object . keys ( config . exposedHeaders )
. forEach ( h => {
headersmsg [ h ] = headersmsg [ config . exposedHeaders [ h ] ] ;
delete headersmsg [ config . exposedHeaders [ h ] ] ;
} ) ;
}
// on ajoute le code pour la signature
headersmsg . hashbody = msg . code ;
2023-02-21 20:51:11 +00:00
logger . info ( 'header after traduction: ' , headersmsg )
2023-01-22 09:53:09 +00:00
try {
const resCamp = await axios . post ( ` ${ config . emailerurl } /outputs/msg ` , msg , {
headers : headersmsg
} ) ;
2023-02-21 20:51:11 +00:00
//logger.info('Etat:', resCamp);
logger . info ( 'Tried to send 1st email of the campain ' + msg . destperso [ 0 ] . email ) ;
2023-01-22 09:53:09 +00:00
// it just check the 1st email in destperso to return an answer if 1st is ok then all other are send in queue
if ( resCamp ) {
return resCamp ;
} else {
return { status : 200 , payload : { info : [ 'CampainSent' ] , model : 'Outputs' } } ;
}
} catch ( err ) {
// aios error handler
return { status : 401 , payload : { info : [ 'erreuraxios' ] , model : 'Outputs' , moreinfo : err . message } }
}
} ;
Outputs . get = function ( filename , header ) {
// check file exist
const file = ` ${ config . tribes } / ${ header . xworkon } / ${ filename } ` ;
2023-02-21 20:51:11 +00:00
// logger.info('fichier demande ', file);
2023-01-22 09:53:09 +00:00
if ( ! fs . existsSync ( file ) ) {
2023-02-21 20:51:11 +00:00
// logger.info('le fichier demande n existe pas ', file);
2023-01-22 09:53:09 +00:00
return {
status : 404 ,
payload : {
info : [ 'fileUnknown' ] ,
model : 'UploadFiles'
}
} ;
} else {
2023-02-21 20:51:11 +00:00
logger . info ( 'envoie le fichier ' , file ) ;
2023-01-22 09:53:09 +00:00
return {
status : 200 ,
payload : {
info : [ 'fileknown' ] ,
model : 'UploadFiles' ,
file : file
}
} ;
}
} ;
Outputs . addjson = function ( data , header ) {
/ *
Le header = { X - WorkOn : "" , destinationfile : "" , filename : "" }
Le body = { jsonp : { } , callback : function to launch after download , 'code' : 'mot cle pour verifier que le fichier est à garder' }
* /
2023-02-21 20:51:11 +00:00
// logger.info(req.body.jsonp);
2023-01-22 09:53:09 +00:00
try {
jsonfile . writeFileSync ( header . destinationfile + '/' + header . filename , data . jsonp ) ;
if ( data . callback ) {
const execCB = require ( ` ${ config . mainDir } /models/tribeid/ ${ header . xworkon
} ` );
execCB [ data . callback ] ( ) ;
}
return {
status : 200 ,
payload : {
info : [ 'wellUpload' ] ,
model : 'UploadFiles' ,
render : {
destination : header . destinationfile ,
filename : header . filename
}
}
} ;
} catch ( err ) {
2023-02-21 20:51:11 +00:00
logger . info ( 'Impossible de sauvegarder le fichier, A COMPRENDRE' , err ) ;
2023-01-22 09:53:09 +00:00
return {
status : 503 ,
payload : {
info : [ 'savingError' ] ,
model : 'UploadFiles'
}
} ;
}
} ;
Outputs . add = function ( req , header ) {
const form = new formidable . IncomingForm ( ) ;
2023-02-21 20:51:11 +00:00
logger . info ( 'req.headers' , req . headers ) ;
logger . info ( 'req.params' , req . params ) ;
logger . info ( 'req.query' , req . query ) ;
logger . info ( 'req.body' , req . body ) ;
2023-01-22 09:53:09 +00:00
let destinationfile = ` ${ config . tribes } / ${ header . xworkon } / ${ header . destinationfile
} ` ;
form . parse ( req , function ( err , fields , files ) {
2023-02-21 20:51:11 +00:00
logger . info ( 'files' , files . file . path ) ;
logger . info ( 'fields' , fields ) ;
2023-01-22 09:53:09 +00:00
const oldpath = files . file . path ;
destinationfile += '/' + files . file . name ;
2023-02-21 20:51:11 +00:00
logger . info ( 'oldpath' , oldpath ) ;
logger . info ( 'destinationfile' , destinationfile ) ;
2023-01-22 09:53:09 +00:00
fs . copyFile ( oldpath , destinationfile , function ( err ) {
if ( err ) {
2023-02-21 20:51:11 +00:00
logger . info ( err ) ;
2023-01-22 09:53:09 +00:00
return {
status : 500 ,
payload : {
info : [ 'savingError' ] ,
model : 'UploadFiles'
}
} ;
} else {
2023-02-21 20:51:11 +00:00
logger . info ( 'passe' ) ;
2023-01-22 09:53:09 +00:00
fs . unlink ( oldpath ) ;
return {
status : 200 ,
payload : {
info : [ 'wellUpload' ] ,
model : 'UploadFiles' ,
render : {
destination : destinationfile
}
}
} ;
}
} ) ;
} ) ;
} ;
Outputs . generepdf = ( req , header ) => {
return new Promise ( ( resolve , reject ) => {
let options = {
format : "A4" ,
orientation : "portrait" ,
border : "10mm" ,
footer : {
height : "20mm" ,
contents : {
default : '<span style="color: #444;">{{page}}</span>/<span>{{pages}}</span>' , // html pagination if edit needed
}
}
} ;
let document = {
html : req . html ,
data : {
data : req . data ,
} ,
path : ` ${ config . tribes } / ${ header . xtribe } /outputs/ ${ UUID . v4 ( ) } .pdf ` ,
type : "" ,
} ;
pdf // generate pdf
. create ( document , options )
. then ( ( res ) => {
resolve ( {
status : 200 ,
payload : {
info : [ 'wellPdfGenerated' ] ,
model : 'Outputs' ,
data : {
path : document . path ,
filename : req . data . filename
} ,
render : {
filename : req . data . filename
}
}
} ) ;
} )
. catch ( ( err ) => {
reject ( {
status : 500 ,
payload : {
info : [ 'pdfGenerationError' ] ,
model : 'Outputs' ,
error : err
}
} ) ;
} ) ;
} ) ;
} ;
module . exports = Outputs ;