Added tag-create validation schema
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
"type": "string",
"example": "T12345678"
},
+ "visualID": {
+ "type": "string",
+ "example": "###"
+ },
"userID": {
"type": "string",
"example": "###"

MODIFY
src/assets/server/rest/v1/schemas/tag/imported-tag-create-req.json
src/assets/server/rest/v1/schemas/tag/imported-tag-create-req.json
{
- "title": "Tag creation",
+ "title": "Tag importation",
"description": "",
"type": "object",
"properties": {
"id": {
- "type": "string",
- "minLength": 1,
- "maxLength": 100,
- "pattern": "^[a-zA-Z0-9]*$"
+ "$ref": "tag.json#/definitions/id"
},
"description": {
- "type": "string"
+ "$ref": "tag.json#/definitions/description"
},
"visualID": {
- "type": "string"
+ "$ref": "tag.json#/definitions/visualID"
}
},
"required": [

ADD
src/assets/server/rest/v1/schemas/tag/tag-create.json
+{
+ "title": "Tag creation",
+ "description": "",
+ "type": "object",
+ "properties": {
+ "id": {
+ "$ref": "tag.json#/definitions/id"
+ },
+ "visualID": {
+ "$ref": "tag.json#/definitions/visualID"
+ },
+ "description": {
+ "$ref": "tag.json#/definitions/description"
+ },
+ "active": {
+ "$ref": "tag.json#/definitions/active"
+ },
+ "issuer": {
+ "$ref": "tag.json#/definitions/issuer"
+ },
+ "default": {
+ "$ref": "tag.json#/definitions/default"
+ },
+ "userID": {
+ "$ref": "tag.json#/definitions/userID"
+ }
+ },
+ "required": [
+ "id",
+ "visualID",
+ "userID"
+ ]
+}

MODIFY
src/assets/server/rest/v1/schemas/tag/tag.json
src/assets/server/rest/v1/schemas/tag/tag.json
"type": "string",
"pattern": "^(([\\w\\d]*)(\\||[\\w\\d])*)?$",
"sanitize": "mongo"
+ },
+ "visualID": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "description": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "active": {
+ "type": "boolean",
+ "sanitize": "mongo"
+ },
+ "issuer": {
+ "type": "boolean",
+ "sanitize": "mongo"
+ },
+ "default": {
+ "type": "boolean",
+ "sanitize": "mongo"
+ },
+ "userID": {
+ "$ref": "user.json#/definitions/id"
}
}
}

MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
@@ -83,7 +83,7 @@ export default class TagService {
public static async handleCreateTag(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = TagSecurity.filterTagCreateRequest(req.body, req.user);
+ const filteredRequest = TagValidator.getInstance().validateTagCreate(req.body);
// Check
UtilsService.checkIfUserTagIsValid(filteredRequest, req);
// Get dynamic auth

MODIFY
src/server/rest/v1/validator/TagValidator.ts
src/server/rest/v1/validator/TagValidator.ts
-import { ImportedTag } from '../../../../types/Tag';
+import Tag, { ImportedTag } from '../../../../types/Tag';
+
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from './SchemaValidator';
import fs from 'fs';
@@ -7,10 +8,12 @@ import global from '../../../../types/GlobalType';
export default class TagValidator extends SchemaValidator {
private static instance: TagValidator|null = null;
private importedTagCreation: Schema;
+ private tagCreate: Schema;
private constructor() {
super('TagValidator');
this.importedTagCreation = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/tag/imported-tag-create-req.json`, 'utf8'));
+ this.tagCreate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/tag/tag-create.json`, 'utf8'));
}
public static getInstance(): TagValidator {
@@ -23,4 +26,9 @@ export default class TagValidator extends SchemaValidator {
validateImportedTagCreation(importedTag: ImportedTag): void {
this.validate(this.importedTagCreation, importedTag);
}
+
+ validateTagCreate(tag: Tag): Tag {
+ this.validate(this.tagCreate, tag);
+ return tag;
+ }
}

Added tag-create validation schema