controller
This commit is contained in:
parent
9f2a08ccc9
commit
2609ecc1bf
17 changed files with 320 additions and 95 deletions
|
@ -1,3 +1,4 @@
|
|||
import { In, Like } from "typeorm";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { equipment } from "../../../entity/unit/equipment/equipment";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
@ -5,15 +6,45 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
export default abstract class EquipmentService {
|
||||
/**
|
||||
* @description get all equipment
|
||||
* @returns {Promise<Array<equipment>>}
|
||||
* @returns {Promise<[Array<equipment>, number]>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<equipment>> {
|
||||
return await dataSource
|
||||
static async getAll({
|
||||
offset = 0,
|
||||
count = 25,
|
||||
search = "",
|
||||
noLimit = false,
|
||||
ids = [],
|
||||
}: {
|
||||
offset?: number;
|
||||
count?: number;
|
||||
search?: string;
|
||||
noLimit?: boolean;
|
||||
ids?: Array<string>;
|
||||
}): Promise<[Array<equipment>, number]> {
|
||||
let query = dataSource
|
||||
.getRepository(equipment)
|
||||
.createQueryBuilder("equipment")
|
||||
.leftJoinAndSelect("equipment.equipmentType", "equipmenttype")
|
||||
.leftJoinAndSelect("equipment.equipmentType", "equipmenttype");
|
||||
|
||||
if (search != "") {
|
||||
query = query.where({
|
||||
code: Like(search),
|
||||
name: Like(search),
|
||||
location: Like(search),
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.length != 0) {
|
||||
query = query.where({ id: In(ids) });
|
||||
}
|
||||
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
||||
return await query
|
||||
.orderBy("name", "ASC")
|
||||
.getMany()
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue