From f1de087299c638fdc48c97d2665d21012a82e18a Mon Sep 17 00:00:00 2001 From: Mohammad Twin Date: Tue, 30 Jan 2024 14:29:55 +0400 Subject: [PATCH 1/2] feat: query for removing announcements were updated --- src/models/schemas/Platform.schema.ts | 28 ++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/models/schemas/Platform.schema.ts b/src/models/schemas/Platform.schema.ts index 1d73e99..60d32fa 100644 --- a/src/models/schemas/Platform.schema.ts +++ b/src/models/schemas/Platform.schema.ts @@ -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'; @@ -37,27 +37,29 @@ platformSchema.plugin(paginate); const announcementDeletion = async (platformId: any): Promise => { // ?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'], + }, }, }, ]); From 42f7a046b1c319bc2091a7092817c19610a4f069 Mon Sep 17 00:00:00 2001 From: Mohammad Twin Date: Tue, 30 Jan 2024 14:30:25 +0400 Subject: [PATCH 2/2] feat: version increased --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fd33fe5..16c644d 100644 --- a/package.json +++ b/package.json @@ -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",