48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
import { dataSource } from "../../../data-source";
|
|
import { memberQualifications } from "../../../entity/club/member/memberQualifications";
|
|
import InternalException from "../../../exceptions/internalException";
|
|
|
|
export default abstract class MemberQualificationService {
|
|
/**
|
|
* @description get all by member id
|
|
* @param {number} memberId
|
|
* @returns {Promise<Array<memberQualifications>>}
|
|
*/
|
|
static async getAll(memberId: number): Promise<Array<memberQualifications>> {
|
|
return await dataSource
|
|
.getRepository(memberQualifications)
|
|
.createQueryBuilder("memberQualifications")
|
|
.leftJoinAndSelect("memberQualifications.qualification", "qualification")
|
|
.where("memberQualifications.memberId = :memberId", { memberId: memberId })
|
|
.orderBy("qualification.qualification", "ASC")
|
|
.getMany()
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch((err) => {
|
|
throw new InternalException("member qualifications 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<memberQualifications> {
|
|
return await dataSource
|
|
.getRepository(memberQualifications)
|
|
.createQueryBuilder("memberQualifications")
|
|
.leftJoinAndSelect("memberQualifications.qualification", "qualification")
|
|
.where("memberQualifications.memberId = :memberId", { memberId: memberId })
|
|
.andWhere("memberQualifications.id = :recordId", { recordId: recordId })
|
|
.getOneOrFail()
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch((err) => {
|
|
throw new InternalException("member qualification not found by id", err);
|
|
});
|
|
}
|
|
}
|