ff-admin-server/src/service/membershipService.ts

47 lines
1.5 KiB
TypeScript

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<Array<membership>>}
*/
static async getAll(memberId: number): Promise<Array<membership>> {
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<Array<member>>}
*/
static async getById(memberId: number, recordId: number): Promise<membership> {
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);
});
}
}