43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { dataSource } from "../data-source";
|
|
import { protocol } from "../entity/protocol";
|
|
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 InternalException("protocols not found", 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);
|
|
});
|
|
}
|
|
}
|