41 lines
1 KiB
TypeScript
41 lines
1 KiB
TypeScript
|
import { dataSource } from "../data-source";
|
||
|
import { query } from "../entity/query";
|
||
|
import InternalException from "../exceptions/internalException";
|
||
|
|
||
|
export default abstract class QueryStoreService {
|
||
|
/**
|
||
|
* @description get all queryStores
|
||
|
* @returns {Promise<Array<query>>}
|
||
|
*/
|
||
|
static async getAll(): Promise<Array<query>> {
|
||
|
return await dataSource
|
||
|
.getRepository(query)
|
||
|
.createQueryBuilder("queryStore")
|
||
|
.getMany()
|
||
|
.then((res) => {
|
||
|
return res;
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
throw new InternalException("queryStores not found", err);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @description get queryStore by id
|
||
|
* @returns {Promise<query>}
|
||
|
*/
|
||
|
static async getById(id: number): Promise<query> {
|
||
|
return await dataSource
|
||
|
.getRepository(query)
|
||
|
.createQueryBuilder("queryStore")
|
||
|
.where("queryStore.id = :id", { id: id })
|
||
|
.getOneOrFail()
|
||
|
.then((res) => {
|
||
|
return res;
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
throw new InternalException("queryStore not found by id", err);
|
||
|
});
|
||
|
}
|
||
|
}
|