printout
This commit is contained in:
parent
58213923e5
commit
9da2a98f55
12 changed files with 341 additions and 54 deletions
60
src/service/protocolPrintoutService.ts
Normal file
60
src/service/protocolPrintoutService.ts
Normal file
|
@ -0,0 +1,60 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { protocolPrintout } from "../entity/protocolPrintout";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
|
||||
export default abstract class ProtocolPrintoutService {
|
||||
/**
|
||||
* @description get all protocolPrintouts
|
||||
* @returns {Promise<Array<protocolPrintout>>}
|
||||
*/
|
||||
static async getAll(protocolId: number): Promise<Array<protocolPrintout>> {
|
||||
return await dataSource
|
||||
.getRepository(protocolPrintout)
|
||||
.createQueryBuilder("protocolPrintout")
|
||||
.where("protocolPrintout.protocolId = :protocolId", { protocolId })
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("protocolPrintouts not found", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get protocolPrintout by id
|
||||
* @returns {Promise<protocolPrintout>}
|
||||
*/
|
||||
static async getById(id: number, protocolId: number): Promise<protocolPrintout> {
|
||||
return await dataSource
|
||||
.getRepository(protocolPrintout)
|
||||
.createQueryBuilder("protocolPrintout")
|
||||
.where("protocolPrintout.protocolId = :protocolId", { protocolId })
|
||||
.andWhere("protocolPrintout.id = :id", { id: id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("protocolPrintout not found by id", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get count of printouts by id
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async getCount(protocolId: number): Promise<number> {
|
||||
return await dataSource
|
||||
.getRepository(protocolPrintout)
|
||||
.createQueryBuilder("protocolPrintout")
|
||||
.where("protocolPrintout.protocolId = :protocolId", { protocolId })
|
||||
.getCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("protocolPrintout not found by id", err);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue