From a20f695d91b8e70a4e86fe60074e6936c68a4f15 Mon Sep 17 00:00:00 2001 From: Behzad-rabiei Date: Wed, 28 May 2025 12:00:17 +0200 Subject: [PATCH] feat: add upsert repo --- CHANGELOG.md | 41 ----------------------------- src/repositories/base.repository.ts | 23 ++++++++++------ 2 files changed, 15 insertions(+), 49 deletions(-) delete mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index f36a3a7..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,41 +0,0 @@ -# [3.10.0](https://github.com/TogetherCrew/mongo-lib/compare/v3.9.0...v3.10.0) (2025-05-18) - - -### Features - -* add discord payloads ([466f450](https://github.com/TogetherCrew/mongo-lib/commit/466f4507bfd13d2f890cf0222dfa4c42bb9d23d6)) -* add discord payloads ([c0e4de0](https://github.com/TogetherCrew/mongo-lib/commit/c0e4de05e7f7afcf278b05793df313a9aae7f79e)) - -# [3.9.0](https://github.com/TogetherCrew/mongo-lib/compare/v3.8.0...v3.9.0) (2025-05-07) - - -### Features - -* add services ([804a4b8](https://github.com/TogetherCrew/mongo-lib/commit/804a4b8c712c2f928f6ce81373d7a551f5bac21e)) - -# [3.8.0](https://github.com/TogetherCrew/mongo-lib/compare/v3.7.1...v3.8.0) (2025-05-07) - - -### Features - -* create seperate db folder ([ac06522](https://github.com/TogetherCrew/mongo-lib/commit/ac065227feb0de095ccc2b3655469bc3a0c27d01)) - -## [3.7.1](https://github.com/TogetherCrew/mongo-lib/compare/v3.7.0...v3.7.1) (2025-05-07) - - -### Bug Fixes - -* create seperate db folder ([dc60831](https://github.com/TogetherCrew/mongo-lib/commit/dc608319a118a5d1631a28d3b48e709f602be836)) -* export files ([c0b6a2d](https://github.com/TogetherCrew/mongo-lib/commit/c0b6a2d3052ace1aabf63273e269faf75f534e8d)) - -# [3.7.0](https://github.com/TogetherCrew/mongo-lib/compare/v3.6.0...v3.7.0) (2025-05-07) - - -### Bug Fixes - -* remove changelog ([0db838e](https://github.com/TogetherCrew/mongo-lib/commit/0db838e99caaa9abbaa1ccc069d9093d5b3ae165)) - - -### Features - -* add connetion support for repos ([36ce42d](https://github.com/TogetherCrew/mongo-lib/commit/36ce42dd89fe3a8a305999580cb4adf23c6365c1)) diff --git a/src/repositories/base.repository.ts b/src/repositories/base.repository.ts index c81a2bb..ca41253 100644 --- a/src/repositories/base.repository.ts +++ b/src/repositories/base.repository.ts @@ -1,12 +1,12 @@ import { - type FilterQuery, - type HydratedDocument, - type LeanDocument, - type Model, - type PopulateOptions, - type ProjectionType, - type QueryOptions, - type UpdateQuery, + FilterQuery, + HydratedDocument, + LeanDocument, + Model, + PopulateOptions, + ProjectionType, + QueryOptions, + UpdateQuery, } from 'mongoose'; export interface PaginateOptions { @@ -63,6 +63,13 @@ export class BaseRepository { return await this.model.updateOne(filter, update, options); } + async upsert(filter: FilterQuery, update: UpdateQuery, options?: QueryOptions): Promise { + return await this.model.updateOne(filter, update, { + ...options, + upsert: true, + }); + } + async deleteOne(filter: FilterQuery): Promise { return await this.model.deleteOne(filter); }