42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { dataSource } from "../../data-source";
|
|
import { award } from "../../entity/settings/award";
|
|
import { member } from "../../entity/club/member/member";
|
|
import InternalException from "../../exceptions/internalException";
|
|
|
|
export default abstract class AwardService {
|
|
/**
|
|
* @description get all awards
|
|
* @returns {Promise<Array<award>>}
|
|
*/
|
|
static async getAll(): Promise<Array<award>> {
|
|
return await dataSource
|
|
.getRepository(award)
|
|
.createQueryBuilder("award")
|
|
.orderBy("award", "ASC")
|
|
.getMany()
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch((err) => {
|
|
throw new InternalException("awards not found", err);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @description get award by id
|
|
* @returns {Promise<award>}
|
|
*/
|
|
static async getById(id: number): Promise<award> {
|
|
return await dataSource
|
|
.getRepository(award)
|
|
.createQueryBuilder("award")
|
|
.where("award.id = :id", { id: id })
|
|
.getOneOrFail()
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch((err) => {
|
|
throw new InternalException("award not found by id", err);
|
|
});
|
|
}
|
|
}
|