48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
|
import { dataSource } from "../data-source";
|
||
|
import { memberQualifications } from "../entity/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 })
|
||
|
.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);
|
||
|
});
|
||
|
}
|
||
|
}
|