Skip to content

Commit

Permalink
add isDeleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Xziy committed May 7, 2024
1 parent c7adb86 commit 9de7cf8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions models/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ let Model = {
let childGroups = [];
const cgs = await Group.find({
id: group.childGroups.map((cg) => cg.id),
isDeleted: false
})
.populate("childGroups")
.populate("dishes")
Expand Down Expand Up @@ -261,7 +262,7 @@ let Model = {
let allGroups = [];
for (let group of menu) {
const groupId = group.id;
const initialGroup = (await Group.find({ id: groupId }).sort('createdAt DESC')).shift();
const initialGroup = (await Group.find({ id: groupId, isDeleted: false }).sort('createdAt DESC')).shift();
if (initialGroup) {
allGroups.push(initialGroup);
const childGroups = await getAllChildGroups(groupId);
Expand All @@ -270,7 +271,7 @@ let Model = {
}
}
async function getAllChildGroups(groupId) {
let childGroups = await Group.find({ parentGroup: groupId, isDeleted: !true });
let childGroups = await Group.find({ parentGroup: groupId, isDeleted: false });
let allChildGroups = [];
for (let group of childGroups) {
allChildGroups.push(group);
Expand Down Expand Up @@ -319,13 +320,15 @@ let Model = {
groups = await Group.find({
parentGroup: topLevelGroupId ?? null,
...concept && { concept: concept },
isDeleted: false,
modifier: false,
visible: true
});
// Check subgroups when one group in the top menu
if (groups.length === 1 && topLevelGroupId === undefined) {
let children = await Group.find({
parentGroup: groups[0].id,
isDeleted: false,
modifier: false,
visible: true
});
Expand Down
9 changes: 6 additions & 3 deletions models/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ let Model = {
if (group.childGroups) {
let childGroups = [];
const cgs = await Group.find({
id: group.childGroups.map((cg) => cg.id),
id: group.childGroups.map((cg) => cg.id),
isDeleted: false
})
.populate("childGroups")
.populate("dishes")
Expand Down Expand Up @@ -325,7 +326,7 @@ let Model = {
let allGroups = [];
for (let group of menu) {
const groupId = group.id
const initialGroup = (await Group.find({ id: groupId }).sort('createdAt DESC')).shift();
const initialGroup = (await Group.find({ id: groupId, isDeleted: false }).sort('createdAt DESC')).shift();
if (initialGroup) {
allGroups.push(initialGroup);
const childGroups = await getAllChildGroups(groupId);
Expand All @@ -335,7 +336,7 @@ let Model = {
}

async function getAllChildGroups(groupId) {
let childGroups = await Group.find({ parentGroup: groupId, isDeleted: !true });
let childGroups = await Group.find({ parentGroup: groupId, isDeleted: false });
let allChildGroups = [];

for (let group of childGroups) {
Expand Down Expand Up @@ -396,6 +397,7 @@ let Model = {
groups = await Group.find({
parentGroup: topLevelGroupId ?? null,
...concept && { concept: concept },
isDeleted: false,
modifier: false,
visible: true
});
Expand All @@ -404,6 +406,7 @@ let Model = {
if(groups.length === 1 && topLevelGroupId === undefined) {
let children = await Group.find({
parentGroup: groups[0].id,
isDeleted: false,
modifier: false,
visible: true
});
Expand Down

0 comments on commit 9de7cf8

Please sign in to comment.