Added updateMobileToken endpoint + doc
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
}
}
},
+ "/api/users/{id}/mobile-token": {
+ "put": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Update user's mobile tokens",
+ "tags": [
+ "Users"
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "properties": {
+ "mobileToken": {
+ "type": "string"
+ },
+ "mobileOS": {
+ "type": "string"
+ }
+ }
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "Mobile token successfully updated",
+ "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/tags": {
"get": {
"security": [

MODIFY
src/server/rest/v1/router/api/UserRouter.ts
src/server/rest/v1/router/api/UserRouter.ts
@@ -22,6 +22,7 @@ export default class UserRouter {
this.buildRouteUserGetSites();
this.buildRouteUserSiteAssign();
this.buildRouteUserSiteUnassign();
+ this.buildRouteUserUpdateMobileToken();
return this.router;
}
@@ -84,4 +85,10 @@ export default class UserRouter {
await RouterUtils.handleServerAction(UserService.handleAssignSitesToUser.bind(this), ServerAction.REMOVE_SITES_FROM_USER, req, res, next);
});
}
+
+ protected buildRouteUserUpdateMobileToken(): void {
+ this.router.put(`/${ServerRoute.REST_USER_UPDATE_MOBILE_TOKEN}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(UserService.handleUpdateUserMobileToken.bind(this), ServerAction.USER_UPDATE_MOBILE_TOKEN, req, res, next);
+ });
+ }
}

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -531,7 +531,7 @@ export default class UserService {
public static async handleUpdateUserMobileToken(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = UserSecurity.filterUserUpdateMobileTokenRequest(req.body);
+ const filteredRequest = UserSecurity.filterUserUpdateMobileTokenRequest({ ...req.params, ...req.body });
// Check Mandatory fields
if (!filteredRequest.mobileToken) {
throw new AppError({

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -498,6 +498,7 @@ export enum ServerRoute {
REST_USER = 'users/:id',
REST_USER_DEFAULT_TAG_CAR = 'users/:id/default-car-tag',
REST_USER_SITES = 'users/:id/sites',
+ REST_USER_UPDATE_MOBILE_TOKEN = 'users/:id/mobile-token',
REST_TAGS = 'tags',
REST_TAG = 'tags/:id',

MODIFY
test/api/UserTest.ts
test/api/UserTest.ts
@@ -2,6 +2,7 @@ import chai, { assert, expect } from 'chai';
import CentralServerService from '../api/client/CentralServerService';
import ChargingStationContext from './context/ChargingStationContext';
+import Constants from '../../src/utils/Constants';
import ContextDefinition from './context/ContextDefinition';
import ContextProvider from './context/ContextProvider';
import Factory from '../factories/Factory';
@@ -238,6 +239,17 @@ describe('User tests', function() {
expect(updatedUser.name).to.equal(testData.newUser.name);
});
+ it('Should update user\'s mobile token', async () => {
+ // Check if the deleted entity cannot be retrieved with its id
+ const response = await testData.userService.userApi.updateMobileToken(
+ testData.newUser.id,
+ 'new_mobile_token',
+ 'mobile_os'
+ );
+ expect(response.status).to.be.eq(StatusCodes.OK);
+ expect(response.data).to.be.deep.eq(Constants.REST_RESPONSE_SUCCESS);
+ });
+
it('Should be able to delete the created user', async () => {
// Delete the created entity
await testData.userService.deleteEntity(
@@ -253,7 +265,6 @@ describe('User tests', function() {
testData.newUser
);
});
-
});
describe('Using function "readAllInError"', () => {

MODIFY
test/api/client/UserApi.ts
test/api/client/UserApi.ts
import CrudApi from './utils/CrudApi';
+import { ServerRoute } from '../../../src/types/Server';
import TestConstants from './utils/TestConstants';
export default class UserApi extends CrudApi {
@@ -57,4 +58,11 @@ export default class UserApi extends CrudApi {
public async exportTags(params) {
return await super.read(params, '/client/api/TagsExport');
}
+
+ public async updateMobileToken(userID: string, mobileToken: string, mobileOS: string) {
+ const url = this.buildRestEndpointUrl(ServerRoute.REST_USER_UPDATE_MOBILE_TOKEN, { id: userID });
+ return await super.update({
+ mobileToken, mobileOS
+ }, url);
+ }
}

Added updateMobileToken endpoint + doc