Use dedicated schema in Car delete endpoint
ADD
src/assets/server/rest/v1/schemas/car/car-delete.json
+{
+ "$id": "car-delete",
+ "title": "Delete Car Request",
+ "type": "object",
+ "properties": {
+ "ID": {
+ "$ref": "common#/definitions/id"
+ }
+ },
+ "required": [
+ "ID"
+ ]
+}

MODIFY
src/server/rest/v1/service/CarService.ts
src/server/rest/v1/service/CarService.ts
import { Action, Entity } from '../../../../types/Authorization';
import { AsyncTaskType, AsyncTasks } from '../../../../types/AsyncTask';
import { CarCatalogDataResult, CarDataResult } from '../../../../types/DataResult';
-import { HTTPAuthError, HTTPError } from '../../../../types/HTTPError';
import { NextFunction, Request, Response } from 'express';
import Tenant, { TenantComponents } from '../../../../types/Tenant';
-import AppAuthError from '../../../../exception/AppAuthError';
import AppError from '../../../../exception/AppError';
import AsyncTaskBuilder from '../../../../async-task/AsyncTaskBuilder';
import AuthorizationService from './AuthorizationService';
@@ -14,6 +12,7 @@ import { Car } from '../../../../types/Car';
import CarStorage from '../../../../storage/mongodb/CarStorage';
import CarValidator from '../validator/CarValidator';
import Constants from '../../../../utils/Constants';
+import { HTTPError } from '../../../../types/HTTPError';
import LockingHelper from '../../../../locking/LockingHelper';
import LockingManager from '../../../../locking/LockingManager';
import Logging from '../../../../utils/Logging';
@@ -394,7 +393,7 @@ export default class CarService {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.CAR,
Action.DELETE, Entity.CAR, MODULE_NAME, 'handleDeleteCar');
// Filter
- const carID = CarValidator.getInstance().validateCarGetReq(req.query).ID;
+ const carID = CarValidator.getInstance().validateCarDeleteReq(req.query).ID;
// Check and Get Car
const car = await UtilsService.checkAndGetCarAuthorization(
req.tenant, req.user, carID, Action.DELETE, action);

MODIFY
src/server/rest/v1/validator/CarValidator.ts
src/server/rest/v1/validator/CarValidator.ts
@@ -15,6 +15,7 @@ export default class CarValidator extends SchemaValidator {
private carUpdate: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/car/car-update.json`, 'utf8'));
private carsGet: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/car/cars-get.json`, 'utf8'));
private carGet: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/car/car-get.json`, 'utf8'));
+ private carDelete: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/car/car-delete.json`, 'utf8'));
private constructor() {
super('CarValidator');
@@ -58,4 +59,8 @@ export default class CarValidator extends SchemaValidator {
public validateCarGetReq(data: Record<string, unknown>): HttpCarRequest {
return this.validate(this.carGet, data);
}
+
+ public validateCarDeleteReq(data: Record<string, unknown>): HttpCarRequest {
+ return this.validate(this.carDelete, data);
+ }
}

Use dedicated schema in Car delete endpoint