-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateHandler.js
44 lines (33 loc) · 1.21 KB
/
generateHandler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const { keycloakForFormRepo } = require("./keycloak.js");
const axios = require("axios");
const populateDatabindings = require("./databindingsHandler.js");
const getFormFromFormTemplate = require("./formRepoHandler.js");
async function generateTemplate(req, res) {
const params = req.body;
const template_id = params["formId"];
console.log("template_id>>",template_id);
if ( !template_id) {
return res
.status(400)
.send({ error: "form Id is required" });
}
const formJson = await constructFormJson(template_id,params);
res.status(200).send({
save_data: formJson
});
}
async function constructFormJson(formId, params) {
const formDefinition = await getFormFromFormTemplate(formId) || {};
const formData = await populateDatabindings(formDefinition,params);
const fullJSON = {
data: formData|| {},
form_definition: formDefinition || {}, // Providing default empty object if missing
metadata: {
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
version: "1.0.0", // Add any other metadata
}
};
return fullJSON;
}
module.exports = generateTemplate;