Merge branch 'fix/nestedtable' into fix/apis-1
This commit is contained in:
@@ -356,10 +356,28 @@ module.exports = {
|
|||||||
const { id, type } = req.body;
|
const { id, type } = req.body;
|
||||||
if (!id || !type) return res.send({ success: false, message: "Missing id or type" });
|
if (!id || !type) return res.send({ success: false, message: "Missing id or type" });
|
||||||
|
|
||||||
const query = {};
|
let query = {};
|
||||||
query[`${type}_id`] = id;
|
|
||||||
|
switch (type) {
|
||||||
|
case "level":
|
||||||
|
case "sublevel":
|
||||||
|
query = { $or: [{ main_level_id: id, parent_sublevel_id: id }] };
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
query[`${type}_id`] = id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
let childrenData = await getChildModel(type).find(query);
|
||||||
|
|
||||||
|
// populate locations to sublevel
|
||||||
|
if (childrenData && ["level", "sublevel"].includes(type)) {
|
||||||
|
const parentData = type === "level" ? await Level.findById(id) : await Sublevel.findById(id);
|
||||||
|
childrenData =
|
||||||
|
parentData && childrenData.map((t1) => ({ ...t1, positions: parentData.sub_levels?.find((t2) => t2.sub_level_id === t1._id)?.positions }));
|
||||||
|
}
|
||||||
|
|
||||||
const childrenData = await getChildModel(type).find(query);
|
|
||||||
res.send({ success: true, data: { parent: { id, type }, childrenData } });
|
res.send({ success: true, data: { parent: { id, type }, childrenData } });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ module.exports = {
|
|||||||
* Create a sublevel
|
* Create a sublevel
|
||||||
*/
|
*/
|
||||||
createSubLevel: async (req, res, next) => {
|
createSubLevel: async (req, res, next) => {
|
||||||
|
console.log(req.body);
|
||||||
const { name, type, specs, parent_id, parentIsLevel, positions } = req.body;
|
const { name, type, specs, parent_id, parentIsLevel, positions } = req.body;
|
||||||
|
|
||||||
if (!(name && type && parent_id && positions)) {
|
if (!(name && type && parent_id && positions)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user