60 lines
2.4 KiB
JavaScript
60 lines
2.4 KiB
JavaScript
const db = require("../config/database")
|
|
|
|
async function executeQuery(sql, values) {
|
|
const connection = await db.getConnection()
|
|
try {
|
|
const [rows] = await connection.execute(sql, values)
|
|
return rows
|
|
} finally {
|
|
connection.release()
|
|
}
|
|
}
|
|
|
|
async function buildExtensionByFormCode(acc_id, formId) {
|
|
const sql = `SELECT * FROM rn_ext_field_t WHERE account_id='${acc_id}' AND id='${formId}'`
|
|
const extension = await executeQuery(sql)
|
|
// console.log(extension)
|
|
let extension_entry_form = []
|
|
let extension_grid_form = []
|
|
|
|
if (!extension || extension.length === 0) {
|
|
return { message: "Extension Fields Not Found" }
|
|
} else {
|
|
// for (const extension of extensions) {
|
|
const data_type = extension[0].data_type
|
|
const mapping = extension[0].mapping
|
|
const f_code = extension[0].form_code
|
|
// console.log(mapping)
|
|
const field_name = extension[0].field_name
|
|
|
|
const ext = `,\"extValue\":\"${mapping}\"`
|
|
let fieldInfo = {}
|
|
|
|
if (data_type === "textfield") {
|
|
fieldInfo = `{\"fieldName\":\"" + ${field_name} + "\",\"fieldType\":\"text\",\"fieldValue\":\"\",\"formCode\":\"" + ${f_code} + "\"" + ${ext} + "},`
|
|
} else if (data_type === "date") {
|
|
fieldInfo = `{\"fieldName\":\"" + ${field_name} + "\",\"fieldType\":\"date\",\"fieldValue\":\"\",\"formCode\":\"" + ${f_code} + "\"" + ${ext} + "},`
|
|
} else if (data_type === "l_textfield") {
|
|
fieldInfo = `{\"fieldName\":\"" + ${field_name} + "\",\"fieldType\":\"textarea\",\"fieldValue\":\"\",\"formCode\":\"" + ${f_code} + "\"" + ${ext} + "},`
|
|
} else if (data_type === "checkbox") {
|
|
fieldInfo = `{\"fieldName\":\"" + ${field_name} + "\",\"fieldType\":\"checkbox\",\"fieldValue\":\"\",\"formCode\":\"" + ${f_code} + "\"" + ${ext} + "},`
|
|
} else if (data_type === "autocomplete") {
|
|
fieldInfo = `{\"fieldName\":\"" + ${field_name} + "\",\"fieldType\":\"text\",\"fieldValue\":\"\",\"formCode\":\"" + ${f_code} + "\"" + ${ext} + "},`
|
|
} else if (data_type === "text") {
|
|
fieldInfo = `{\"fieldName\":\"" + ${field_name} + "\",\"fieldType\":\"text\",\"fieldValue\":\"\",\"formCode\":\"" + ${f_code} + "\"" + ${ext} + "},`
|
|
}
|
|
|
|
extension_entry_form.push(fieldInfo)
|
|
|
|
// Extension grid-view code
|
|
extension_grid_form.push(
|
|
`{prop: \"" + ${mapping} + "\", name: \"" + ${field_name} + "\", width: 200},\n`
|
|
)
|
|
// }
|
|
}
|
|
|
|
return extension_entry_form
|
|
}
|
|
|
|
module.exports = { buildExtensionByFormCode }
|