master
shoaibalmasi 4 years ago
parent 3d416fb96b
commit 8532bb72d9
  1. 32
      tools/docxtemp.js

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

Loading…
Cancel
Save