Add generic address schema
DELETE
src/assets/server/rest/v1/schemas/common/address.json
-{
- "$id": "/assets/server/rest/v1/schemas/common/address.json",
- "type": "object",
- "properties": {
- "address1": {
- "type": "string",
- "sanitize": "mongo"
- },
- "address2": {
- "type": "string",
- "sanitize": "mongo"
- },
- "postalCode": {
- "type": "string",
- "sanitize": "mongo"
- },
- "city": {
- "type": "string",
- "sanitize": "mongo"
- },
- "department": {
- "type": "string",
- "sanitize": "mongo"
- },
- "region": {
- "type": "string",
- "sanitize": "mongo"
- },
- "country": {
- "type": "string",
- "sanitize": "mongo"
- },
- "coordinates": {
- "type": "array",
- "sanitize": "mongo"
- }
- }
-}
\ No newline at end of file

ADD
src/assets/server/rest/v1/schemas/common/common.json
+{
+ "$id": "common.json",
+ "type": "object",
+ "common": {
+ "type": "object",
+ "address": {
+ "type": "object",
+ "properties": {
+ "address1": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "address2": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "postalCode": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "city": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "department": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "region": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "country": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "coordinates": {
+ "type": "array",
+ "sanitize": "mongo"
+ }
+ }
+ }
+ }
+}
\ No newline at end of file

MODIFY
src/assets/server/rest/v1/schemas/tenant/tenant-create-req-super-admin.json
src/assets/server/rest/v1/schemas/tenant/tenant-create-req-super-admin.json
"type": "string",
"sanitize": "mongo"
},
- "address": {
- "type": "object",
- "properties": {
- "address1": {
- "type": "string",
- "sanitize": "mongo"
- },
- "address2": {
- "type": "string",
- "sanitize": "mongo"
- },
- "postalCode": {
- "type": "string",
- "sanitize": "mongo"
- },
- "city": {
- "type": "string",
- "sanitize": "mongo"
- },
- "department": {
- "type": "string",
- "sanitize": "mongo"
- },
- "region": {
- "type": "string",
- "sanitize": "mongo"
- },
- "country": {
- "type": "string",
- "sanitize": "mongo"
- },
- "coordinates": {
- "type": "array",
- "sanitize": "mongo"
- }
- }
- },
+ "address": { "$ref": "common.json#/common/address" },
"components": {
"type": "object",
"properties": {

MODIFY
src/assets/server/rest/v1/schemas/tenant/tenant-update-req-super-admin.json
src/assets/server/rest/v1/schemas/tenant/tenant-update-req-super-admin.json
"type": "string",
"sanitize": "mongo"
},
- "address": {
- "type": "object",
- "properties": {
- "address1": {
- "type": "string",
- "sanitize": "mongo"
- },
- "address2": {
- "type": "string",
- "sanitize": "mongo"
- },
- "postalCode": {
- "type": "string",
- "sanitize": "mongo"
- },
- "city": {
- "type": "string",
- "sanitize": "mongo"
- },
- "department": {
- "type": "string",
- "sanitize": "mongo"
- },
- "region": {
- "type": "string",
- "sanitize": "mongo"
- },
- "country": {
- "type": "string",
- "sanitize": "mongo"
- },
- "coordinates": {
- "type": "array",
- "sanitize": "mongo"
- }
- }
- },
+ "address": { "$ref": "common.json#/common/address" },
"components": {
"type": "object",
"properties": {

MODIFY
src/server/rest/v1/validator/SchemaValidator.ts
src/server/rest/v1/validator/SchemaValidator.ts
@@ -4,6 +4,8 @@ import Constants from '../../../../utils/Constants';
import { HTTPError } from '../../../../types/HTTPError';
import ajvSanitizer from 'ajv-sanitizer';
import sanitize from 'mongo-sanitize';
+import fs from 'fs';
+import global from '../../../../types/GlobalType';
const extraSanitizers = {
mongo: (value) => sanitize(value),
@@ -11,6 +13,7 @@ const extraSanitizers = {
export default class SchemaValidator {
private readonly ajv: Ajv.Ajv;
+ private _commonSchema: any = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/common/common.json`, 'utf8'));
constructor(readonly moduleName: string,
config: {allErrors: boolean; removeAdditional: boolean|'all'|'failing'|undefined;
@@ -21,6 +24,7 @@ export default class SchemaValidator {
coerceTypes: true
}) {
this.ajv = ajvSanitizer(new Ajv(config), extraSanitizers);
+ this.ajv.addSchema(this._commonSchema);
}
public validate(schema: boolean|object, content: any): void {

MODIFY
src/server/rest/v1/validator/TenantValidation.ts
src/server/rest/v1/validator/TenantValidation.ts
@@ -8,7 +8,6 @@ import global from '../../../../types/GlobalType';
export default class TenantValidator extends SchemaValidator {
private static _instance: TenantValidator | undefined;
- private _commonAddress: any;
private _tenantCreateReqSuperAdmin: any;
private _tenantUpdateReqSuperAdmin: any;
private _tenantDeleteReqSuperAdmin: any;
@@ -18,12 +17,10 @@ export default class TenantValidator extends SchemaValidator {
private constructor() {
super('TenantValidator');
- this._commonAddress = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/common/address.json`, 'utf8'));
this._tenantCreateReqSuperAdmin = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/tenant/tenant-create-req-super-admin.json`, 'utf8'));
this._tenantUpdateReqSuperAdmin = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/tenant/tenant-update-req-super-admin.json`, 'utf8'));
this._tenantDeleteReqSuperAdmin = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/tenant/tenant-delete-req-super-admin.json`, 'utf8'));
// TODO: restliche Json nachladen
- // Address -> "address": { "$ref": "address.json#" }
}
public static getInstance(): TenantValidator {

Add generic address schema