Added sites getUsers/assign/unassign endpoints + doc
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
}
}
},
+ "/api/sites/{id}/users": {
+ "get": {
+ "description": "Retrieve site's users",
+ "tags": [
+ "Sites"
+ ],
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/siteID"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Return site's user list",
+ "content": {
+ "application/json": {
+ "example": {
+ "count": 1,
+ "result": [
+ {
+ "siteID": "###",
+ "siteAdmin": false,
+ "user": {
+ "email": "###",
+ "firstName": "###",
+ "name": "###",
+ "role": "A",
+ "id": "###"
+ }
+ }
+ ]
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
+ }
+ }
+ },
+ "/api/sites/{id}/assign": {
+ "get": {
+ "description": "Assign users to a site",
+ "tags": [
+ "Sites"
+ ],
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/siteID"
+ }
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "required": [
+ "userIDs"
+ ],
+ "properties": {
+ "userIDs": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "Users successfully assigned",
+ "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}/unassign": {
+ "get": {
+ "description": "Unassign users from a site",
+ "tags": [
+ "Sites"
+ ],
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/siteID"
+ }
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "required": [
+ "userIDs"
+ ],
+ "properties": {
+ "userIDs": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "Users successfully unassigned",
+ "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
@@ -17,6 +17,9 @@ export default class SiteRouter {
this.buildRouteSites();
this.buildRouteSite();
this.buildRouteCreateSite();
+ this.buildRouteSiteAssignUsers();
+ this.buildRouteSiteUnassignUsers();
+ this.buildRouteSiteGetUsers();
return this.router;
}
@@ -38,4 +41,25 @@ export default class SiteRouter {
await RouterUtils.handleServerAction(SiteService.handleCreateSite.bind(this), ServerAction.SITE_CREATE, req, res, next);
});
}
+
+ private buildRouteSiteAssignUsers(): void {
+ this.router.put(`/${ServerRoute.REST_SITE_ADD_USERS}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
+ await RouterUtils.handleServerAction(SiteService.handleAssignUsersToSite.bind(this), ServerAction.ADD_USERS_TO_SITE, req, res, next);
+ });
+ }
+
+ private buildRouteSiteUnassignUsers(): void {
+ this.router.put(`/${ServerRoute.REST_SITE_REMOVE_USERS}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
+ await RouterUtils.handleServerAction(SiteService.handleAssignUsersToSite.bind(this), ServerAction.REMOVE_USERS_FROM_SITE, req, res, next);
+ });
+ }
+
+ private buildRouteSiteGetUsers(): void {
+ this.router.get(`/${ServerRoute.REST_SITE_USERS}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.SiteID = req.params.id;
+ await RouterUtils.handleServerAction(SiteService.handleGetUsers.bind(this), ServerAction.SITE_USERS, req, res, next);
+ });
+ }
}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -611,6 +611,9 @@ export enum ServerRoute {
REST_SITES = 'sites',
REST_SITE = 'sites/:id',
+ REST_SITE_USERS = 'sites/:id/users',
+ REST_SITE_ADD_USERS = 'sites/:id/users/assign',
+ REST_SITE_REMOVE_USERS = 'sites/:id/users/unassign',
// 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
@@ -24,36 +24,32 @@ export default class SiteApi extends CrudApi {
await super.create({
siteID: site.data.id,
userIDs: data.userIDs
- }, '/client/api/AddUsersToSite');
+ }, this.buildRestEndpointUrl(ServerRoute.REST_SITE_ADD_USERS, { id: site.data.id }));
}
return site;
}
- public async addUsersToSite(siteId, userIds) {
- return super.create({
- siteID: siteId,
- userIDs: userIds
- }, '/client/api/AddUsersToSite');
+ public async addUsersToSite(siteID: string, userIDs: string[]) {
+ return super.update({
+ siteID,
+ userIDs
+ }, this.buildRestEndpointUrl(ServerRoute.REST_SITE_ADD_USERS, { id: siteID }));
}
- public async addSitesToUser(userId: string, siteIds: string[]) {
- const url = this.buildRestEndpointUrl(ServerRoute.REST_USER_SITES, { id: userId });
- return super.create({
- siteIDs: siteIds,
- }, url);
+ public async addSitesToUser(userID: string, siteIDs: string[]) {
+ const url = this.buildRestEndpointUrl(ServerRoute.REST_USER_SITES, { id: userID });
+ return super.create({ siteIDs }, url);
}
- public async unassignSitesToUser(userId: string, siteIds: string[]) {
- const url = this.buildRestEndpointUrl(ServerRoute.REST_USER_SITES, { id: userId });
- return super.update({
- siteIDs: siteIds,
- }, url);
+ public async unassignSitesToUser(userID: string, siteIDs: string[]) {
+ const url = this.buildRestEndpointUrl(ServerRoute.REST_USER_SITES, { id: userID });
+ return super.update({ siteIDs }, url);
}
- public async readUsersForSite(siteId) {
+ public async readUsersForSite(siteID: string) {
return super.read({
- SiteID: siteId
- }, '/client/api/SiteUsers');
+ SiteID: siteID
+ }, this.buildRestEndpointUrl(ServerRoute.REST_SITE_USERS, { id: siteID }));
}
public async update(data) {

Added sites getUsers/assign/unassign endpoints + doc