Merge pull request 'feature/#22-API-Tokens' (#49) from feature/#22-API-Tokens into develop
Reviewed-on: #49
This commit is contained in:
commit
bbfdc69049
28 changed files with 886 additions and 9 deletions
24
src/service/user/webapiPermissionService.ts
Normal file
24
src/service/user/webapiPermissionService.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import { dataSource } from "../../data-source";
|
||||
import { webapiPermission } from "../../entity/user/webapi_permission";
|
||||
import InternalException from "../../exceptions/internalException";
|
||||
|
||||
export default abstract class WebapiPermissionService {
|
||||
/**
|
||||
* @description get permission by api
|
||||
* @param webapiId number
|
||||
* @returns {Promise<Array<webapiPermission>>}
|
||||
*/
|
||||
static async getByApi(webapiId: number): Promise<Array<webapiPermission>> {
|
||||
return await dataSource
|
||||
.getRepository(webapiPermission)
|
||||
.createQueryBuilder("webapi_permission")
|
||||
.where("webapi_permission.webapiId = :webapiId", { webapiId: webapiId })
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("webapi permissions not found by api", err);
|
||||
});
|
||||
}
|
||||
}
|
83
src/service/user/webapiService.ts
Normal file
83
src/service/user/webapiService.ts
Normal file
|
@ -0,0 +1,83 @@
|
|||
import { dataSource } from "../../data-source";
|
||||
import { webapi } from "../../entity/user/webapi";
|
||||
import InternalException from "../../exceptions/internalException";
|
||||
|
||||
export default abstract class WebapiService {
|
||||
/**
|
||||
* @description get apis
|
||||
* @returns {Promise<Array<webapi>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<webapi>> {
|
||||
return await dataSource
|
||||
.getRepository(webapi)
|
||||
.createQueryBuilder("webapi")
|
||||
.leftJoinAndSelect("webapi.permissions", "permissions")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("webapis not found", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get api by id
|
||||
* @param id number
|
||||
* @returns {Promise<webapi>}
|
||||
*/
|
||||
static async getById(id: number): Promise<webapi> {
|
||||
return await dataSource
|
||||
.getRepository(webapi)
|
||||
.createQueryBuilder("webapi")
|
||||
.leftJoinAndSelect("webapi.permissions", "permissions")
|
||||
.where("webapi.id = :id", { id: id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("webapi not found by id", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get api by token
|
||||
* @param token string
|
||||
* @returns {Promise<webapi>}
|
||||
*/
|
||||
static async getByToken(token: string): Promise<webapi> {
|
||||
return await dataSource
|
||||
.getRepository(webapi)
|
||||
.createQueryBuilder("webapi")
|
||||
.leftJoinAndSelect("webapi.permissions", "permissions")
|
||||
.where("webapi.token = :token", { token: token })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("webapi not found by token", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get api by id
|
||||
* @param id number
|
||||
* @returns {Promise<webapi>}
|
||||
*/
|
||||
static async getTokenById(id: number): Promise<webapi> {
|
||||
return await dataSource
|
||||
.getRepository(webapi)
|
||||
.createQueryBuilder("webapi")
|
||||
.select("webapi.token")
|
||||
.where("webapi.id = :id", { id: id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("webapi token not found by id", err);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue