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

41 lines
1.1 KiB
TypeScript

import { dataSource } from "../data-source";
import { award } from "../entity/award";
import { member } from "../entity/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")
.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);
});
}
}