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

61 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-09-04 14:01:22 +02:00
import { dataSource } from "../data-source";
import { award } from "../entity/award";
import { user } from "../entity/user";
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(() => {
throw new InternalException("awards not found");
});
}
/**
* @description get award by id
* @returns {Promise<award>}
*/
static async getById(id: number): Promise<award> {
return await dataSource
.getRepository(award)
.createQueryBuilder("award")
.andWhere("award.id = :id", { id: id })
.getOneOrFail()
.then((res) => {
return res;
})
.catch(() => {
throw new InternalException("award not found by id");
});
}
// /**
// * @description get members assigned to award
// * @returns {Promise<Array<member>>}
// */
// static async getMembersByAwardId(id: number): Promise<Array<member>> {
// return await dataSource
// .getRepository(award)
// .createQueryBuilder("award")
// .leftJoinAndSelect("award.members", "members")
// .andWhere("award.id = :id", { id: id })
// .getOneOrFail()
// .then((res) => {
// return [];
// })
// .catch(() => {
// throw new InternalException("award assigned members not found by id");
// });
// }
}