ff-admin-server/src/service/settings/queryStoreService.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-01-05 14:14:00 +01:00
import { dataSource } from "../../data-source";
import { query } from "../../entity/settings/query";
2025-01-29 09:42:22 +01:00
import DatabaseActionException from "../../exceptions/databaseActionException";
2025-01-05 14:14:00 +01:00
import InternalException from "../../exceptions/internalException";
2024-12-14 16:11:53 +01:00
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")
2025-01-12 18:17:54 +01:00
.orderBy("title", "ASC")
2024-12-14 16:11:53 +01:00
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
2025-01-29 09:42:22 +01:00
throw new DatabaseActionException("SELECT", "queryStore", err);
2024-12-14 16:11:53 +01:00
});
}
/**
* @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) => {
2025-01-29 09:42:22 +01:00
throw new DatabaseActionException("SELECT", "queryStore", err);
2024-12-14 16:11:53 +01:00
});
}
}