setup and invite
This commit is contained in:
parent
03e0f90279
commit
7df7cf2697
23 changed files with 515 additions and 43 deletions
26
src/service/inviteService.ts
Normal file
26
src/service/inviteService.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { invite } from "../entity/invite";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
|
||||
export default abstract class InviteService {
|
||||
/**
|
||||
* @description get invite by id
|
||||
* @param mail string
|
||||
* @param token string
|
||||
* @returns {Promise<invite>}
|
||||
*/
|
||||
static async getByMailAndToken(mail: string, token: string): Promise<invite> {
|
||||
return await dataSource
|
||||
.getRepository(invite)
|
||||
.createQueryBuilder("invite")
|
||||
.where("invite.mail = :mail", { mail: mail })
|
||||
.andWhere("invite.token = :token", { token: token })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("invite not found by mail and token");
|
||||
});
|
||||
}
|
||||
}
|
|
@ -41,4 +41,44 @@ export default abstract class UserService {
|
|||
throw new InternalException("user not found by username");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get users by mail or username
|
||||
* @param username string
|
||||
* @param mail string
|
||||
* @returns {Promise<Array<user>>}
|
||||
*/
|
||||
static async getByMailOrUsername(mail?: string, username?: string): Promise<Array<user>> {
|
||||
return await dataSource
|
||||
.getRepository(user)
|
||||
.createQueryBuilder("user")
|
||||
.select()
|
||||
.where("user.mail = :mail", { mail: mail })
|
||||
.orWhere("user.username = :username", { username: username })
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("user not found by mail or username");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get count of users
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async count(): Promise<number> {
|
||||
return await dataSource
|
||||
.getRepository(user)
|
||||
.createQueryBuilder("user")
|
||||
.select()
|
||||
.getCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("could not count users");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue