get protocol item

This commit is contained in:
Julian Krauser 2024-10-03 13:31:05 +02:00
parent 72fb6fbc20
commit 5c4e521bd8
10 changed files with 155 additions and 3 deletions

View file

@ -0,0 +1,43 @@
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")
.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);
});
}
}