44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { dataSource } from "../../../data-source";
|
|
import { protocol } from "../../../entity/club/protocol/protocol";
|
|
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
|
import InternalException from "../../../exceptions/internalException";
|
|
|
|
export default abstract class ProtocolService {
|
|
/**
|
|
* @description get all protocols
|
|
* @returns {Promise<[Array<protocol>, number]>}
|
|
*/
|
|
static async getAll(offset: number = 0, count: number = 25): Promise<[Array<protocol>, number]> {
|
|
return await dataSource
|
|
.getRepository(protocol)
|
|
.createQueryBuilder("protocol")
|
|
.offset(offset)
|
|
.limit(count)
|
|
.orderBy("date", "DESC")
|
|
.getManyAndCount()
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("SELECT", "protocol", err);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @description get protocol by id
|
|
* @returns {Promise<protocol>}
|
|
*/
|
|
static async getById(id: number): Promise<protocol> {
|
|
return await dataSource
|
|
.getRepository(protocol)
|
|
.createQueryBuilder("protocol")
|
|
.where("protocol.id = :id", { id: id })
|
|
.getOneOrFail()
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch((err) => {
|
|
throw new InternalException("protocol not found by id", err);
|
|
});
|
|
}
|
|
}
|