Skip to content

Commit

Permalink
Merge pull request #150 from TogetherCrew/feature/announcement-caseca…
Browse files Browse the repository at this point in the history
…de-delete

Feature/announcement casecade delete
  • Loading branch information
Behzad-rabiei authored Feb 1, 2024
2 parents 82df715 + 42f7a04 commit 19a7101
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@togethercrew.dev/db",
"version": "3.0.29",
"version": "3.0.30",
"description": "All interactions with DB",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
28 changes: 15 additions & 13 deletions src/models/schemas/Platform.schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Schema, type Document } from 'mongoose';
import { Schema, type Document, Types } from 'mongoose';
import { toJSON, paginate } from './plugins';
import { type IPlatform, type PlatformModel } from '../../interfaces';
import { Announcement, Community } from '../index';
Expand Down Expand Up @@ -37,27 +37,29 @@ platformSchema.plugin(paginate);
const announcementDeletion = async (platformId: any): Promise<void> => {
// ?in case the platformID (inputted platformID) of each item in the data array field matches, delete that announcement.
const announcementsWithAllDataOnSamePlatformIds = await Announcement.aggregate([
{
$match: {
'data.platform': platformId,
},
},
{
$project: {
allMatch: {
$not: [
{
$elemMatch: {
'data.platform': { $ne: platformId },
matchNumber: {
$size: {
$filter: {
input: '$data',
as: 'item',
cond: {
$eq: ['$$item.platform', new Types.ObjectId(platformId)],
},
},
],
},
},
allNumber: {
$size: '$data',
},
},
},
{
$match: {
allMatch: true,
$expr: {
$eq: ['$allNumber', '$matchNumber'],
},
},
},
]);
Expand Down

0 comments on commit 19a7101

Please sign in to comment.