Added createTag endpoint + doc
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
"$ref": "#/components/responses/500BackendError"
}
}
+ },
+ "post": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Create a Tag",
+ "tags": [
+ "Tags"
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "example": "T12345678"
+ },
+ "userID": {
+ "type": "string",
+ "example": "5db815731fdcb70006e0a8ce"
+ },
+ "issuer": {
+ "type": "boolean",
+ "example": true
+ },
+ "active": {
+ "type": "boolean",
+ "example": true
+ },
+ "description": {
+ "type": "string",
+ "example": "Badge description"
+ },
+ "default": {
+ "type": "boolean",
+ "example": true
+ }
+ }
+ }
+ }
+ }
+ },
+ "responses": {
+ "201": {
+ "description": "Tag created successfully",
+ "content": {
+ "application/json": {
+ "example": {
+ "id": "###",
+ "status": "Success"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/500BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ },
+ "576": {
+ "description": "Tag already exists"
+ }
+ }
}
},
"/api/tags/{id}": {
"chargingRateUnit",
"chargingSchedulePeriod"
]
+ },
+ "Tag": {
+ "type": "object",
+ "properties": {
+ "userID": {
+ "type": "string",
+ "example": "###"
+ },
+ "issuer": {
+ "type": "boolean",
+ "example": true
+ },
+ "active": {
+ "type": "boolean",
+ "example": true
+ },
+ "description": {
+ "type": "string",
+ "example": "Badge description"
+ },
+ "default": {
+ "type": "boolean",
+ "example": true
+ }
+ }
}
},
"parameters": {

MODIFY
src/server/rest/v1/router/api/TagRouter.ts
src/server/rest/v1/router/api/TagRouter.ts
@@ -15,6 +15,7 @@ export default class TagRouter {
public buildRoutes(): express.Router {
this.buildRouteTags();
this.buildRouteTag();
+ this.buildRouteCreateTag();
return this.router;
}
@@ -30,4 +31,11 @@ export default class TagRouter {
await RouterUtils.handleServerAction(TagService.handleGetTag.bind(this), ServerAction.TAG, req, res, next);
});
}
+
+ protected buildRouteCreateTag(): void {
+ this.router.post(`/${ServerRoute.REST_TAGS}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(TagService.handleCreateTag.bind(this), ServerAction.TAG_CREATE, req, res, next);
+ });
+ }
}

MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
@@ -14,6 +14,7 @@ import Logging from '../../../../utils/Logging';
import OCPIClientFactory from '../../../../client/ocpi/OCPIClientFactory';
import { OCPIRole } from '../../../../types/ocpi/OCPIRole';
import { ServerAction } from '../../../../types/Server';
+import { StatusCodes } from 'http-status-codes';
import Tag from '../../../../types/Tag';
import TagSecurity from './security/TagSecurity';
import TagStorage from '../../../../storage/mongodb/TagStorage';
@@ -315,7 +316,7 @@ export default class TagService {
message: `Tag with ID '${newTag.id}'has been created successfully`,
detailedMessages: { tag: newTag }
});
- res.json(Object.assign({ id: newTag.id }, Constants.REST_RESPONSE_SUCCESS));
+ res.status(StatusCodes.CREATED).json(Object.assign({ id: newTag.id }, Constants.REST_RESPONSE_SUCCESS));
next();
}

Added createTag endpoint + doc