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