generated from xgeekshq/oss-template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Rui Silva <r.silva@kigroup.de>
- Loading branch information
1 parent
546c563
commit 3530417
Showing
51 changed files
with
302 additions
and
190 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
18 changes: 18 additions & 0 deletions
18
backend/src/libs/repositories/interfaces/base.repository.interface.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { UpdateQuery } from 'mongoose'; | ||
import { ModelProps, SelectedValues } from '../types'; | ||
|
||
export interface BaseInterfaceRepository<T> { | ||
getAll(selectedValues?: SelectedValues<T>): Promise<T[]>; | ||
|
||
get(id: string, selectedValues?: SelectedValues<T>): Promise<T>; | ||
|
||
create(item: T): Promise<T>; | ||
|
||
update(id: string, item: T); | ||
|
||
getByProp(value: ModelProps<T>): Promise<T>; | ||
|
||
countDocuments(): Promise<number>; | ||
|
||
findOneByFieldAndUpdate(value: ModelProps<T>, query: UpdateQuery<T>): Promise<T>; | ||
} |
45 changes: 45 additions & 0 deletions
45
backend/src/libs/repositories/mongo/mongo-generic.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Model, UpdateQuery } from 'mongoose'; | ||
import { BaseInterfaceRepository } from '../interfaces/base.repository.interface'; | ||
import { ModelProps, SelectedValues } from '../types'; | ||
|
||
export class MongoGenericRepository<T> implements BaseInterfaceRepository<T> { | ||
private _repository: Model<T>; | ||
private _populateOnFind: string[]; | ||
|
||
constructor(repository: Model<T>, populateOnFind: string[] = []) { | ||
this._repository = repository; | ||
this._populateOnFind = populateOnFind; | ||
} | ||
|
||
getAll(selectedValues?: SelectedValues<T>): Promise<T[]> { | ||
return this._repository.find().select(selectedValues).populate(this._populateOnFind).exec(); | ||
} | ||
|
||
get(id: any, selectedValues?: SelectedValues<T>): Promise<T> { | ||
return this._repository | ||
.findById(id) | ||
.select(selectedValues) | ||
.populate(this._populateOnFind) | ||
.exec() as Promise<T>; | ||
} | ||
|
||
getByProp(value: ModelProps<T>): Promise<T> { | ||
return this._repository.findOne(value).exec(); | ||
} | ||
|
||
create(item: T): Promise<T> { | ||
return this._repository.create(item); | ||
} | ||
|
||
update(id: string, item: T) { | ||
return this._repository.findByIdAndUpdate(id, item); | ||
} | ||
|
||
countDocuments(): Promise<number> { | ||
return this._repository.countDocuments().exec(); | ||
} | ||
|
||
findOneByFieldAndUpdate(value: ModelProps<T>, query: UpdateQuery<T>): Promise<T> { | ||
return this._repository.findOneAndUpdate(value, query).exec(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type SelectedValues<T> = | ||
| string // maintain compatibility with existing code | ||
| { | ||
[K in keyof T]?: 1 | 0; | ||
}; | ||
|
||
export type ModelProps<T> = { | ||
[K in keyof T]?: T[K]; | ||
}; |
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
5 changes: 2 additions & 3 deletions
5
backend/src/modules/auth/interfaces/applications/register.auth.application.interface.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,7 +1,6 @@ | ||
import { LeanDocument } from 'mongoose'; | ||
import CreateUserDto from 'src/modules/users/dto/create.user.dto'; | ||
import { UserDocument } from 'src/modules/users/schemas/user.schema'; | ||
import User from 'src/modules/users/entities/user.schema'; | ||
|
||
export interface RegisterAuthApplication { | ||
register(registrationData: CreateUserDto): Promise<LeanDocument<UserDocument>>; | ||
register(registrationData: CreateUserDto): Promise<User>; | ||
} |
5 changes: 2 additions & 3 deletions
5
backend/src/modules/auth/interfaces/services/register.auth.service.interface.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,7 +1,6 @@ | ||
import { LeanDocument } from 'mongoose'; | ||
import CreateUserDto from 'src/modules/users/dto/create.user.dto'; | ||
import { UserDocument } from 'src/modules/users/schemas/user.schema'; | ||
import User from 'src/modules/users/entities/user.schema'; | ||
|
||
export interface RegisterAuthService { | ||
register(registrationData: CreateUserDto): Promise<LeanDocument<UserDocument>>; | ||
register(registrationData: CreateUserDto): Promise<User>; | ||
} |
15 changes: 4 additions & 11 deletions
15
backend/src/modules/auth/interfaces/services/validate-user.auth.service.interface.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,9 @@ | ||
import { LeanDocument } from 'mongoose'; | ||
import { UserDocument } from 'src/modules/users/schemas/user.schema'; | ||
import User from 'src/modules/users/entities/user.schema'; | ||
|
||
export interface ValidateUserAuthService { | ||
validateUserWithCredentials( | ||
email: string, | ||
plainTextPassword: string | ||
): Promise<LeanDocument<UserDocument> | null>; | ||
validateUserWithCredentials(email: string, plainTextPassword: string): Promise<User | null>; | ||
|
||
validateUserById(userId: string): Promise<LeanDocument<UserDocument> | null>; | ||
validateUserById(userId: string): Promise<User | null>; | ||
|
||
validateUserByRefreshToken( | ||
authorization: string, | ||
userId: string | ||
): Promise<false | LeanDocument<UserDocument>>; | ||
validateUserByRefreshToken(authorization: string, userId: string): Promise<false | User>; | ||
} |
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
Oops, something went wrong.