controller

This commit is contained in:
Julian Krauser 2025-06-02 13:14:09 +02:00
parent 9f2a08ccc9
commit 2609ecc1bf
17 changed files with 320 additions and 95 deletions

View file

@ -1,3 +1,4 @@
import { Like, In } from "typeorm";
import { dataSource } from "../../../data-source";
import { vehicle } from "../../../entity/unit/vehicle/vehicle";
import DatabaseActionException from "../../../exceptions/databaseActionException";
@ -5,15 +6,45 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
export default abstract class VehicleService {
/**
* @description get all vehicles
* @returns {Promise<Array<vehicle>>}
* @returns {Promise<[Array<vehicle>, number]>}
*/
static async getAll(): Promise<Array<vehicle>> {
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<vehicle>, number]> {
let query = dataSource
.getRepository(vehicle)
.createQueryBuilder("vehicle")
.leftJoinAndSelect("vehicle.vehicleType", "vehicletype")
.leftJoinAndSelect("vehicle.vehicleType", "vehicletype");
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;
})

View file

@ -1,3 +1,4 @@
import { Like, In } from "typeorm";
import { dataSource } from "../../../data-source";
import { vehicleType } from "../../../entity/unit/vehicle/vehicleType";
import DatabaseActionException from "../../../exceptions/databaseActionException";
@ -5,14 +6,40 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
export default abstract class VehicleTypeService {
/**
* @description get all vehicleTypes
* @returns {Promise<Array<vehicleType>>}
* @returns {Promise<[Array<vehicleType>, number]>}
*/
static async getAll(): Promise<Array<vehicleType>> {
return await dataSource
.getRepository(vehicleType)
.createQueryBuilder("vehicleType")
static async getAll({
offset = 0,
count = 25,
search = "",
noLimit = false,
ids = [],
}: {
offset?: number;
count?: number;
search?: string;
noLimit?: boolean;
ids?: Array<string>;
}): Promise<[Array<vehicleType>, number]> {
let query = dataSource.getRepository(vehicleType).createQueryBuilder("vehicleType");
if (search != "") {
query = query.where({
type: Like(search),
});
}
if (ids.length != 0) {
query = query.where({ id: In(ids) });
}
if (!noLimit) {
query = query.offset(offset).limit(count);
}
return await query
.orderBy("type", "ASC")
.getMany()
.getManyAndCount()
.then((res) => {
return res;
})