Skip to content

Commit 75aa6d1

Browse files
committed
Fix: Issues with xml2json convertor
1 parent c286cf9 commit 75aa6d1

File tree

11 files changed

+30779
-18
lines changed

11 files changed

+30779
-18
lines changed

packages/enketo-express/package-lock.json

Lines changed: 37 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/enketo-express/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"jstransformer-markdown-it": "^2.1.0",
6767
"jszip": "^3.7.1",
6868
"jwt-simple": "^0.5.6",
69+
"libxslt": "^0.10.1",
6970
"load-grunt-tasks": "^5.1.0",
7071
"lodash": "^4.17.21",
7172
"morgan": "^1.10.0",

packages/enketo-express/public/js/src/module/form-controller.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class FormController {
6464
// execute method string
6565
if (functionString) {
6666
//TODO: fix this with a sandbox
67-
return eval(functionString)(this.formData);
67+
return (0, eval)(functionString)(this.formData);
6868
} else {
6969
throw new Error('No function string provided');
7070
}
@@ -75,10 +75,8 @@ export class FormController {
7575
}
7676

7777
async processForm(formData) {
78-
console.log({ formData });
79-
console.log(xml2json(formData).data);
8078
const doc = this._parser.parseFromString(formData, 'text/xml');
81-
this.formData = doc;
79+
this.formData = (await fetch('http://localhost:3002/form/parse/' + encodeURIComponent(formData)).then(res => res.json())).data;
8280
if (await this.formSpec.isSuccessExecute() === true) {
8381
this._state = 'FORM_SUCCESS';
8482
this._onFormSuccessData = await this.formSpec.onFormSuccessExecute();

packages/form-manager/package-lock.json

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/form-manager/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"prebuild": "rimraf dist",
1010
"build": "nest build",
1111
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
12-
"start": "nest start",
12+
"start": "nest start --watch",
1313
"start:dev": "nest start --watch",
1414
"start:debug": "nest start --debug --watch",
1515
"start:prod": "node dist/main",
@@ -28,7 +28,8 @@
2828
"rimraf": "^3.0.2",
2929
"rxjs": "^7.2.0",
3030
"webpack": "^5.74.0",
31-
"xmldom": "^0.6.0"
31+
"xmldom": "^0.6.0",
32+
"xml2json": "^0.12.0"
3233
},
3334
"devDependencies": {
3435
"@nestjs/cli": "^8.0.0",
@@ -70,4 +71,4 @@
7071
"coverageDirectory": "../coverage",
7172
"testEnvironment": "node"
7273
}
73-
}
74+
}

packages/form-manager/src/app.controller.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common';
22
import { AppService } from './app.service';
33

4+
// eslint-disable-next-line @typescript-eslint/no-var-requires
5+
const parser = require('xml2json');
6+
47
type PrefillDto = {
58
form: string;
69
onFormSuccessData: any;
@@ -53,4 +56,9 @@ export class AppController {
5356
getForm(@Param('id') id): string {
5457
return this.appService.getForm(id);
5558
}
59+
60+
@Get('form/parse/:xml')
61+
parseXML(@Param('xml') xml): any {
62+
return parser.toJson(xml);
63+
}
5664
}

0 commit comments

Comments
 (0)