42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { dataSource } from "../../data-source";
|
|
import { query } from "../../entity/configuration/query";
|
|
import DatabaseActionException from "../../exceptions/databaseActionException";
|
|
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")
|
|
.orderBy("title", "ASC")
|
|
.getMany()
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("SELECT", "queryStore", 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 DatabaseActionException("SELECT", "queryStore", err);
|
|
});
|
|
}
|
|
}
|