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

MODIFY
src/server/rest/v1/service/CompanyService.ts
src/server/rest/v1/service/CompanyService.ts
import { Action, Entity } from '../../../../types/Authorization';
import { NextFunction, Request, Response } from 'express';
-import AppAuthError from '../../../../exception/AppAuthError';
import AuthorizationService from './AuthorizationService';
import Company from '../../../../types/Company';
import { CompanyDataResult } from '../../../../types/DataResult';
import CompanyStorage from '../../../../storage/mongodb/CompanyStorage';
import CompanyValidator from '../validator/CompanyValidator';
import Constants from '../../../../utils/Constants';
-import { HTTPAuthError } from '../../../../types/HTTPError';
import Logging from '../../../../utils/Logging';
import { ServerAction } from '../../../../types/Server';
import { StatusCodes } from 'http-status-codes';
@@ -25,7 +23,7 @@ export default class CompanyService {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ORGANIZATION,
Action.DELETE, Entity.COMPANY, MODULE_NAME, 'handleDeleteCompany');
// Filter
- const companyID = CompanyValidator.getInstance().validateCompanyGetReq(req.query).ID;
+ const companyID = CompanyValidator.getInstance().validateCompanyDeleteReq(req.query).ID;
// Check and Get Company
const company = await UtilsService.checkAndGetCompanyAuthorization(
req.tenant, req.user, companyID, Action.DELETE, action);

MODIFY
src/server/rest/v1/validator/CompanyValidator.ts
src/server/rest/v1/validator/CompanyValidator.ts
@@ -10,6 +10,7 @@ export default class CompanyValidator extends SchemaValidator {
private static instance: CompanyValidator|null = null;
private companiesGet: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/company/companies-get.json`, 'utf8'));
private companyGet: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/company/company-get.json`, 'utf8'));
+ private companyDelete: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/company/company-delete.json`, 'utf8'));
private companyCreate: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/company/company-create.json`, 'utf8'));
private companyUpdate: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/company/company-update.json`, 'utf8'));
private companyLogoGet: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/company/company-logo-get.json`, 'utf8'));
@@ -29,6 +30,10 @@ export default class CompanyValidator extends SchemaValidator {
return this.validate(this.companiesGet, data);
}
+ public validateCompanyDeleteReq(data: Record<string, unknown>): HttpCompanyRequest {
+ return this.validate(this.companyDelete, data);
+ }
+
public validateCompanyGetReq(data: Record<string, unknown>): HttpCompanyRequest {
return this.validate(this.companyGet, data);
}

Use dedicated schema in Company delete endpoint