diff --git a/src/service/print/getdocxdata.js b/src/service/print/getdocxdata.js index b334aa4d5dbf04ce598d972c5ea8b961e5e8bca9..0707d66603d9ffb2e89b9dfbd877ccfb95c9084a 100644 --- a/src/service/print/getdocxdata.js +++ b/src/service/print/getdocxdata.js @@ -17,6 +17,7 @@ const { ITableCellMarginOptions, convertInchesToTwip, } = docx; +const _ = require("lodash"); function create(data, paperData) { const doc = new Document({ @@ -79,15 +80,8 @@ function create(data, paperData) { }), ], }), - new Paragraph({ - alignment: AlignmentType.LEFT, - children: [ - new TextRun({ - text: `Instructions:`, - bold: true, - }), - ], - }), + + instructionHead(paperData.instructions), instructions(paperData.instructions), new Paragraph({ alignment: AlignmentType.CENTER, @@ -293,27 +287,56 @@ function create(data, paperData) { return doc; } +function instructionHead(data) { + const arr = []; + + if (!_.isUndefined(data)) { + arr.push( + new TextRun({ + text: `Instructions:`, + bold: true, + }) + ); + return new Paragraph({ + alignment: AlignmentType.LEFT, + children: arr, + }); + } +} + function instructions(data) { const arr = []; - data - .map((text) => { - arr.push( - new TextRun({ - text: `${text}`, - break: 1, - bold: true, - }) - ); - }) - .reduce((prev, curr) => prev.concat(curr), []); - return new Paragraph({ - alignment: AlignmentType.LEFT, - indent: { - left: 720, - }, - children: arr, - }); + + if (_.isUndefined(data)) { + return new Paragraph({ + alignment: AlignmentType.LEFT, + indent: { + left: 720, + }, + children: arr, + }); + } else { + data + .map((text) => { + arr.push( + new TextRun({ + text: `${text}`, + break: 1, + bold: true, + }) + ); + }) + .reduce((prev, curr) => prev.concat(curr), []); + return new Paragraph({ + alignment: AlignmentType.LEFT, + indent: { + left: 720, + }, + children: arr, + }); + } } + function displayMTFHeader(data) { return new TableCell({ borders: MTFborder, @@ -375,7 +398,7 @@ function MTFTabel(question) { } function createFTB(data, count) { - if(data === undefined){ + if (_.isUndefined(data)) { return new Paragraph({ alignment: AlignmentType.LEFT, children: [ @@ -411,7 +434,7 @@ function createFTB(data, count) { function createSAObject(data, count) { const arr = []; - if(data === undefined){ + if (_.isUndefined(data)) { return createFTB(data, count); } if (data.text) { @@ -920,7 +943,6 @@ function formatview(data, count, questionCounter, marks) { } function mtfTableData(data) { - const cell = new TableCell({ children: [MTFTabel(data)], }); diff --git a/src/service/print/printDocxV1.0/dataImporter.js b/src/service/print/printDocxV1.0/dataImporter.js index aed3f4a35b73bbe8c3b473252bac2a49287b94c8..2743ec217306cd4dee5cd74f25353a025a005755 100644 --- a/src/service/print/printDocxV1.0/dataImporter.js +++ b/src/service/print/printDocxV1.0/dataImporter.js @@ -1,7 +1,7 @@ const { async } = require("rxjs/internal/scheduler/async"); const fetch = require("node-fetch"); const axios = require("axios"); - +const _ = require("lodash") const envVariables = require("../../../envVariables"); const { result } = require("lodash"); @@ -67,7 +67,7 @@ const getQuestionSet = async (id) => { }); // Hierarchy const instructions = await getQuestionForSet(id); - + const promiseMap = questionIds.map((sec) => sec.map((question) => { if (question !== undefined) { @@ -94,13 +94,10 @@ const getQuestionSet = async (id) => { questions: questions, }; }); - - - return { sectionData, paperData: data, - instructions: instructions.instructions.default + instructions: _.isUndefined(instructions.instructions) ? undefined : instructions.instructions.default }; }); }) diff --git a/src/service/print/printDocxV1.0/docx.js b/src/service/print/printDocxV1.0/docx.js index 7f2f7ad185079edf8884eceb62afde812fbc4630..45960f87654c641709f7cefb829c4bf8e2c3cf83 100644 --- a/src/service/print/printDocxV1.0/docx.js +++ b/src/service/print/printDocxV1.0/docx.js @@ -33,7 +33,7 @@ const buildDOCX_1_WithCallback = async (id, callback) => { examName: examName, className: grade, subject: subject, - instructions: instructions.split(/\n/), + instructions: instructions == undefined ? undefined : instructions.split(/\n/), }; let questionCounter = 0;