41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { dataSource } from "../../../data-source";
|
|
import { inspection } from "../../../entity/unit/inspection/inspection";
|
|
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
|
|
|
export default abstract class InspectionService {
|
|
/**
|
|
* @description get all inspection types
|
|
* @returns {Promise<Array<inspection>>}
|
|
*/
|
|
static async getAll(): Promise<Array<inspection>> {
|
|
return await dataSource
|
|
.getRepository(inspection)
|
|
.createQueryBuilder("inspection")
|
|
.orderBy("type", "ASC")
|
|
.getMany()
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("SELECT", "inspection", err);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @description get inspection by id
|
|
* @returns {Promise<inspection>}
|
|
*/
|
|
static async getById(id: string): Promise<inspection> {
|
|
return await dataSource
|
|
.getRepository(inspection)
|
|
.createQueryBuilder("inspection")
|
|
.where({ id })
|
|
.getOneOrFail()
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("SELECT", "inspection", err);
|
|
});
|
|
}
|
|
}
|