Untitled
user_7626021
plain_text
a month ago
1.0 kB
1
Indexable
Never
const addRefToViewAllGroups2 = async (userId, projectBinId) => { const viewAllGroup = await UserProjectGroup.findOne({ user: userId }); if (!viewAllGroup || !viewAllGroup.viewAllGroups) return; const viewAllGroups = Array.from(viewAllGroup.viewAllGroups).map(([key, value]) => ({ [key]: value, })); console.log("viewAllGroups before",viewAllGroups) const id = `Ungroup_${projectBinId}` const newObj = { [id]: [] }; viewAllGroups.unshift(newObj); console.log("viewAllGroups after",viewAllGroups) const resultObject = viewAllGroups.reduce((acc, obj) => { const key = Object.keys(obj)[0]; acc[key] = obj[key]; return acc; }, {}); console.log("resultObject",resultObject) try { await UserProjectGroup.updateOne( { user: userId }, { viewAllGroups: resultObject } ); } catch (error) { console.log(error) } await addRefToViewAllGroups(userId, projectBinId, id) res.json({ viewAllGroup }); };
Leave a Comment