Skip to content

Commit 647ec7a

Browse files
Merge pull request #209 from TogetherCrew/add-functions-to-base-repo
feat: add upsert repo
2 parents 67b56dc + a20f695 commit 647ec7a

File tree

2 files changed

+15
-49
lines changed

2 files changed

+15
-49
lines changed

CHANGELOG.md

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/repositories/base.repository.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {
2-
type FilterQuery,
3-
type HydratedDocument,
4-
type LeanDocument,
5-
type Model,
6-
type PopulateOptions,
7-
type ProjectionType,
8-
type QueryOptions,
9-
type UpdateQuery,
2+
FilterQuery,
3+
HydratedDocument,
4+
LeanDocument,
5+
Model,
6+
PopulateOptions,
7+
ProjectionType,
8+
QueryOptions,
9+
UpdateQuery,
1010
} from 'mongoose';
1111

1212
export interface PaginateOptions {
@@ -63,6 +63,13 @@ export class BaseRepository<T> {
6363
return await this.model.updateOne(filter, update, options);
6464
}
6565

66+
async upsert(filter: FilterQuery<T>, update: UpdateQuery<T>, options?: QueryOptions): Promise<any> {
67+
return await this.model.updateOne(filter, update, {
68+
...options,
69+
upsert: true,
70+
});
71+
}
72+
6673
async deleteOne(filter: FilterQuery<T>): Promise<any> {
6774
return await this.model.deleteOne(filter);
6875
}

0 commit comments

Comments
 (0)