Skip to content

Commit

Permalink
refactor: pr suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
nunocaseiro committed Dec 7, 2022
1 parent 5953d33 commit 3d7e324
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions backend/src/libs/repositories/mongo/mongo-generic.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ClientSession, Model, PopulateOptions, UpdateQuery } from 'mongoose';
import { BaseInterfaceRepository } from '../interfaces/base.repository.interface';
import { ModelProps, SelectedValues } from '../types';

type PopulateType = PopulateOptions | (PopulateOptions | string)[];

export class MongoGenericRepository<T> implements BaseInterfaceRepository<T> {
protected _repository: Model<T>;
protected _session: ClientSession;
Expand All @@ -14,14 +16,11 @@ export class MongoGenericRepository<T> implements BaseInterfaceRepository<T> {
return this._repository.countDocuments().lean().exec();
}

findAll(
selectedValues?: SelectedValues<T>,
populate?: PopulateOptions | (PopulateOptions | string)[]
): Promise<T[]> {
findAll(selectedValues?: SelectedValues<T>, populate?: PopulateType): Promise<T[]> {
return this._repository.find().select(selectedValues).populate(populate).exec();
}

findOneById(id: any, selectedValues?: SelectedValues<T>, populate?: any): Promise<T> {
findOneById(id: any, selectedValues?: SelectedValues<T>, populate?: PopulateType): Promise<T> {
return this._repository
.findById(id)
.select(selectedValues)
Expand All @@ -33,7 +32,11 @@ export class MongoGenericRepository<T> implements BaseInterfaceRepository<T> {
return this._repository.findOne(value).exec();
}

findAllWithQuery(query: any, selectedValues?: SelectedValues<T>, populate?: any): Promise<T[]> {
findAllWithQuery(
query: any,
selectedValues?: SelectedValues<T>,
populate?: PopulateType
): Promise<T[]> {
return this._repository
.find(query)
.select(selectedValues)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/modules/teams/services/create.team.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class CreateTeamService implements CreateTeamServiceInterface {
private readonly teamUserRepository: TeamUserRepositoryInterface
) {}

async createTeamUsers(teamUsers: TeamUserDto[], teamId: string) {
createTeamUsers(teamUsers: TeamUserDto[], teamId: string) {
return Promise.all(
teamUsers.map((user) => this.teamUserRepository.create({ ...user, team: teamId }))
);
Expand Down

0 comments on commit 3d7e324

Please sign in to comment.