Skip to content

Commit 62ed363

Browse files
fixed/type-undefined auto-commit (#379) (#380)
Co-authored-by: Matias <49443249+ahumadamatias@users.noreply.github.com>
1 parent c81b1a7 commit 62ed363

File tree

8 files changed

+3298
-3030
lines changed

8 files changed

+3298
-3030
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
## [2.6.1] - 2026-01-13
10+
11+
- Sync code with 2.5.1
12+
913
## [2.6.0] - 2025-09-24
1014

1115
- Migrate to angular 19
1216

17+
## [2.5.1] - 2025-12-10
18+
19+
### Fixed
20+
21+
- Fixed service undefined ([#379](https://github.com/reyesoft/ngx-jsonapi/pull/379))
22+
1323
## [2.5.0] - 2025-09-16
1424

1525
- Migrate to angular 18

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
"ts-node": "3.1.0",
179179
"typescript": "5.8.2",
180180
"uglify-js": "3.1.9",
181+
"to-fast-properties": "^2.0.0",
181182
"zone.js": "0.15.1"
182183
},
183184
"dependencies": {
@@ -187,5 +188,5 @@
187188
"tsickle": "0.39.1",
188189
"tslib": "^2.6.0"
189190
},
190-
"version": "2.6.0"
191-
}
191+
"version": "2.6.1"
192+
}

projects/ngx-jsonapi-lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-jsonapi",
3-
"version": "2.6.0",
3+
"version": "2.6.1",
44
"description": "JSON API library for Angular",
55
"module": "ngx-jsonapi/@ngx-jsonapi/ngx-jsonapi.es5.js",
66
"es2015": "ngx-jsonapi/@ngx-jsonapi/ngx-jsonapi.js",

projects/ngx-jsonapi-lib/src/lib/resource.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ import { of } from 'rxjs';
1010
import { Book } from './tests/factories/books.service';
1111
import { Service } from './service';
1212

13+
// Inicializar Core.me antes de los tests
14+
beforeAll(() => {
15+
if (!Core.me) {
16+
Core.me = {
17+
getResourceService: jest.fn().mockReturnValue(undefined),
18+
getResourceServiceOrFail: jest.fn(),
19+
registerService: jest.fn(),
20+
resourceServices: {}
21+
} as any;
22+
}
23+
});
24+
1325
describe('resource', () => {
1426
// it('should be reset()', () => {
1527
// resource.id = 'some-id';
@@ -133,6 +145,13 @@ describe('resource.toObject() method', () => {
133145
}
134146
};
135147
jest.spyOn(Resource.prototype, 'getService').mockReturnValue(mocked_service_data as Service<Resource>);
148+
// Configurar Core.me.getResourceService para retornar el servicio mock cuando se busque el tipo 'main'
149+
jest.spyOn(Core.me, 'getResourceService').mockImplementation((type: string) => {
150+
if (type === 'main') {
151+
return mocked_service_data as Service<Resource>;
152+
}
153+
return undefined;
154+
});
136155
let new_resource: Resource = new Resource();
137156
new_resource.type = 'main';
138157
new_resource.id = '1';

projects/ngx-jsonapi-lib/src/lib/resource.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ export class Resource implements ICacheable {
132132

133133
// just for performance dont copy if not necessary
134134
let attributes: any;
135-
if (this.getService() && this.getService().parseToServer) {
135+
let service: Service | undefined = this.getServiceOrUndefined();
136+
if (service && service.parseToServer) {
136137
attributes = { ...{}, ...this.attributes };
137-
this.getService().parseToServer(attributes);
138+
service.parseToServer(attributes);
138139
} else {
139140
attributes = this.attributes;
140141
}
@@ -167,6 +168,7 @@ export class Resource implements ICacheable {
167168

168169
public fill(data_object: IDocumentResource | ICacheableDocumentResource): boolean {
169170
this.id = data_object.data.id || '';
171+
this.type = data_object.data.type || '';
170172

171173
// WARNING: leaving previous line for a tiem because this can produce undesired behavior
172174
// this.attributes = data_object.data.attributes || this.attributes;
@@ -283,6 +285,13 @@ export class Resource implements ICacheable {
283285
return Converter.getServiceOrFail(this.type);
284286
}
285287

288+
/*
289+
@return This resource like a service or undefined if not registered
290+
*/
291+
public getServiceOrUndefined(): Service | undefined {
292+
return Converter.getService(this.type);
293+
}
294+
286295
public delete(): Observable<void> {
287296
return this.getService().delete(this.id);
288297
}

projects/ngx-jsonapi-lib/src/lib/services/json-ripper.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ import { TestFactory } from '../tests/factories/test-factory';
55
import { IElement } from '../data-providers/data-provider';
66
import { ICacheableDocumentResource } from '../interfaces/data-object';
77
import { ICacheableDataCollection } from '../interfaces/data-collection';
8+
import { Core } from '../core';
9+
10+
// Inicializar Core.me antes de los tests
11+
beforeAll(() => {
12+
if (!Core.me) {
13+
Core.me = {
14+
getResourceService: jest.fn().mockReturnValue(undefined),
15+
getResourceServiceOrFail: jest.fn(),
16+
registerService: jest.fn(),
17+
resourceServices: {}
18+
} as any;
19+
}
20+
});
821

922
describe('JsonRipper for resources', () => {
1023
let book: any = TestFactory.getBook('5');

projects/ngx-jsonapi-lib/src/lib/services/resource-relationships-converter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export class ResourceRelationshipsConverter {
7878
// TODO: FE-92 --- this.is a hotfix... check and improve conditions when building has-one relationships
7979
if (!this.relationships_dest[relation_alias].data) {
8080
this.relationships_dest[relation_alias].data = new Resource();
81+
(<Resource>this.relationships_dest[relation_alias].data).type = relation_data_from.data.type;
8182
}
8283

8384
if (relation_data_from.data.id !== (<Resource>this.relationships_dest[relation_alias].data).id) {

0 commit comments

Comments
 (0)