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