2024-09-04 14:01:22 +02:00
|
|
|
import { dataSource } from "../data-source";
|
|
|
|
import { award } from "../entity/award";
|
2024-09-15 14:03:15 +02:00
|
|
|
import { member } from "../entity/member";
|
2024-09-04 14:01:22 +02:00
|
|
|
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;
|
|
|
|
})
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|