Added getUserImage endpoint + doc
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
"content": {
"application/json": {
"schema": {
+ "required": [
+ "mobileToken"
+ ],
"properties": {
"mobileToken": {
"type": "string"
}
}
},
+ "/api/users/{id}/images": {
+ "get": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Get user's image",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/userID"
+ }
+ ],
+ "tags": [
+ "Users"
+ ],
+ "responses": {
+ "200": {
+ "description": "Retrieved user image",
+ "content": {
+ "application/json": {
+ "schema": {
+ "required": [
+ "id"
+ ],
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "User ID"
+ },
+ "image": {
+ "type": "string",
+ "description": "Base 64 encoded image"
+ }
+ }
+ },
+ "example": {
+ "id": "###",
+ "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAC..."
+ }
+ }
+ }
+ },
+ "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
@@ -23,6 +23,7 @@ export default class UserRouter {
this.buildRouteUserSiteAssign();
this.buildRouteUserSiteUnassign();
this.buildRouteUserUpdateMobileToken();
+ this.buildRouteUserGetImage();
return this.router;
}
@@ -91,4 +92,11 @@ export default class UserRouter {
await RouterUtils.handleServerAction(UserService.handleUpdateUserMobileToken.bind(this), ServerAction.USER_UPDATE_MOBILE_TOKEN, req, res, next);
});
}
+
+ protected buildRouteUserGetImage(): void {
+ this.router.get(`/${ServerRoute.REST_USER_IMAGE}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(UserService.handleGetUserImage.bind(this), ServerAction.USER_IMAGE, req, res, next);
+ });
+ }
}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -499,6 +499,7 @@ export enum ServerRoute {
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_USER_IMAGE = 'users/:id/image',
REST_TAGS = 'tags',
REST_TAG = 'tags/:id',

MODIFY
test/api/UserTest.ts
test/api/UserTest.ts
@@ -250,6 +250,13 @@ describe('User tests', function() {
expect(response.data).to.be.deep.eq(Constants.REST_RESPONSE_SUCCESS);
});
+ it('Should get user image', async () => {
+ const response = await testData.userService.userApi.getImage(testData.newUser.id);
+ expect(response.status).to.be.eq(StatusCodes.OK);
+ expect(response.data.id).to.be.eq(testData.newUser.id);
+ expect(response.data.image).to.be.null; // New users have a null image
+ });
+
it('Should be able to delete the created user', async () => {
// Delete the created entity
await testData.userService.deleteEntity(

MODIFY
test/api/client/UserApi.ts
test/api/client/UserApi.ts
@@ -8,11 +8,13 @@ export default class UserApi extends CrudApi {
}
public async readById(id) {
- return super.readById(id, '/client/api/User');
+ const url = this.buildRestEndpointUrl(ServerRoute.REST_USER, { id });
+ return super.readById(id, url);
}
public async readAll(params, paging = TestConstants.DEFAULT_PAGING, ordering = TestConstants.DEFAULT_ORDERING) {
- return super.readAll(params, paging, ordering, '/client/api/Users');
+ const url = this.buildRestEndpointUrl(ServerRoute.REST_USERS);
+ return super.readAll(params, paging, ordering, url);
}
public async readAllInError(params, paging = TestConstants.DEFAULT_PAGING, ordering = TestConstants.DEFAULT_ORDERING) {
@@ -20,15 +22,18 @@ export default class UserApi extends CrudApi {
}
public async create(data) {
- return super.create(data, '/client/api/UserCreate');
+ const url = this.buildRestEndpointUrl(ServerRoute.REST_USERS);
+ return super.create(data, url);
}
public async update(data) {
- return super.update(data, '/client/api/UserUpdate');
+ const url = this.buildRestEndpointUrl(ServerRoute.REST_USER, { id: data.id });
+ return super.update(data, url);
}
public async delete(id) {
- return super.delete(id, '/client/api/UserDelete');
+ const url = this.buildRestEndpointUrl(ServerRoute.REST_USER, { id });
+ return super.delete(id, url);
}
public async getByEmail(email) {
@@ -65,4 +70,9 @@ export default class UserApi extends CrudApi {
mobileToken, mobileOS
}, url);
}
+
+ public async getImage(userID: string) {
+ const url = this.buildRestEndpointUrl(ServerRoute.REST_USER_IMAGE, { id: userID });
+ return await super.read({}, url);
+ }
}

Added getUserImage endpoint + doc