From 2e44f8a97b8bd89842c920dd7f300025a09dc662 Mon Sep 17 00:00:00 2001 From: Ingvord Date: Mon, 29 Jul 2024 16:01:31 +0200 Subject: [PATCH] Fix for #1338 --- src/datasets/datasets.service.ts | 38 ++++++++++++++++++++++++++++++-- src/users/users.service.ts | 8 +++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/datasets/datasets.service.ts b/src/datasets/datasets.service.ts index c78974c1e..d303fce07 100644 --- a/src/datasets/datasets.service.ts +++ b/src/datasets/datasets.service.ts @@ -9,7 +9,17 @@ import { ConfigService } from "@nestjs/config"; import { REQUEST } from "@nestjs/core"; import { InjectModel } from "@nestjs/mongoose"; import { Request } from "express"; -import { FilterQuery, Model, QueryOptions, UpdateQuery } from "mongoose"; +import { + FilterQuery, + HydratedDocument, + IfAny, + Model, + ModifyResult, + Query, + QueryOptions, + Schema, + UpdateQuery, +} from "mongoose"; import { JWTUser } from "src/auth/interfaces/jwt-user.interface"; import { IFacets, IFilters } from "src/common/interfaces/common.interface"; import { @@ -39,6 +49,7 @@ import { } from "./dto/update-raw-dataset.dto"; import { IDatasetFields } from "./interfaces/dataset-filters.interface"; import { DatasetClass, DatasetDocument } from "./schemas/dataset.schema"; +import Types = Schema.Types; @Injectable({ scope: Scope.REQUEST }) export class DatasetsService { @@ -288,7 +299,30 @@ export class DatasetsService { } // DELETE dataset - async findByIdAndDelete(id: string): Promise { + async findByIdAndDelete(id: string): Promise< + Query< + ModifyResult>, + Document & DatasetClass & Document extends { + _id?: infer U; + } + ? IfAny< + U, + DatasetClass & + Document & { + _id: Types.ObjectId; + }, + DatasetClass & Document & Required<{ _id: U }> + > + : DatasetClass & + Document & { + _id: Types.ObjectId; + }, + object, + DatasetClass & Document, + "findOneAndDelete" + > & + object + > { if (this.ESClient) { await this.ESClient.deleteDocument(id); } diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 7369730d7..c8dd0fe83 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -2,7 +2,7 @@ import { Injectable, Logger, OnModuleInit } from "@nestjs/common"; import { ConfigService } from "@nestjs/config"; import { InjectModel } from "@nestjs/mongoose"; import { genSalt, hash } from "bcrypt"; -import { FilterQuery, Model } from "mongoose"; +import { FilterQuery, HydratedDocument, Model, ModifyResult } from "mongoose"; import { CreateUserIdentityDto } from "./dto/create-user-identity.dto"; import { CreateUserDto } from "./dto/create-user.dto"; import { RolesService } from "./roles.service"; @@ -249,7 +249,11 @@ export class UsersService implements OnModuleInit { } // NOTE: This is just for testing purposes inside accessGroups.e2e-spec.ts - async removeUserIdentity(userId: string): Promise { + async removeUserIdentity( + userId: string, + ): Promise< + ModifyResult> + > { const removedUserIdentity = await this.userIdentityModel .findOneAndDelete({ userId }) .exec();