@return {?}
*/
Resource.prototype.toObject = function (params) {
params = Object.assign({}, Base.ParamsResource, params);
/ @type {?} */
var relationships = {};
/* @type {?} /
var included = [];
/ @type {?} */
var included_ids = []; // just for control don't repeat any resource
// REALTIONSHIPS
for (var relation_alias in this.relationships) {
/ @type {?} */
var relationship = this.relationships[relation_alias];
if (relationship instanceof DocumentCollection) {
// @TODO PABLO: definir cuál va a ser la propiedd indispensable para guardar la relación
if (!relationship.builded && (!relationship.data || relationship.data.length === 0)) {
delete relationships[relation_alias];
} else {
relationships[relation_alias] = {data: []};
}
for (var _i = 0, _a = relationship.data; _i < _a.length; _i++) {
var resource = _a[_i];
/* @type {?} /
var reational_object = {
id: resource.id,
type: resource.type
};
relationships[relation_alias].data.push(reational_object);
/ @type {?} */
var temporalid = resource.type + '' + resource.id;
if (included_ids.indexOf(temporal_id) === -1 && params.include && params.include.indexOf(relation_alias) !== -1) {
included_ids.push(temporal_id);
included.push(resource.toObject({}).data);
}
}
//by ehsan Amj if has meta
if(Object.keys(relationship.meta).length >0)
{
relationships[relation_alias]['meta'] = relationship.meta;
}
} else {
// @TODO PABLO: agregué el check de null porque sino fallan las demás condiciones, además es para eliminar la relacxión del back
if (relationship.data === null || relationship.data === undefined) {
relationships[relation_alias] = {data: relationship.data};
continue;
}
if (!(relationship instanceof DocumentResource)) {
console.warn(relationship, ' is not DocumentCollection or DocumentResource');
}
/** @type {?} */
var relationship_data = /** @type {?} */ (relationship.data);
if (relationship.data && !('id' in relationship.data) && Object.keys(relationship.data).length > 0) {
console.warn(relation_alias + ' defined with hasMany:false, but I have a collection');
}
if (relationship_data.id && relationship_data.type) {
relationships[relation_alias] = {
data: {
id: relationship_data.id,
type: relationship_data.type
}
};
// @TODO PABLO: definir cuál va a ser la propiedd indispensable para guardar la relación
// @WARNING: no borrar la verificación de que no sea null... sino no se van a poder borrar
} else if (!relationship.builded && !relationship_data.id && !relationship_data.type) {
delete relationships[relation_alias];
continue;
}
/** @type {?} */
var temporal_id = relationship_data.type + '_' + relationship_data.id;
if (included_ids.indexOf(temporal_id) === -1 && params.include && params.include.indexOf(relation_alias) !== -1) {
included_ids.push(temporal_id);
included.push(relationship_data.toObject({}).data);
}
}
}
/* @type {?} /
var attributes;
if (this.getService() && this.getService().parseToServer) {
attributes = Object.assign({}, this.attributes);
this.getService().parseToServer(attributes);
} else {
attributes = this.attributes;
}
/* @type {?} /
var ret = {
data: {
type: this.type,
id: this.id,
attributes: attributes,
relationships: relationships
}
};
// resource's meta
if (this.meta) {
ret.data.meta = this.meta;
}
// top level meta
if (params.meta) {
ret.meta = params.meta;
}
if (included.length > 0) {
ret.included = included;
}
return ret;
};
Hi You do not work on relationship metas https://jsonapi.org/format/#document-resource-object-relationships please see meta on this part I did it,please update your package:
/**
@return {?} */ Resource.prototype.toObject = function (params) { params = Object.assign({}, Base.ParamsResource, params); / @type {?} */ var relationships = {}; /* @type {?} / var included = []; / @type {?} */ var included_ids = []; // just for control don't repeat any resource // REALTIONSHIPS for (var relation_alias in this.relationships) { / @type {?} */ var relationship = this.relationships[relation_alias]; if (relationship instanceof DocumentCollection) { // @TODO PABLO: definir cuál va a ser la propiedd indispensable para guardar la relación if (!relationship.builded && (!relationship.data || relationship.data.length === 0)) { delete relationships[relation_alias]; } else { relationships[relation_alias] = {data: []}; } for (var _i = 0, _a = relationship.data; _i < _a.length; _i++) { var resource = _a[_i]; /* @type {?} / var reational_object = { id: resource.id, type: resource.type }; relationships[relation_alias].data.push(reational_object); / @type {?} */ var temporalid = resource.type + '' + resource.id; if (included_ids.indexOf(temporal_id) === -1 && params.include && params.include.indexOf(relation_alias) !== -1) { included_ids.push(temporal_id); included.push(resource.toObject({}).data); } }
} else { // @TODO PABLO: agregué el check de null porque sino fallan las demás condiciones, además es para eliminar la relacxión del back if (relationship.data === null || relationship.data === undefined) { relationships[relation_alias] = {data: relationship.data}; continue; } if (!(relationship instanceof DocumentResource)) { console.warn(relationship, ' is not DocumentCollection or DocumentResource'); }
} }
/* @type {?} / var attributes; if (this.getService() && this.getService().parseToServer) { attributes = Object.assign({}, this.attributes); this.getService().parseToServer(attributes); } else { attributes = this.attributes; } /* @type {?} / var ret = { data: { type: this.type, id: this.id, attributes: attributes, relationships: relationships } }; // resource's meta if (this.meta) { ret.data.meta = this.meta; } // top level meta if (params.meta) { ret.meta = params.meta; } if (included.length > 0) { ret.included = included; } return ret; };