Skip to content

Commit

Permalink
Fix: Fixed the issue in update user form.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoud-Emad committed Apr 23, 2024
1 parent d7715c5 commit f6e4b76
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
11 changes: 8 additions & 3 deletions client/src/components/UpdateUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,18 @@ export default {
const { execute, isLoading } = useAsyncState(
async () => {
selectedUser.value.user_type = selectedUser.value.user_type === "Team Lead" ? "Supervisor" : selectedUser.value.user_type
await $api.myprofile.update(selectedUser.value.id, {
// const imageParts = selectedUser.value.image.split("/") as string[]
// const filename = imageParts[imageParts.length -1]
// console.log("selectedUser.value.image", filename)
const data = {
...selectedUser.value,
image: imageUrl.value ? imageUrl.value : selectedUser.value.image,
image: imageUrl.value ? imageUrl.value : null,
location: selectedUser.value.location.id,
filename: image.value ? image.value[0].name : null,
reporting_to: reporting_to.value ? [reporting_to.value.id] : []
})
}
await $api.myprofile.update(selectedUser.value.id, data)
},
null,
{ immediate: false }
Expand Down
15 changes: 5 additions & 10 deletions server/cshr/views/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,10 @@ def put(self, request: Request, id: str, format=None) -> Response:
user = get_user_by_id(id)
if user is None:
return CustomResponse.not_found(status_code=404, message="User not found")
remove_image: bool = request.data.get("remove_image")
filename: str = request.data.get("filename")
if request.data.get("image") == "":

image = request.data.get("image")

if not image:
request.data["image"] = user.image if user.image else None

serializer = self.get_serializer(user, data=request.data, partial=True)
Expand All @@ -288,13 +289,7 @@ def put(self, request: Request, id: str, format=None) -> Response:
joining_at=request.data.get("joining_at"),
reporting_to=request.data.get("reporting_to"),
)
if remove_image:
user.image.delete()
user.save()
else:
dir = user.image.name.split("/")[0]
user.image = f"{dir}/{filename}"
user.save()

return CustomResponse.success(
data=serializer.data, status_code=202, message="User updated"
)
Expand Down

0 comments on commit f6e4b76

Please sign in to comment.