ff-admin-server/src/service/memberExecutivePositionService.ts

49 lines
1.8 KiB
TypeScript

import { dataSource } from "../data-source";
import { memberExecutivePositions } from "../entity/memberExecutivePositions";
import InternalException from "../exceptions/internalException";
export default abstract class MemberExecutivePositionService {
/**
* @description get all by member id
* @param {number} memberId
* @returns {Promise<Array<memberExecutivePositions>>}
*/
static async getAll(memberId: number): Promise<Array<memberExecutivePositions>> {
return await dataSource
.getRepository(memberExecutivePositions)
.createQueryBuilder("memberExecutivePositions")
.leftJoinAndSelect("memberExecutivePositions.executivePosition", "executivePosition")
.where("memberExecutivePositions.memberId = :memberId", { memberId: memberId })
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("member executivePositions 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<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);
});
}
}