"Get de last item of object field list to user record"

Options
Sorry if the post title is a little bit odd 🙈
I will show step by step what I am doing and what I want to achieve.
I am in right way of there is something simpler or faster ?
[mock001.jpeg][mock002.jpeg]
I need to incorporate this in all user table queries (GET) to have only the user update status id ( lastest ) as a "regular field". All suggestions/brainstormings is welcome 😂  thanks in advance!🙏
Mayday to:  🙂

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
     - can you clarify for me? You want to just pull the user record that has the latest status_at field value?
  • Daniel Rjeili
    Options
     , when I query an user ( GET ) I need the response json brings the useraccountstatus_id of the latest status from the user object list accountStatus... as a regular single field from the table like i showed in the last image.
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    Ok. I think I understand now - useraccountstatus_id is nested in an object array of a record and you just want to return the latest object from that? Do you only want that object or do you want it a part of the user record you are pulling?
  • Daniel Rjeili
    Options
     
    I want it as part of the user I am pulling
    example : GET user id = 123

    {"id":123,"email":"daniel@xyz.com.br","name":"Daniel","status_at":1632524100000,"usersaccountstatus_id":1,"status_by":94}

    or only usersaccountstatus_id (even better):

    {"id":123,"email":"daniel@xyz.com.br","name":"Daniel","usersaccountstatus_id":1}
  • Sean Montgomery
    Sean Montgomery Administrator

    ADMIN

    Options
    If I am understanding this correctly, it sounds like this is just a transformation problem. Each user record has all the information it needs, but you want it to be transformed into a more minimal format - is that correct?

    If that is correct, then you can do that with just a foreach loop. Here is the pseudocode.
    1. Query All Records as users
    2. For Each users as user1. Update var:user = var:user|merge( var:user.accountStatus|last)|unset("accountStatus")

    The For Each loop uses a reference while it iterates, so you can just update that variable "user" and it will automatically update itself in the array - very convenient.

    Then you use the merge filter with the last element and then unset the accountStatus field.
  • Daniel Rjeili
    Options
     , i don't need query all records, I just need query specific record Id (GET single record), that brings lastest "usersaccountstatus_id". 
  • Daniel Rjeili
    Options
      and  , in this last minutes I followed Sean suggestion even with what I answered above. And I reached the result I needed!
    [mockup3.png]results:[mockup4.png]
    Thanks you both ! 👏  👍