folder structure
This commit is contained in:
parent
5d3f8ea46a
commit
84e2ec72ac
242 changed files with 635 additions and 635 deletions
43
src/service/club/protocol/protocolService.ts
Normal file
43
src/service/club/protocol/protocolService.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { dataSource } from "../../../data-source";
|
||||
import { protocol } from "../../../entity/club/protocol/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);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue