49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
import { dataSource } from "../../../data-source";
|
|
import { memberEducations } from "../../../entity/club/member/memberEducations";
|
|
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
|
import InternalException from "../../../exceptions/internalException";
|
|
|
|
export default abstract class MemberEducationService {
|
|
/**
|
|
* @description get all by member id
|
|
* @param {string} memberId
|
|
* @returns {Promise<Array<memberEducations>>}
|
|
*/
|
|
static async getAll(memberId: string): Promise<Array<memberEducations>> {
|
|
return await dataSource
|
|
.getRepository(memberEducations)
|
|
.createQueryBuilder("memberEducations")
|
|
.leftJoinAndSelect("memberEducations.education", "education")
|
|
.where("memberEducations.memberId = :memberId", { memberId: memberId })
|
|
.orderBy("education.education", "ASC")
|
|
.getMany()
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("SELECT", "memberEducations", err);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @description get by memberId and recordId
|
|
* @param {string} memberId
|
|
* @param {number} recordId
|
|
* @returns {Promise<Array<member>>}
|
|
*/
|
|
static async getById(memberId: string, recordId: number): Promise<memberEducations> {
|
|
return await dataSource
|
|
.getRepository(memberEducations)
|
|
.createQueryBuilder("memberEducations")
|
|
.leftJoinAndSelect("memberEducations.education", "education")
|
|
.where("memberEducations.memberId = :memberId", { memberId: memberId })
|
|
.andWhere("memberEducations.id = :recordId", { recordId: recordId })
|
|
.getOneOrFail()
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("SELECT", "memberEducations", err);
|
|
});
|
|
}
|
|
}
|