-
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.
fix: adjusting some import and methods call
- Loading branch information
Showing
12 changed files
with
80 additions
and
48 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export enum RoutesEnum { | ||
SIGN_IN = '/signin', | ||
SIGN_UP = '/signup', | ||
USERS = '/users', | ||
USERS = '/users/:id', | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
export interface IHttpRequest { | ||
headers?: unknown; | ||
params?: unknown; | ||
headers?: { | ||
authorization?: string; | ||
[key: string]: unknown; | ||
}; | ||
params?: { | ||
id?: string; | ||
[key: string]: unknown; | ||
}; | ||
body: unknown; | ||
} |
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,7 @@ | ||
export interface IRepository<T> { | ||
create(model: T): Promise<T>; | ||
delete?(model: T): Promise<T>; | ||
update(property: Partial<T>): Promise<T>; | ||
findOne(property: Partial<T>): Promise<T>; | ||
update(property: Partial<T>, model: Partial<T>): Promise<T>; | ||
findOne(property: Partial<T>): Promise<T | undefined>; | ||
findAll?(property: Partial<T>): Promise<T[]>; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,52 @@ | ||
import { DatabaseError } from '../../util/errors/DatabaseError'; | ||
import { IRepository } from '../IRepository'; | ||
import { IRepositoryModel } from '../repositoryModel/IRepositoryModel'; | ||
import { IUser } from '../../models/user/IUser'; | ||
|
||
import httpStatus from 'http-status-codes'; | ||
export class UserRepository implements IRepository<IUser> { | ||
constructor(private readonly UserRepositoryModel: IRepositoryModel<IUser>) {} | ||
|
||
public async create(model: IUser): Promise<IUser> { | ||
const user = await this.UserRepositoryModel.save(model); | ||
return user; | ||
} | ||
|
||
public async update(user: Partial<IUser>): Promise<IUser> { | ||
const result = await this.UserRepositoryModel.updateOne( | ||
{ email: user.email }, | ||
{ ...user } | ||
); | ||
public async create(user: IUser): Promise<IUser> { | ||
const result = await this.UserRepositoryModel.save(user); | ||
|
||
if (!result) { | ||
throw new Error(''); | ||
throw new DatabaseError( | ||
`Could not save user ${user.email} in database`, | ||
httpStatus.BAD_REQUEST | ||
); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public async findOne(user: Partial<IUser>): Promise<IUser> { | ||
const result = await this.UserRepositoryModel.findOne({ | ||
email: user.email, | ||
}); | ||
public async update( | ||
property: Partial<IUser>, | ||
user: Partial<IUser> | ||
): Promise<IUser> { | ||
const result = await this.UserRepositoryModel.updateOne(property, user); | ||
|
||
if (!result) { | ||
throw new Error(''); | ||
throw new DatabaseError( | ||
`User ${user.email} not found in database`, | ||
httpStatus.BAD_REQUEST | ||
); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public async findOne(user: Partial<IUser>): Promise<IUser | undefined> { | ||
return await this.UserRepositoryModel.findOne(user); | ||
} | ||
|
||
public async deleteAll(): Promise<void> { | ||
await this.UserRepositoryModel.deleteAll(); | ||
} | ||
|
||
public async findOneByIdAndToken( | ||
userId: string, | ||
token: string | ||
): Promise<IUser | undefined> { | ||
return this.UserRepositoryModel.findOneByIdAndToken(userId, token); | ||
} | ||
} |
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