Added updateUser + deleteUser endpoit + doc
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
},
"responses": {
"201": {
- "description": "Retrieved user",
+ "description": "User created successfully",
"content": {
"application/json": {
"example": {
},
"510": {
"$ref": "#/components/responses/EmailAlreadyUsed"
- },
- "550": {
- "$ref": "#/components/responses/ResourceDoesNotExists"
}
}
}
"$ref": "#/components/responses/ResourceDoesNotExists"
}
}
+ },
+ "put": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Update a User",
+ "tags": [
+ "Users"
+ ],
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/userID"
+ }
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/User"
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "User updated successfully",
+ "content": {
+ "application/json": {
+ "example": {
+ "status": "Success"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/500BackendError"
+ },
+ "510": {
+ "$ref": "#/components/responses/EmailAlreadyUsed"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
+ }
+ },
+ "delete": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Delete a User",
+ "tags": [
+ "Users"
+ ],
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/userID"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "User deleted successfully",
+ "content": {
+ "application/json": {
+ "example": {
+ "status": "Success"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/500BackendError"
+ },
+ "510": {
+ "description": "User cannot be deleted due to billing constraints"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
+ }
}
}
},
},
"User": {
"type": "object",
- "required": [""],
+ "required": [
+ "name",
+ "email"
+ ],
"properties": {
"costCenter": {
- "type": "string"
+ "type": "string",
+ "example": "######"
},
"name": {
"type": "string",
"example": "0000000000"
},
"locale": {
- "type": "string"
+ "type": "string",
+ "example": "en_EN"
},
"address": {
"$ref": "#/components/schemas/Address"
},
"email": {
"type": "string",
- "example": "user.demo2@sap.com"
+ "example": "user.demo@sap.com"
},
"issuer": {
"type": "boolean"
},
"status": {
"type": "string",
- "enum": ["P", "A", "I", "B", "L"]
+ "enum": [
+ "P",
+ "A",
+ "I",
+ "B",
+ "L"
+ ]
},
"plateID": {
"type": "string",
},
"role": {
"type": "string",
- "enum": ["S", "A", "B", "D"],
+ "enum": [
+ "S",
+ "A",
+ "B",
+ "D"
+ ],
"example": "B"
},
"notifications": {

MODIFY
src/server/rest/v1/router/api/UserRouter.ts
src/server/rest/v1/router/api/UserRouter.ts
@@ -15,6 +15,9 @@ export default class UserRouter {
public buildRoutes(): express.Router {
this.buildRouteUsers();
this.buildRouteUser();
+ this.buildRouteCreateUser();
+ this.buildRouteUpdateUser();
+ this.buildRouteDeleteUser();
return this.router;
}
@@ -22,16 +25,31 @@ export default class UserRouter {
this.router.get(`/${ServerRoute.REST_USERS}`, async (req: Request, res: Response, next: NextFunction) => {
await RouterUtils.handleServerAction(UserService.handleGetUsers.bind(this), ServerAction.USERS, req, res, next);
});
+ }
+
+ protected buildRouteUser(): void {
+ this.router.get(`/${ServerRoute.REST_USER}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(UserService.handleGetUser.bind(this), ServerAction.USER, req, res, next);
+ });
+ }
+ protected buildRouteCreateUser(): void {
this.router.post(`/${ServerRoute.REST_USERS}`, async (req: Request, res: Response, next: NextFunction) => {
await RouterUtils.handleServerAction(UserService.handleCreateUser.bind(this), ServerAction.USER_CREATE, req, res, next);
});
}
- protected buildRouteUser(): void {
- this.router.get(`/${ServerRoute.REST_USER}`, async (req: Request, res: Response, next: NextFunction) => {
+ protected buildRouteUpdateUser(): void {
+ this.router.put(`/${ServerRoute.REST_USER}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(UserService.handleUpdateUser.bind(this), ServerAction.USER_UPDATE, req, res, next);
+ });
+ }
+
+ protected buildRouteDeleteUser(): void {
+ this.router.delete(`/${ServerRoute.REST_USER}`, async (req: Request, res: Response, next: NextFunction) => {
req.query.ID = req.params.id;
- await RouterUtils.handleServerAction(UserService.handleGetUser.bind(this), ServerAction.USER, req, res, next);
+ await RouterUtils.handleServerAction(UserService.handleDeleteUser.bind(this), ServerAction.USER_DELETE, req, res, next);
});
}
}

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -420,7 +420,7 @@ export default class UserService {
public static async handleUpdateUser(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
let statusHasChanged = false;
// Filter
- const filteredRequest = UserSecurity.filterUserUpdateRequest(req.body, req.user);
+ const filteredRequest = UserSecurity.filterUserUpdateRequest({ ...req.params, ...req.body }, req.user);
UtilsService.assertIdIsProvided(action, filteredRequest.id, MODULE_NAME, 'handleUpdateUser', req.user);
// Check auth
if (!Authorizations.canUpdateUser(req.user, filteredRequest.id)) {

Added updateUser + deleteUser endpoit + doc