Help wanted in converting context.req.body to User model with Dart and appwrite function
- 0
- Users
- Flutter
- Functions
- Cloud
From the looks of it, this function creates a user-specific document. Why do you want to convert to a User object?
One other thing i also need to encode-decode "context.req.body" for using it, i don't think i am doing it right also
I have created a friend request type system in my app. so i need to show other users to app user so i thought it will be a better way
Okay but why do you want to use the User object in this function for that?
A better approach would be to store just the user IDs in the friendIdList attribute, and use the IDs to fetch and display each user
Just to be sure, what exactly do you want to convert into a User object?
I think i am not clear in what i am trying to say
I have implemented exactly what you said i am just storing IDs of users in friendIdList
I am trying to say that ,
How can i convert context.req.body into a User model so that i can access properties (name,email) like userObject.name , userObject.email. & not have to userMap['key'] to use its value I hope you are getting it.
You definitely shouldn't need to encode and decode like that
How are you executing this function?
It is executed on user create event
Right now, body is a string. In 1.4.4, it will be a map
So can i parse it?
If you don't want your function to break you should jsonDecode(context.bodyRaw). That will give you a map
I think i am getting the above mentioned error when parsing map to User model but i didn't try with bodyRaw , let me check
It will work if i directly assign it to a variable?
I've seen an issue raised about user preferences...can you check the type of user preferences before converting it?
I think because the list is empty, dart can not check the type of List
An empty list is still a type. However, it shouldn't be a list
If you can confirm it's a list, we know where the problem is
I have not touched preferences ,I don't know how it is set to an empty list (First i thought it is supposed to be a list but now that you said,I checked again 😅 )
Ya it's a bug. You might want to 👍 this issue and comment saying it's a problem in functions too: https://github.com/appwrite/appwrite/issues/6360
What you can do now is after JSON decode, check if it's a list and if it is, set it to an empty Map<String, dynamic>. Then, doing User.fromMap() should work
Thought so , For now i am using the map for accessing the values 👍
Recommended threads
- Function deployment failed: Unable to re...
Hi Appwrite team, I have been experiencing persistent errors when i attempt to push my appwrite functions. The logs on the deployment detail page on the console...
- One to many 2 way, console UI not correc...
Hey, seems I'm facing the exactly same issue with this one: https://github.com/appwrite/appwrite/issues/6016 Since this Github issue stay open for so long, let ...
- Server Down
Appwrite services are down. When will they start working again?