2024-09-16 13:55:41 +00:00
|
|
|
import { dataSource } from "../data-source";
|
|
|
|
import { membership } from "../entity/membership";
|
|
|
|
import InternalException from "../exceptions/internalException";
|
|
|
|
|
2024-09-16 14:00:05 +00:00
|
|
|
export default abstract class MembershipService {
|
2024-09-16 13:55:41 +00:00
|
|
|
/**
|
|
|
|
* @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")
|
2024-09-17 14:44:39 +00:00
|
|
|
.leftJoinAndSelect("membership.status", "membershipStatus")
|
2024-09-16 13:55:41 +00:00
|
|
|
.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")
|
2024-09-17 14:44:39 +00:00
|
|
|
.leftJoinAndSelect("membership.status", "membershipStatus")
|
2024-09-16 13:55:41 +00:00
|
|
|
.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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|