import { dataSource } from "../data-source"; import { memberExecutivePositions } from "../entity/memberExecutivePositions"; import InternalException from "../exceptions/internalException"; export default abstract class MemberExecutivePositionService { /** * @description get all by member id * @param {number} memberId * @returns {Promise>} */ static async getAll(memberId: number): Promise> { return await dataSource .getRepository(memberExecutivePositions) .createQueryBuilder("memberExecutivePositions") .leftJoinAndSelect("memberExecutivePositions.executivePosition", "executivePosition") .where("memberExecutivePositions.memberId = :memberId", { memberId: memberId }) .getMany() .then((res) => { return res; }) .catch((err) => { throw new InternalException("member executivePositions not found", err); }); } /** * @description get by memberId and recordId * @param {number} memberId * @param {number} recordId * @returns {Promise>} */ static async getById(memberId: number, recordId: number): Promise { return await dataSource .getRepository(memberExecutivePositions) .createQueryBuilder("memberExecutivePositions") .leftJoinAndSelect("memberExecutivePositions.executivePosition", "executivePosition") .where("memberExecutivePositions.memberId = :memberId", { memberId: memberId }) .andWhere("memberExecutivePositions.id = :recordId", { recordId: recordId, }) .getOneOrFail() .then((res) => { return res; }) .catch((err) => { throw new InternalException("member executivePosition not found by id", err); }); } }