-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ♻️ MongooseUserRepository to MongooseUsersRepository
- Loading branch information
1 parent
b37adaa
commit c725fce
Showing
2 changed files
with
14 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 9 additions & 3 deletions
12
...goose/src/lib/mongoose-user.repository.ts → ...oose/src/lib/mongoose-users.repository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { User, UserRepository } from '@users/domain'; | ||
import { User, UsersRepository } from '@users/domain'; | ||
import { Model } from 'mongoose'; | ||
|
||
import { UserDocument } from './user.schema'; | ||
|
||
export class MongooseUserRepository implements UserRepository { | ||
@Injectable() | ||
export class MongooseUsersRepository implements UsersRepository { | ||
constructor( | ||
@InjectModel(UserDocument.name) private userModel: Model<UserDocument>, | ||
) {} | ||
|
||
async findById(id: string): Promise<User | null> { | ||
const userDoc = await this.userModel.findById(id).exec(); | ||
return userDoc ? new User(userDoc.id, userDoc.name) : null; | ||
|
||
if (!userDoc) { | ||
return null; | ||
} | ||
return new User(userDoc.id, userDoc.name); | ||
} | ||
} |