|
|
@ -60,12 +60,12 @@ module.exports = function (templateInfo, fileName) { |
|
|
|
//check empty fields
|
|
|
|
//check empty fields
|
|
|
|
for (const key in templateInfo) { |
|
|
|
for (const key in templateInfo) { |
|
|
|
if (!templateInfo[key]) { |
|
|
|
if (!templateInfo[key]) { |
|
|
|
throw({ |
|
|
|
throw ({ |
|
|
|
eCode: 406, |
|
|
|
eCode: 406, |
|
|
|
eText: 'هیچ یک از فیلدها نباید خالی باشند' |
|
|
|
eText: 'هیچ یک از فیلدها نباید خالی باشند' |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let content = fs.readFileSync(path.resolve(__dirname, `../template/${fileName}`), 'binary'); |
|
|
|
let content = fs.readFileSync(path.resolve(__dirname, `../template/${fileName}`), 'binary'); |
|
|
|
let zip = new PizZip(content); |
|
|
|
let zip = new PizZip(content); |
|
|
@ -73,7 +73,7 @@ module.exports = function (templateInfo, fileName) { |
|
|
|
let inspectModule = new InspectModule(); |
|
|
|
let inspectModule = new InspectModule(); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
doc = new Docxtemplater(zip,{ |
|
|
|
doc = new Docxtemplater(zip, { |
|
|
|
modules: [inspectModule] |
|
|
|
modules: [inspectModule] |
|
|
|
}); |
|
|
|
}); |
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
@ -82,18 +82,18 @@ module.exports = function (templateInfo, fileName) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let postParsed = inspectModule.inspect.postparsed; |
|
|
|
let postParsed = inspectModule.inspect.postparsed; |
|
|
|
let tags = Object.keys(getTags(postParsed)) |
|
|
|
let placeholders = Object.keys(getTags(postParsed)) |
|
|
|
let templateInfoKeys = Object.keys(templateInfo) |
|
|
|
let templateInfoKeys = Object.keys(templateInfo) |
|
|
|
|
|
|
|
|
|
|
|
//compare template tags and received fields from client(templateInfo)
|
|
|
|
//compare template placeholders and received fields from client(templateInfo)
|
|
|
|
for(let i = 0; i < tags.length; i++){ |
|
|
|
for (let i = 0; i < placeholders.length; i++) { |
|
|
|
if(!templateInfoKeys.includes(tags[i]) ){ |
|
|
|
if (!templateInfoKeys.includes(placeholders[i])) { |
|
|
|
throw({ |
|
|
|
throw ({ |
|
|
|
eCode: 406, |
|
|
|
eCode: 406, |
|
|
|
eText: 'اطلاعات وارد شده ناقص است' |
|
|
|
eText: 'اطلاعات وارد شده ناقص است' |
|
|
|
}) |
|
|
|
}) |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
doc.setData(templateInfo); |
|
|
|
doc.setData(templateInfo); |
|
|
|
|
|
|
|
|
|
|
|