import { dataSource } from "../../data-source"; import { mission } from "../../entity/operation/mission"; import DatabaseActionException from "../../exceptions/databaseActionException"; export default abstract class MissionService { /** * @description get all missions * @returns {Promise<[Array, number]>} */ static async getAll({ offset = 0, count = 25, noLimit = false, }: { offset?: number; count?: number; noLimit?: boolean; }): Promise<[Array, number]> { let query = dataSource.getRepository(mission).createQueryBuilder("mission"); if (!noLimit) { query = query.offset(offset).limit(count); } return await query .orderBy("mission.createdAt") .getManyAndCount() .then((res) => { return res; }) .catch((err) => { throw new DatabaseActionException("SELECT", "mission", err); }); } /** * @description get mission by id * @param {string} id * @returns {Promise} */ static async getById(id: string): Promise { return dataSource .getRepository(mission) .createQueryBuilder("mission") .where("mission.id = :id", { id: id }) .getOneOrFail() .then((res) => { return res; }) .catch((err) => { throw new DatabaseActionException("SELECT", "mission", err); }); } }