diff --git a/backend/src/libs/repositories/interfaces/base.repository.interface.ts b/backend/src/libs/repositories/interfaces/base.repository.interface.ts index c960baca0..43ebe19fb 100644 --- a/backend/src/libs/repositories/interfaces/base.repository.interface.ts +++ b/backend/src/libs/repositories/interfaces/base.repository.interface.ts @@ -1,18 +1,24 @@ -import { UpdateQuery } from 'mongoose'; +import { PopulateOptions, UpdateQuery } from 'mongoose'; import { ModelProps, SelectedValues } from '../types'; +export type PopulateType = PopulateOptions | (PopulateOptions | string)[]; + export interface BaseInterfaceRepository { findAll(selectedValues?: SelectedValues): Promise; - findOneById(id: any, selectedValues?: SelectedValues, populate?: any): Promise; + findOneById(id: any, selectedValues?: SelectedValues, populate?: PopulateType): Promise; - findAllWithQuery(query: any, selectedValues?: SelectedValues, populate?: any): Promise; + findAllWithQuery( + query: any, + selectedValues?: SelectedValues, + populate?: PopulateType + ): Promise; findOneByField(fields: ModelProps): Promise; create(item: T): Promise; - update(id: string, item: T); + update(id: string, item: T): Promise; deleteMany(field: ModelProps, withSession: boolean): Promise; @@ -22,11 +28,11 @@ export interface BaseInterfaceRepository { findOneAndRemoveByField(fields: ModelProps, withSession: boolean): Promise; - startTransaction(); + startTransaction(): Promise; - commitTransaction(); + commitTransaction(): Promise; - abortTransaction(); + abortTransaction(): Promise; - endSession(); + endSession(): Promise; } diff --git a/backend/src/libs/repositories/mongo/mongo-generic.repository.ts b/backend/src/libs/repositories/mongo/mongo-generic.repository.ts index c8ddba71f..26a2f0bcc 100644 --- a/backend/src/libs/repositories/mongo/mongo-generic.repository.ts +++ b/backend/src/libs/repositories/mongo/mongo-generic.repository.ts @@ -1,9 +1,7 @@ -import { ClientSession, Model, PopulateOptions, UpdateQuery } from 'mongoose'; -import { BaseInterfaceRepository } from '../interfaces/base.repository.interface'; +import { ClientSession, Model, UpdateQuery } from 'mongoose'; +import { BaseInterfaceRepository, PopulateType } from '../interfaces/base.repository.interface'; import { ModelProps, SelectedValues } from '../types'; -type PopulateType = PopulateOptions | (PopulateOptions | string)[]; - export class MongoGenericRepository implements BaseInterfaceRepository { protected _repository: Model; protected _session: ClientSession; @@ -49,8 +47,8 @@ export class MongoGenericRepository implements BaseInterfaceRepository { return this._repository.create(item); } - update(id: string, item: T) { - return this._repository.findByIdAndUpdate(id, item); + update(id: string, item: T): Promise { + return this._repository.findByIdAndUpdate(id, item).exec(); } findOneByFieldAndUpdate(value: ModelProps, query: UpdateQuery): Promise {