Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usersEndpoint: create or update user #107

Closed
kilchenmann opened this issue Nov 17, 2019 · 5 comments
Closed

usersEndpoint: create or update user #107

kilchenmann opened this issue Nov 17, 2019 · 5 comments
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@kilchenmann
Copy link
Contributor

kilchenmann commented Nov 17, 2019

I'm not able to create a user (or update user). In the app we have a form to create new user and I submit for example the following data:

{
  "email": "[email protected]",
  "familyName": "Duck",
  "givenName": "Donald",
  "lang": "en",
  "password": "DuckDuck50",
  "status": true,
  "systemAdmin": false,
  "username": "duck"
}

I get an error 400 Bad Request with the message: "The request content was malformed:
Object is missing required member 'username'". I figured out, that the request payload is an empty object {}. It seems to be something's wrong in the createUser method in usersEndpoint. I have similar issues in updateUserBasicInformation or in projectsEndpoint. It always converts my payload data into an empty object. Probably because of jsonConvert.serializeObject?

@kilchenmann kilchenmann added bug Something isn't working question Further information is requested labels Nov 17, 2019
@tobiasschweizer
Copy link
Contributor

Could you point out to me how you use the method?

Or could you compare it to the unit tests:

https://github.com/dasch-swiss/knora-api-js-lib/blob/ac1d0fe2bc4b299bb88118aefb175e2d5cf03454/src/api/admin/users/users-endpoint.spec.ts#L289-L369

The unit tests also check for the payload. Hence an empty object should make the tests fail.

@tobiasschweizer
Copy link
Contributor

see #67 for a more convenient way to create instances

@kilchenmann
Copy link
Contributor Author

I used the method as follow:

this.knoraApiConnection.admin.usersEndpoint.createUser(this.form.value).subscribe(
    (response: ApiResponseData<UserResponse>) => {
        this.user = response.body.user;
    },
    (error: ApiResponseError) => {
        this.errorMessage = error;
    }
);

But as #67 says, I have to initiate the data with new User() and allocate all properties with the form values? I'll try...

@kilchenmann
Copy link
Contributor Author

So I have to write as follow:

const userData: User = new User();
userData.username = this.form.value.username;
userData.familyName = this.form.value.familyName;
userData.givenName = this.form.value.givenName;
userData.email = this.form.value.email;
userData.password = this.form.value.password;
userData.systemAdmin = this.form.value.systemAdmin;
userData.status = this.form.value.status;
userData.lang = this.form.value.lang;

this.knoraApiConnection.admin.usersEndpoint.createUser(userData).subscribe(
    (response: ApiResponseData<UserResponse>) => {
        this.user = response.body.user;
    },
    (error: ApiResponseError) => {
        this.errorMessage = error;
    }
);

It's a little awkward, but ok. Thanks @tobiasschweizer

@tobiasschweizer
Copy link
Contributor

It's a little awkward

Yes, it is indeed inconvenient!

We will try to come up with a better solution in #67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants