You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

99 lines
2.4 KiB

const _ = require("lodash");
initFunctionData = async (data) => {
const {
processId,
payload,
previousData,
ref1Id,
ref2Id,
ref3Id,
ref4Id,
ref5Id,
description,
} = data;
let { unitId } = data;
// if (unitId == 14166153)
// return { statusCode: 403, message: "درحال توسعه", error: data };
const process =
data.process ||
(await bpmsDB.bpms_process.findOne({
where: { id: processId, type: { [Op.in]: [0, 1] } },
raw: true,
}));
// if (process.networkId) {
const processNetwork = await db.network.findByPk(process.networkId, {
raw: true,
attributes: ["level"],
});
// const payloadNetwork = await db.network.findOne({
// where: {
// [`level${processNetwork.level}Id`]: process.networkId,
// id: payload.networkId,
// },
// raw: true,
// });
// }
// let processChecklist = await bpmsDB.bpms_processChecklist.findAll({
// where: { processId: process.id },
// attributes: ["checklistId"],
// order: [["ord", "asc"]],
// });
// const checklistIds =
// data?.checklists?.length
// ? data.checklists.map((item) => +item.id).filter(Boolean).join(",")
// : processChecklist
// .map((e) => +e.checklistId)
// .filter((id) => !isNaN(id) && id !== 0)
// .join(",");
// const previousTask = data.previousTask;
// const network = await db.network.findByPk(processNetwork.id, {
// raw: true,
// });
const network = await db.network.findByPk(payload.networkId, {
raw: true,
});
let newData = {
workflowId: process.workflowId,
processId,
userId: payload.userId,
..._.pick(network, [
"level1Id",
"level2Id",
"level3Id",
"level4Id",
"level5Id",
"level6Id",
]),
};
if (unitId) {
const unit =
data.unit ||
(await db.unit.findOne({
where: { id: unitId, status: 1 },
}));
newData = { ...newData, data: [{ questionId: 100009, answer: unitId }] };
} else {
const unitQuestion = data?.data?.find(
(r) => r.questionId == 100009 && r.answer
);
if (unitQuestion) {
unitId = unitQuestion.answer;
const unit =
data.unit ||
(await db.unit.findOne({
where: { id: unitId, status: 1 },
}));
}
return { data: newData, transaction: data.transaction }
}
}
module.exports = {
initFunctionData
}