Added site update/admin/owner endpoints + 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/ResourceDoesNotExists"
}
}
+ },
+ "put": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Update a Site",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/siteID"
+ }
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/Site"
+ }
+ }
+ }
+ },
+ "tags": [
+ "Sites"
+ ],
+ "responses": {
+ "200": {
+ "description": "Site updated successfully",
+ "content": {
+ "application/json": {
+ "example": {
+ "status": "Success"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ },
+ "585": {
+ "description": "Cannot set site to private as one or several charging stations under site are public"
+ }
+ }
}
},
"/api/sites/{id}/users": {
}
}
},
+ "/api/sites/{id}/users/admin": {
+ "put": {
+ "description": "Set user as site admin",
+ "tags": [
+ "Sites"
+ ],
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/siteID"
+ }
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "required": [
+ "userID",
+ "siteAdmin"
+ ],
+ "properties": {
+ "userID": {
+ "type": "string"
+ },
+ "siteAdmin": {
+ "type": "boolean"
+ }
+ }
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "User successfully set/unset as site admin",
+ "content": {
+ "application/json": {
+ "example": {
+ "status": "Success"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
+ }
+ }
+ },
+ "/api/sites/{id}/users/owner": {
+ "put": {
+ "description": "Set user as site owner",
+ "tags": [
+ "Sites"
+ ],
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/siteID"
+ }
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "required": [
+ "userID",
+ "siteOwner"
+ ],
+ "properties": {
+ "userID": {
+ "type": "string"
+ },
+ "siteAdmin": {
+ "type": "boolean"
+ }
+ }
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "User successfully set/unset as site owner",
+ "content": {
+ "application/json": {
+ "example": {
+ "status": "Success"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
+ }
+ }
+ },
"/api/loggings": {
"get": {
"security": [

MODIFY
src/server/rest/v1/router/api/SiteRouter.ts
src/server/rest/v1/router/api/SiteRouter.ts
@@ -20,6 +20,9 @@ export default class SiteRouter {
this.buildRouteSiteAssignUsers();
this.buildRouteSiteUnassignUsers();
this.buildRouteSiteGetUsers();
+ this.buildRouteSetSiteAdmin();
+ this.buildRouteSetSiteOwner();
+ this.buildRouteUpdateSite();
return this.router;
}
@@ -62,4 +65,25 @@ export default class SiteRouter {
await RouterUtils.handleServerAction(SiteService.handleGetUsers.bind(this), ServerAction.SITE_USERS, req, res, next);
});
}
+
+ private buildRouteSetSiteAdmin(): void {
+ this.router.put(`/${ServerRoute.REST_SITE_ADMIN}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.siteID = req.params.id;
+ await RouterUtils.handleServerAction(SiteService.handleUpdateSiteUserAdmin.bind(this), ServerAction.SITE_USER_ADMIN, req, res, next);
+ });
+ }
+
+ private buildRouteSetSiteOwner(): void {
+ this.router.put(`/${ServerRoute.REST_SITE_OWNER}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.siteID = req.params.id;
+ await RouterUtils.handleServerAction(SiteService.handleUpdateSiteOwner.bind(this), ServerAction.SITE_OWNER, req, res, next);
+ });
+ }
+
+ private buildRouteUpdateSite(): void {
+ this.router.put(`/${ServerRoute.REST_SITE}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
+ await RouterUtils.handleServerAction(SiteService.handleUpdateSite.bind(this), ServerAction.SITE_UPDATE, req, res, next);
+ });
+ }
}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -614,6 +614,8 @@ export enum ServerRoute {
REST_SITE_USERS = 'sites/:id/users',
REST_SITE_ADD_USERS = 'sites/:id/users/assign',
REST_SITE_REMOVE_USERS = 'sites/:id/users/unassign',
+ REST_SITE_ADMIN = 'sites/:id/users/admin',
+ REST_SITE_OWNER = 'sites/:id/users/owner',
// BILLING URLs for CRUD operations on PAYMENT METHODS
REST_BILLING_PAYMENT_METHODS = 'users/:userID/payment-methods',

MODIFY
test/api/client/SiteApi.ts
test/api/client/SiteApi.ts
@@ -53,27 +53,25 @@ export default class SiteApi extends CrudApi {
}
public async update(data) {
- return super.update(data, '/client/api/SiteUpdate');
+ return super.update(data, this.buildRestEndpointUrl(ServerRoute.REST_SITE, { id: data.id }));
}
public async delete(id) {
return super.delete(id, '/client/api/SiteDelete');
}
- public async assignSiteAdmin(siteId, userId) {
+ public async assignSiteAdmin(siteID: string, userID: string) {
return super.update({
- siteID: siteId,
- userID: userId,
+ userID: userID,
siteAdmin: true
- }, '/client/api/SiteUserAdmin');
+ }, this.buildRestEndpointUrl(ServerRoute.REST_SITE_ADMIN, { id: siteID }));
}
- public async assignSiteOwner(siteId, userId) {
+ public async assignSiteOwner(siteID: string, userID: string) {
return super.update({
- siteID: siteId,
- userID: userId,
+ userID: userID,
siteOwner: true
- }, '/client/api/SiteOwner');
+ }, this.buildRestEndpointUrl(ServerRoute.REST_SITE_OWNER, { id: siteID }));
}
}

Added site update/admin/owner endpoints + doc