login and authentication
login via totp authentication via access and refresh tokens
This commit is contained in:
parent
6696975bee
commit
e1ec65350d
28 changed files with 3750 additions and 0 deletions
44
src/service/userService.ts
Normal file
44
src/service/userService.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { user } from "../entity/user";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
|
||||
export default abstract class UserService {
|
||||
/**
|
||||
* @description get user by id
|
||||
* @param id number
|
||||
* @returns {Promise<user>}
|
||||
*/
|
||||
static async getById(id: number): Promise<user> {
|
||||
return await dataSource
|
||||
.getRepository(user)
|
||||
.createQueryBuilder("user")
|
||||
.where("user.id = :id", { id: id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("user not found by id");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get user by username
|
||||
* @param username string
|
||||
* @returns {Promise<user>}
|
||||
*/
|
||||
static async getByUsername(username: string): Promise<user> {
|
||||
return await dataSource
|
||||
.getRepository(user)
|
||||
.createQueryBuilder("user")
|
||||
.select()
|
||||
.where("user.username = :username", { username: username })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("user not found by username");
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue