Skip to content

Commit 6595e83

Browse files
authored
Merge pull request #7 from klerick/fix-transform
fix(json-api-nestjs): fix transform service
2 parents fddb7f2 + d30d684 commit 6595e83

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

libs/json-api-nestjs/project.json

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77
"deploy": {
88
"executor": "./dist/libs/semrel:release",
99
"dependsOn": [
10-
{ "projects": "self", "target": "buildSemRel"},
11-
{ "projects": "self", "target": "release" }
10+
{
11+
"projects": "self",
12+
"target": "buildSemRel"
13+
},
14+
{
15+
"projects": "self",
16+
"target": "release"
17+
}
1218
],
1319
"options": {
1420
"npm": {
@@ -18,7 +24,12 @@
1824
},
1925
"release": {
2026
"executor": "nx:run-commands",
21-
"dependsOn": [{ "projects": "self", "target": "build" }],
27+
"dependsOn": [
28+
{
29+
"projects": "self",
30+
"target": "build"
31+
}
32+
],
2233
"options": {
2334
"commands": [
2435
"echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}'>./dist/libs/json-api-nestjs/.npmrc"
@@ -30,26 +41,20 @@
3041
"buildSemRel": {
3142
"executor": "nx:run-commands",
3243
"options": {
33-
"commands": [
34-
"npx nx build semrel"
35-
],
44+
"commands": ["npx nx build semrel"],
3645
"cwd": "./",
3746
"parallel": false
3847
}
3948
},
4049
"build": {
4150
"executor": "@nrwl/js:tsc",
42-
"outputs": [
43-
"{options.outputPath}"
44-
],
51+
"outputs": ["{options.outputPath}"],
4552
"options": {
4653
"outputPath": "dist/libs/json-api-nestjs",
4754
"tsConfig": "libs/json-api-nestjs/tsconfig.lib.json",
4855
"packageJson": "libs/json-api-nestjs/package.json",
4956
"main": "libs/json-api-nestjs/src/index.ts",
50-
"assets": [
51-
"libs/json-api-nestjs/*.md"
52-
]
57+
"assets": ["libs/json-api-nestjs/*.md"]
5358
}
5459
},
5560
"publish": {
@@ -66,20 +71,14 @@
6671
},
6772
"lint": {
6873
"executor": "@nrwl/linter:eslint",
69-
"outputs": [
70-
"{options.outputFile}"
71-
],
74+
"outputs": ["{options.outputFile}"],
7275
"options": {
73-
"lintFilePatterns": [
74-
"libs/json-api-nestjs/**/*.ts"
75-
]
76+
"lintFilePatterns": ["libs/json-api-nestjs/**/*.ts"]
7677
}
7778
},
7879
"test": {
7980
"executor": "@nrwl/jest:jest",
80-
"outputs": [
81-
"coverage/libs/json-api-nestjs"
82-
],
81+
"outputs": ["coverage/libs/json-api-nestjs"],
8382
"options": {
8483
"jestConfig": "libs/json-api-nestjs/jest.config.ts",
8584
"passWithNoTests": true

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ export class TransformMixinService<T> {
7878
this.repository.metadata.relations.reduce((acum, i) => {
7979
switch (i.relationType) {
8080
case 'one-to-one':
81-
case 'one-to-many':
81+
case 'many-to-one':
8282
acum[i.propertyName] = false;
8383
break;
8484
case 'many-to-many':
85-
case 'many-to-one':
85+
case 'one-to-many':
8686
acum[i.propertyName] = true;
8787
break;
8888
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ export async function getOne<T>(
5959
const result = await builder
6060
.select([...fieldsSelect])
6161
.where({ id })
62-
.getRawOne();
62+
.getRawMany();
6363

64-
if (!result) {
64+
if (result.length === 0) {
6565
throw new NotFoundException({
6666
detail: `Resource '${preparedResourceName}' with id '${id}' does not exist`,
6767
});
6868
}
6969
const callQuery = Date.now() - startTime;
70-
const itemResult = this.transform.transformRawData([result]);
70+
const itemResult = this.transform.transformRawData(result);
7171
const data = this.transform.transformData(itemResult[0], include);
7272
const included = this.transform.transformInclude(itemResult);
7373

0 commit comments

Comments
 (0)