Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intellisense through partials #3

Open
wants to merge 1 commit into
base: abstract-repository
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/database/entity.repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Document, FilterQuery, Model, ModelUpdateOptions, QueryOptions, UpdateQuery } from 'mongoose';
import { Document, FilterQuery, Model, UpdateQuery } from 'mongoose';

export abstract class EntityRepository<T extends Document> {
export abstract class EntityRepository<T extends Document, D> {
constructor(protected readonly entityModel: Model<T>) {}

async findOne(
Expand All @@ -20,14 +20,14 @@ export abstract class EntityRepository<T extends Document> {
return this.entityModel.find(entityFilterQuery);
}

async create(createEntityData: unknown): Promise<T> {
async create(createEntityData: Partial<D>): Promise<T> {
const entity = new this.entityModel(createEntityData);
return entity.save()
}

async findOneAndUpdate(
entityFilterQuery: FilterQuery<T>,
updateEntityData: UpdateQuery<unknown>
updateEntityData: UpdateQuery<Partial<D>>
): Promise<T | null> {
return this.entityModel.findOneAndUpdate(
entityFilterQuery,
Expand Down