Skip to content

Commit 24f93a7

Browse files
authored
Merge pull request #52 from Mites-G/fix/resource-type
fix(json-api-nestjs): Revert resource type when path is overridden
2 parents 39eac1f + d77e670 commit 24f93a7

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

libs/json-api-nestjs/src/lib/mixin/service/transform/transform.mixin.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ export class TransformMixinService<T> {
165165
include: string[] = [],
166166
table = this.currentResourceName
167167
): ResourceData<T> {
168-
const urlTable = this.config?.['overrideRoute'] || camelToKebab(table);
168+
const urlTable = camelToKebab(table);
169+
const routePath = this.config?.['overrideRoute'] || camelToKebab(table);
169170
const attributes = {} as Attributes<Omit<T, 'id'>>;
170171
const relationships = {} as Partial<Relationships<T>>;
171172

@@ -214,13 +215,13 @@ export class TransformMixinService<T> {
214215
...(include.includes(field) && builtData.data ? builtData : {}),
215216
links: {
216217
self: this.getLink(
217-
urlTable,
218+
routePath,
218219
data[this.relationPrimaryField.get(field)],
219220
'relationships',
220221
camelToKebab(field)
221222
),
222223
related: this.getLink(
223-
urlTable,
224+
routePath,
224225
data[this.relationPrimaryField.get(field)],
225226
camelToKebab(field)
226227
),
@@ -240,12 +241,12 @@ export class TransformMixinService<T> {
240241
relationships[itemRelation as string] = {
241242
links: {
242243
self: this.getLink(
243-
urlTable,
244+
routePath,
244245
data[idNameField],
245246
'relationships',
246247
field
247248
),
248-
related: this.getLink(urlTable, data[idNameField], field),
249+
related: this.getLink(routePath, data[idNameField], field),
249250
},
250251
};
251252
}
@@ -255,7 +256,7 @@ export class TransformMixinService<T> {
255256
attributes,
256257
relationships,
257258
links: {
258-
self: this.getLink(urlTable, data[idNameField]),
259+
self: this.getLink(routePath, data[idNameField]),
259260
},
260261
};
261262
}

libs/json-api-nestjs/src/lib/mixin/service/typeorm/methods/get-one/get-one.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,16 @@ describe('GetOne methode test', () => {
155155
});
156156

157157
it('should be correct if route is overriden', async () => {
158-
expect.assertions(2);
158+
expect.assertions(3);
159159
configParam.overrideRoute = 'overridden';
160160

161161
const response = await typeormService.getOne({
162162
query: defaultField,
163163
route: { id: params },
164164
});
165165

166+
expect(response.data['type']).toContain('users');
167+
166168
expect(response.data['relationships'].addresses.links.related).toContain(
167169
'overridden'
168170
);

0 commit comments

Comments
 (0)