From 2f62f49a69094d449a93836b3f2c0a68aecb0277 Mon Sep 17 00:00:00 2001
From: snehar-nd <sneha@navadhiti.com>
Date: Tue, 26 Apr 2022 12:54:00 +0530
Subject: [PATCH] FIx for instrucion data.

---
 src/service/print/getdocxdata.js              | 75 +++++++++++--------
 .../print/printDocxV1.0/dataImporter.js       |  4 +-
 2 files changed, 45 insertions(+), 34 deletions(-)

diff --git a/src/service/print/getdocxdata.js b/src/service/print/getdocxdata.js
index 7d77ee3..0707d66 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,28 +287,46 @@ 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 = [];
-  if(data !== undefined){
-    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: {
@@ -323,8 +335,8 @@ function instructions(data) {
       children: arr,
     });
   }
-  
 }
+
 function displayMTFHeader(data) {
   return new TableCell({
     borders: MTFborder,
@@ -386,7 +398,7 @@ function MTFTabel(question) {
 }
 
 function createFTB(data, count) {
-  if(data === undefined){
+  if (_.isUndefined(data)) {
     return new Paragraph({
       alignment: AlignmentType.LEFT,
       children: [
@@ -422,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) {
@@ -931,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 c1a4a25..2743ec2 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");
 
@@ -97,7 +97,7 @@ const getQuestionSet = async (id) => {
       return {
         sectionData,
         paperData: data,
-        instructions: instructions.instructions === undefined ? undefined:instructions.instructions.default
+        instructions: _.isUndefined(instructions.instructions) ? undefined : instructions.instructions.default
       };
     });
   })
-- 
GitLab