-
Notifications
You must be signed in to change notification settings - Fork 7
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
Object is empty inside client after upgrade to v3 #1200
Comments
If I understand this correctly, if you call Can you also send the relevant part of the User model? From the lib perspective, it shouldn't matter where the request is coming from, as long as it uses request/fetchOne/fetchMany, if it gets the same response, it should initialize in the same way. |
I haven't tried it when calling via the fetch service, I have just followed the setup guide and it is mentioned there to override the fetch with the custom fetch service User model: import {BaseModel} from './base-model';
import {Permission} from './permission';
import {Company} from './company';
import {Role} from './role';
import {Revision} from './revision';
import {Field} from '@datx/core';
export class User extends BaseModel {
static type: string = 'users';
static endpoint: string = 'users';
@Field() public name: string;
@Field() public email: string;
@Field() public given_name: string;
@Field() public family_name: string;
@Field({toOne: Company}) public company: Company;
@Field({toMany: Role}) public roles: Role[] = [];
@Field({toMany: Revision}) public revisions: Revision[] = [];
public permissions: Permission[] = [];
} |
Need more information from me? |
Sorry for the late response. I see now that you're using the httpClient request. In order for DatX response parsing to work, you should either use the fetch service or do requests directly from the collection, e.g. |
I am using the collection to call the request method export class UsersService extends CollectionService<User, AppCollection> {
protected ctor = User;
constructor() {
super();
}
public me(include?: string): Observable<User> {
const options: IRequestOptions = {} as IRequestOptions;
options.queryParams = {};
if (include) {
options.queryParams.include = include;
}
return this.collection.request('users/me', HttpMethod.Get, null, options).pipe(map((response: Response) => response.data));
}
} |
In the model, you shouldn't directly assign the default values: @Field({toMany: Role}) public roles: Role[] = []; because the transpilation actually breaks this flow. Instead, you should use @Field({toMany: Role, defaultValue: []}) public roles!: Role[]; |
Have updated the user model to: import {BaseModel} from './base-model';
import {Permission} from './permission';
import {Company} from './company';
import {Role} from './role';
import {Revision} from './revision';
import {Field} from '@datx/core';
export class User extends BaseModel {
static type: string = 'users';
static endpoint: string = 'users';
@Field() public name: string;
@Field() public email: string;
@Field() public given_name: string;
@Field() public family_name: string;
@Field({toOne: Company}) public company: Company;
@Field({toMany: Role}) public roles!: Role[];
@Field({toMany: Revision}) public revisions!: Revision[];
public permissions!: Permission[];
} and these are the request I am sending to test: this.customFetchService.fetch(HttpMethod.Get, 'api/v1/users/me?include=roles.permissions,revisions', null, null).then();
return this.collection.request('users/me', HttpMethod.Get, null, options).pipe(map((response: Response) => {
console.log(response);
return response.data;
})); I have a console log inside the fetch method. and these are the responses {
"headers":{
"normalizedNames":{
},
"lazyUpdate":null,
"lazyInit":null,
"headers":{
}
},
"status":200,
"statusText":"OK",
"url":"http://localhost/api/v1/users/me?include=roles.permissions,revisions",
"ok":true,
"type":4,
"body":{
"jsonapi":{
"version":"1.0"
},
"links":{
"self":"http://localhost/api/v1/users/1"
},
"data":{
"type":"users",
"id":"1",
"attributes":{
"name":"Stefan Willems",
"email":"[email protected]",
"given_name":"Stefan",
"family_name":"Willems",
"created_at":"2023-09-25T10:04:06.000000Z",
"updated_at":"2023-09-25T10:04:06.000000Z"
},
"relationships":{
"roles":{
"links":{
"related":"http://localhost/api/v1/users/1/roles",
"self":"http://localhost/api/v1/users/1/relationships/roles"
},
"data":[
{
"type":"roles",
"id":"2"
}
]
},
"revisions":{
"links":{
"related":"http://localhost/api/v1/users/1/revisions",
"self":"http://localhost/api/v1/users/1/relationships/revisions"
},
"data":[
]
}
},
"links":{
"self":"http://localhost/api/v1/users/1"
}
},
"included":[
{
"type":"roles",
"id":"2",
"attributes":{
"name":"user"
},
"relationships":{
"permissions":{
"links":{
"related":"http://localhost/api/v1/roles/2/permissions",
"self":"http://localhost/api/v1/roles/2/relationships/permissions"
},
"data":[
{
"type":"permissions",
"id":"1"
},
{
"type":"permissions",
"id":"10"
},
{
"type":"permissions",
"id":"11"
},
{
"type":"permissions",
"id":"12"
},
{
"type":"permissions",
"id":"13"
},
{
"type":"permissions",
"id":"14"
}
]
}
},
"links":{
"self":"http://localhost/api/v1/roles/2"
}
},
{
"type":"permissions",
"id":"1",
"attributes":{
"name":"login-permission"
},
"links":{
"self":"http://localhost/api/v1/permissions/1"
}
},
{
"type":"permissions",
"id":"10",
"attributes":{
"name":"file-read"
},
"links":{
"self":"http://localhost/api/v1/permissions/10"
}
},
{
"type":"permissions",
"id":"11",
"attributes":{
"name":"file-create"
},
"links":{
"self":"http://localhost/api/v1/permissions/11"
}
},
{
"type":"permissions",
"id":"12",
"attributes":{
"name":"file-delete"
},
"links":{
"self":"http://localhost/api/v1/permissions/12"
}
},
{
"type":"permissions",
"id":"13",
"attributes":{
"name":"file-upload"
},
"links":{
"self":"http://localhost/api/v1/permissions/13"
}
},
{
"type":"permissions",
"id":"14",
"attributes":{
"name":"file-update"
},
"links":{
"self":"http://localhost/api/v1/permissions/14"
}
}
]
}
} {
"__internal": {
"response": {
"data": {
"jsonapi": {
"version": "1.0"
},
"links": {
"self": "http://localhost/api/v1/users/1"
},
"data": {
"type": "users",
"id": "1",
"attributes": {
"name": "Stefan Willems",
"email": "[email protected]",
"given_name": "Stefan",
"family_name": "Willems",
"created_at": "2023-09-25T10:04:06.000000Z",
"updated_at": "2023-09-25T10:04:06.000000Z"
},
"relationships": {
"roles": {
"links": {
"related": "http://localhost/api/v1/users/1/roles",
"self": "http://localhost/api/v1/users/1/relationships/roles"
},
"data": [
{
"type": "roles",
"id": "2"
}
]
},
"revisions": {
"links": {
"related": "http://localhost/api/v1/users/1/revisions",
"self": "http://localhost/api/v1/users/1/relationships/revisions"
},
"data": []
}
},
"links": {
"self": "http://localhost/api/v1/users/1"
}
},
"included": [
{
"type": "roles",
"id": "2",
"attributes": {
"name": "user"
},
"relationships": {
"permissions": {
"links": {
"related": "http://localhost/api/v1/roles/2/permissions",
"self": "http://localhost/api/v1/roles/2/relationships/permissions"
},
"data": [
{
"type": "permissions",
"id": "1"
},
{
"type": "permissions",
"id": "10"
},
{
"type": "permissions",
"id": "11"
},
{
"type": "permissions",
"id": "12"
},
{
"type": "permissions",
"id": "13"
},
{
"type": "permissions",
"id": "14"
}
]
}
},
"links": {
"self": "http://localhost/api/v1/roles/2"
}
},
{
"type": "permissions",
"id": "1",
"attributes": {
"name": "login-permission"
},
"links": {
"self": "http://localhost/api/v1/permissions/1"
}
},
{
"type": "permissions",
"id": "10",
"attributes": {
"name": "file-read"
},
"links": {
"self": "http://localhost/api/v1/permissions/10"
}
},
{
"type": "permissions",
"id": "11",
"attributes": {
"name": "file-create"
},
"links": {
"self": "http://localhost/api/v1/permissions/11"
}
},
{
"type": "permissions",
"id": "12",
"attributes": {
"name": "file-delete"
},
"links": {
"self": "http://localhost/api/v1/permissions/12"
}
},
{
"type": "permissions",
"id": "13",
"attributes": {
"name": "file-upload"
},
"links": {
"self": "http://localhost/api/v1/permissions/13"
}
},
{
"type": "permissions",
"id": "14",
"attributes": {
"name": "file-update"
},
"links": {
"self": "http://localhost/api/v1/permissions/14"
}
}
]
},
"headers": {
"normalizedNames": {},
"lazyUpdate": null,
"lazyInit": null,
"headers": {}
},
"requestHeaders": {
"Content-Type": "application/vnd.api+json",
"Accept": "application/vnd.api+json"
},
"status": 200,
"collection": {
"models": [
{
"__META__": {
"type": "roles",
"id": "2",
"fields": {
"name": {
"referenceDef": false
},
"permissions": {
"referenceDef": {
"type": 1,
"model": "permissions"
}
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/roles/2"
},
"networkPersisted": true,
"jsonapiRefLinks": {
"permissions": {
"related": "http://localhost/api/v1/roles/2/permissions",
"self": "http://localhost/api/v1/roles/2/relationships/permissions"
}
},
"jsonapiRefMeta": {}
},
"permissions": [
{
"type": "permissions",
"id": "1"
},
{
"type": "permissions",
"id": "10"
},
{
"type": "permissions",
"id": "11"
},
{
"type": "permissions",
"id": "12"
},
{
"type": "permissions",
"id": "13"
},
{
"type": "permissions",
"id": "14"
}
]
},
{
"__META__": {
"type": "permissions",
"id": "1",
"fields": {
"name": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/permissions/1"
},
"networkPersisted": true
}
},
{
"__META__": {
"type": "permissions",
"id": "10",
"fields": {
"name": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/permissions/10"
},
"networkPersisted": true
}
},
{
"__META__": {
"type": "permissions",
"id": "11",
"fields": {
"name": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/permissions/11"
},
"networkPersisted": true
}
},
{
"__META__": {
"type": "permissions",
"id": "12",
"fields": {
"name": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/permissions/12"
},
"networkPersisted": true
}
},
{
"__META__": {
"type": "permissions",
"id": "13",
"fields": {
"name": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/permissions/13"
},
"networkPersisted": true
}
},
{
"__META__": {
"type": "permissions",
"id": "14",
"fields": {
"name": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/permissions/14"
},
"networkPersisted": true
}
},
{
"__META__": {
"type": "users",
"id": "1",
"fields": {
"name": {
"referenceDef": false
},
"email": {
"referenceDef": false
},
"given_name": {
"referenceDef": false
},
"family_name": {
"referenceDef": false
},
"company": {
"referenceDef": {
"type": 0,
"model": "companies"
}
},
"roles": {
"referenceDef": {
"type": 1,
"model": "roles"
}
},
"revisions": {
"referenceDef": {
"type": 1,
"model": "revisions"
}
},
"created_at": {
"referenceDef": false
},
"updated_at": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/users/1"
},
"networkPersisted": true,
"jsonapiRefLinks": {
"roles": {
"related": "http://localhost/api/v1/users/1/roles",
"self": "http://localhost/api/v1/users/1/relationships/roles"
},
"revisions": {
"related": "http://localhost/api/v1/users/1/revisions",
"self": "http://localhost/api/v1/users/1/relationships/revisions"
}
},
"jsonapiRefMeta": {}
},
"company": null,
"roles": [
{
"id": "2",
"type": "roles"
}
],
"revisions": [],
"created_at": "2023-09-25T10:04:06.000000Z",
"updated_at": "2023-09-25T10:04:06.000000Z"
}
],
"views": {},
"cache": []
}
},
"views": [],
"options": {
"queryParams": {
"include": "roles.permissions,revisions"
},
"fetchOptions": {
"takeUntil$": {
"closed": false,
"currentObservers": [],
"observers": [],
"isStopped": true,
"hasError": false,
"thrownError": null
}
}
},
"meta": {},
"links": {
"self": "http://localhost/api/v1/users/1"
},
"jsonapi": {
"version": "1.0"
},
"headers": {
"normalizedNames": {},
"lazyUpdate": null,
"lazyInit": null,
"headers": {}
},
"requestHeaders": {
"Content-Type": "application/vnd.api+json",
"Accept": "application/vnd.api+json"
},
"status": 200
},
"__cache": {},
"collection": {
"models": [
{
"__META__": {
"type": "roles",
"id": "2",
"fields": {
"name": {
"referenceDef": false
},
"permissions": {
"referenceDef": {
"type": 1,
"model": "permissions"
}
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/roles/2"
},
"networkPersisted": true,
"jsonapiRefLinks": {
"permissions": {
"related": "http://localhost/api/v1/roles/2/permissions",
"self": "http://localhost/api/v1/roles/2/relationships/permissions"
}
},
"jsonapiRefMeta": {}
},
"permissions": [
{
"type": "permissions",
"id": "1"
},
{
"type": "permissions",
"id": "10"
},
{
"type": "permissions",
"id": "11"
},
{
"type": "permissions",
"id": "12"
},
{
"type": "permissions",
"id": "13"
},
{
"type": "permissions",
"id": "14"
}
]
},
{
"__META__": {
"type": "permissions",
"id": "1",
"fields": {
"name": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/permissions/1"
},
"networkPersisted": true
}
},
{
"__META__": {
"type": "permissions",
"id": "10",
"fields": {
"name": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/permissions/10"
},
"networkPersisted": true
}
},
{
"__META__": {
"type": "permissions",
"id": "11",
"fields": {
"name": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/permissions/11"
},
"networkPersisted": true
}
},
{
"__META__": {
"type": "permissions",
"id": "12",
"fields": {
"name": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/permissions/12"
},
"networkPersisted": true
}
},
{
"__META__": {
"type": "permissions",
"id": "13",
"fields": {
"name": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/permissions/13"
},
"networkPersisted": true
}
},
{
"__META__": {
"type": "permissions",
"id": "14",
"fields": {
"name": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/permissions/14"
},
"networkPersisted": true
}
},
{
"__META__": {
"type": "users",
"id": "1",
"fields": {
"name": {
"referenceDef": false
},
"email": {
"referenceDef": false
},
"given_name": {
"referenceDef": false
},
"family_name": {
"referenceDef": false
},
"company": {
"referenceDef": {
"type": 0,
"model": "companies"
}
},
"roles": {
"referenceDef": {
"type": 1,
"model": "roles"
}
},
"revisions": {
"referenceDef": {
"type": 1,
"model": "revisions"
}
},
"created_at": {
"referenceDef": false
},
"updated_at": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/users/1"
},
"networkPersisted": true,
"jsonapiRefLinks": {
"roles": {
"related": "http://localhost/api/v1/users/1/roles",
"self": "http://localhost/api/v1/users/1/relationships/roles"
},
"revisions": {
"related": "http://localhost/api/v1/users/1/revisions",
"self": "http://localhost/api/v1/users/1/relationships/revisions"
}
},
"jsonapiRefMeta": {}
},
"company": null,
"roles": [
{
"id": "2",
"type": "roles"
}
],
"revisions": [],
"created_at": "2023-09-25T10:04:06.000000Z",
"updated_at": "2023-09-25T10:04:06.000000Z"
}
],
"views": {},
"cache": []
},
"__data": {
"id": "1",
"type": "users"
}
} |
when console logging the reponse.data I get the same empty User object: {
"__META__": {
"type": "users",
"id": "1",
"fields": {
"name": {
"referenceDef": false
},
"email": {
"referenceDef": false
},
"given_name": {
"referenceDef": false
},
"family_name": {
"referenceDef": false
},
"company": {
"referenceDef": {
"type": 0,
"model": "companies"
}
},
"roles": {
"referenceDef": {
"type": 1,
"model": "roles"
}
},
"revisions": {
"referenceDef": {
"type": 1,
"model": "revisions"
}
},
"created_at": {
"referenceDef": false
},
"updated_at": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/users/1"
},
"networkPersisted": true,
"jsonapiRefLinks": {
"roles": {
"related": "http://localhost/api/v1/users/1/roles",
"self": "http://localhost/api/v1/users/1/relationships/roles"
},
"revisions": {
"related": "http://localhost/api/v1/users/1/revisions",
"self": "http://localhost/api/v1/users/1/relationships/revisions"
}
},
"jsonapiRefMeta": {}
},
"company": null,
"roles": [
{
"id": "2",
"type": "roles"
}
],
"revisions": [],
"created_at": "2023-09-25T10:04:06.000000Z",
"updated_at": "2023-09-25T10:04:06.000000Z"
} |
are there any workaround around this problem or should I just do custom requests via the httpclient instead of the datx collection? |
I have put a console.log inside the fetch function inside the custom fetch service and see it isn't called, is this normal behavior? |
Currently I am trying to handle the request via the custom fetch service. Wherein I found the sync is not working as intended: return from(this.customFetchService.fetch(HttpMethod.Get, 'api/v1/users/me?include=roles.permissions,revisions', null, null)).pipe(
map((responseObject: IResponseObject) => {
const response: IResponse = responseObject.data as IResponse
const user = this.collection.sync(response);
console.log(user);
return response.data;
})
); {
"__META__": {
"type": "users",
"id": "1",
"fields": {
"name": {
"referenceDef": false
},
"email": {
"referenceDef": false
},
"given_name": {
"referenceDef": false
},
"family_name": {
"referenceDef": false
},
"company": {
"referenceDef": {
"type": 0,
"model": "companies"
}
},
"roles": {
"referenceDef": {
"type": 1,
"model": "roles"
}
},
"revisions": {
"referenceDef": {
"type": 1,
"model": "revisions"
}
},
"created_at": {
"referenceDef": false
},
"updated_at": {
"referenceDef": false
}
},
"jsonapiLinks": {
"self": "http://localhost/api/v1/users/1"
},
"networkPersisted": true,
"jsonapiRefLinks": {
"roles": {
"related": "http://localhost/api/v1/users/1/roles",
"self": "http://localhost/api/v1/users/1/relationships/roles"
},
"revisions": {
"related": "http://localhost/api/v1/users/1/revisions",
"self": "http://localhost/api/v1/users/1/relationships/revisions"
}
},
"jsonapiRefMeta": {}
},
"company": null,
"roles": [
{
"id": "2",
"type": "roles"
}
],
"revisions": [],
"created_at": "2023-09-25T10:04:06.000000Z",
"updated_at": "2023-09-25T10:04:06.000000Z"
} and the IResponse is as follows: {
"type": "users",
"id": "1",
"attributes": {
"name": "Stefan Willems",
"email": "[email protected]",
"given_name": "Stefan",
"family_name": "Willems",
"created_at": "2023-09-25T10:04:06.000000Z",
"updated_at": "2023-09-25T10:04:06.000000Z"
},
"relationships": {
"roles": {
"links": {
"related": "http://localhost/api/v1/users/1/roles",
"self": "http://localhost/api/v1/users/1/relationships/roles"
},
"data": [
{
"type": "roles",
"id": "2"
}
]
},
"revisions": {
"links": {
"related": "http://localhost/api/v1/users/1/revisions",
"self": "http://localhost/api/v1/users/1/relationships/revisions"
},
"data": []
}
},
"links": {
"self": "http://localhost/api/v1/users/1"
}
} |
I am reverting every version of the package to v2 because v3 isn't workable for me |
any progress @DarkoKukovec? |
Used libraries
core, jsonapi, jsonapi-angular, utils
Library version(s)
Issue description
When retrieving the model via a custom url the data is not being set inside the object.
Whereas I retrieve all the users after, the data is getting filled properly.
Response from api
Object inside Angular
Request being send from client
App module
Custom Fetch Service
The text was updated successfully, but these errors were encountered: