import { dataSource } from "../data-source"; import { membership } from "../entity/membership"; import InternalException from "../exceptions/internalException"; export default abstract class MembershipService { /** * @description get all by member id * @param {number} memberId * @returns {Promise>} */ static async getAll(memberId: number): Promise> { return await dataSource .getRepository(membership) .createQueryBuilder("membership") .leftJoinAndSelect("membership.status", "membershipStatus") .where("membership.memberId = :memberId", { memberId: memberId }) .getMany() .then((res) => { return res; }) .catch((err) => { throw new InternalException("member memberships 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(membership) .createQueryBuilder("membership") .leftJoinAndSelect("membership.status", "membershipStatus") .where("membership.memberId = :memberId", { memberId: memberId }) .andWhere("membership.id = :recordId", { recordId: recordId }) .getOneOrFail() .then((res) => { return res; }) .catch((err) => { throw new InternalException("member membership not found by id", err); }); } }