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

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-01-05 14:14:00 +01:00
import { dataSource } from "../../data-source";
import { award } from "../../entity/settings/award";
import { member } from "../../entity/club/member/member";
import InternalException from "../../exceptions/internalException";
2024-09-04 14:01:22 +02:00
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")
2025-01-12 18:17:54 +01:00
.orderBy("award", "ASC")
2024-09-04 14:01:22 +02:00
.getMany()
.then((res) => {
return res;
})
2024-09-06 10:08:19 +02:00
.catch((err) => {
throw new InternalException("awards not found", err);
2024-09-04 14:01:22 +02:00
});
}
/**
* @description get award by id
* @returns {Promise<award>}
*/
static async getById(id: number): Promise<award> {
return await dataSource
.getRepository(award)
.createQueryBuilder("award")
2024-09-15 14:03:15 +02:00
.where("award.id = :id", { id: id })
2024-09-04 14:01:22 +02:00
.getOneOrFail()
.then((res) => {
return res;
})
2024-09-06 10:08:19 +02:00
.catch((err) => {
throw new InternalException("award not found by id", err);
2024-09-04 14:01:22 +02:00
});
}
}