robsontenorio/vue-api-query

More usage example needed for use Model as a Type

Closed this issue · 2 comments

Hi, I want to know how to use Model as Type.
because firtst(), get() returns Promise and I am making another class for contains It's data.

for example, If there is UserInfo Model for get user information from serer, I can get that information use dot notation with It. but It can't. UserInfo Model is just api Wrapper now.

  1. I query UserInfo.
await UserInfo.get()
  1. response preview
responseData: {,…}
returnCode: "0000"
returnMessage: "SUCCESS"
  1. pull out data inside responseData object and contain it in new Class
.then(res => {
  const userInfo = new UserInfoImpl(res.responseData)
 })
  1. Query Model is not Data. so I should another type for Models data.
  2. Model just one-time material. It's not a Model, just api wrapper.
  3. But all documents Model name represents It's (cached) data, not api returns or wrapper
    7, So, If I store Model inside Vuex state, I'm not save state, I save api wrapper function.

Is there something I misleading?

I think get() always expect an array/collection response of data. so instead of using get() on the model.

use await UserInfo.find(userID)

eg.

// The reponse here is already wrapped with UserInfo model class.
const  _userInfo = await UserInfo.find(userID)

const _userInfo = new UserInfoImpl(_userInfo)

so if you are using spatie/laravel-query-builder in your Backend there is no need to desctructure the reponse data if you are using the find() method, the data preporty are already wrapped with the Model instance.

@baramofme It has to do with @ronssij explained. It is more about conventions. It is out of scope. Feel free to open new issues if you have any questions.