Skip to content

Commit

Permalink
feat: allow to clear reference values
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtek-krysiak committed Aug 27, 2020
1 parent 5a9dcb3 commit f60e61d
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion example-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"typescript": "3.9.7"
},
"dependencies": {
"admin-bro": "^3.0.0",
"admin-bro": "^3.1.0-beta.3",
"@admin-bro/express": "^3.0.0",
"@admin-bro/typeorm": "^1.0.1",
"express": "^4.17.1",
Expand Down
8 changes: 4 additions & 4 deletions example-app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1350,10 +1350,10 @@ accepts@~1.3.7:
mime-types "~2.1.24"
negotiator "0.6.2"

admin-bro@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/admin-bro/-/admin-bro-3.0.0.tgz#e6f6238672ab7ec46debd008eab6e6a1299fe59b"
integrity sha512-fXnPn/BFBSrib1oAn65kG6LhxE6WAH9QVsLjGw+gMut6j4l9uNloodrgxuERHMksMMDmO5pMzmCOUuqw3LmRuw==
admin-bro@^3.1.0-beta.3:
version "3.1.0-beta.3"
resolved "https://registry.yarnpkg.com/admin-bro/-/admin-bro-3.1.0-beta.3.tgz#d0677edec228dcb251e74758f22dc71aed685784"
integrity sha512-Dxccv+07bmUSWlyA5TtXoX/jqCaJE65GESBFBfbJHEbr/28CukK//lRAqPBhyNQWQAtsP8sot7kcelrDZ5Jm4w==
dependencies:
"@admin-bro/design-system" "^1.3.3"
"@babel/core" "^7.10.2"
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"test": "mocha -r ts-node/register ./spec/**/*.spec.ts",
"ts-node": "ts-node",
"lint": "eslint './src/**/*.{ts,js}' './spec/**/*.{ts,js}' './example-app/**/*.{ts,js}' --ignore-pattern 'build' --ignore-pattern 'yarn.lock'",
"check:all": "yarn lint && yarn test && yarn build",
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
"release": "semantic-release"
},
Expand All @@ -33,15 +34,15 @@
"author": "Artem Zabolotnyi <1arteha1@gmail.com>",
"license": "MIT",
"peerDependencies": {
"admin-bro": ">=3.0.0",
"admin-bro": "^3.1.0-beta.3",
"typeorm": ">=0.2.1"
},
"optionalDependencies": {},
"devDependencies": {
"@types/chai": "^4.2.4",
"@types/mocha": "^5.2.7",
"@types/node": "12.0.10",
"admin-bro": ">=3.0.0",
"admin-bro": "^3.1.0-beta.3",
"chai": "^4.2.0",
"class-validator": "^0.11.0",
"mocha": "^6.2.2",
Expand Down
4 changes: 2 additions & 2 deletions spec/entities/Car.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ export class Car extends BaseEntity {
})
public carType: CarType;

@ManyToOne((type) => CarDealer, (carDealer) => carDealer.cars)
@ManyToOne(() => CarDealer, (carDealer) => carDealer.cars)
public carDealer: CarDealer;

@RelationId((car: Car) => car.carDealer)
public carDealerId: number;

@ManyToOne((type) => CarBuyer, (carBuyer) => carBuyer.cars)
@ManyToOne(() => CarBuyer, (carBuyer) => carBuyer.cars)
public carBuyer: CarBuyer;

@RelationId((car: Car) => car.carBuyer)
Expand Down
2 changes: 1 addition & 1 deletion spec/entities/CarBuyer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export class CarBuyer extends BaseEntity {
@IsDefined()
public name: string;

@OneToMany((type) => Car, (car) => car.carDealer)
@OneToMany(() => Car, (car) => car.carDealer)
public cars: Array<Car>;
}
2 changes: 1 addition & 1 deletion spec/entities/CarDealer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export class CarDealer extends BaseEntity {
@IsDefined()
public name: string;

@OneToMany((type) => Car, (car) => car.carDealer)
@OneToMany(() => Car, (car) => car.carDealer)
public cars: Array<Car>;
}
21 changes: 12 additions & 9 deletions src/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class Resource extends BaseResource {
const property = this.property(key)

// eslint-disable-next-line no-continue
if (!(property && param)) continue
if (!(property && param !== undefined)) continue

const type = property.type()

Expand All @@ -172,14 +172,17 @@ export class Resource extends BaseResource {
}

if (type === 'reference') {
// references cannot be stored as an IDs in typeorm, so in order to mimic this) and
// not fetching reference resource) change this:
// { postId: "1" }
// to that:
// { post: { id: 1 } }

const id = (property.column.type === Number) ? Number(param) : param
preparedParams[property.column.propertyName] = { id }
if (param === null) {
preparedParams[property.column.propertyName] = null
} else {
// references cannot be stored as an IDs in typeorm, so in order to mimic this) and
// not fetching reference resource) change this:
// { postId: "1" }
// to that:
// { post: { id: 1 } }
const id = (property.column.type === Number) ? Number(param) : param
preparedParams[property.column.propertyName] = { id }
}
}
}
return preparedParams
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1801,10 +1801,10 @@ acorn@^7.3.1:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.0.tgz#e1ad486e6c54501634c6c397c5c121daa383607c"
integrity sha512-+G7P8jJmCHr+S+cLfQxygbWhXy+8YTVGzAkpEbcLo2mLoL7tij/VG41QSHACSf5QgYRhMZYHuNc6drJaO0Da+w==

admin-bro@>=3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/admin-bro/-/admin-bro-3.0.0.tgz#e6f6238672ab7ec46debd008eab6e6a1299fe59b"
integrity sha512-fXnPn/BFBSrib1oAn65kG6LhxE6WAH9QVsLjGw+gMut6j4l9uNloodrgxuERHMksMMDmO5pMzmCOUuqw3LmRuw==
admin-bro@^3.1.0-beta.3:
version "3.1.0-beta.3"
resolved "https://registry.yarnpkg.com/admin-bro/-/admin-bro-3.1.0-beta.3.tgz#d0677edec228dcb251e74758f22dc71aed685784"
integrity sha512-Dxccv+07bmUSWlyA5TtXoX/jqCaJE65GESBFBfbJHEbr/28CukK//lRAqPBhyNQWQAtsP8sot7kcelrDZ5Jm4w==
dependencies:
"@admin-bro/design-system" "^1.3.3"
"@babel/core" "^7.10.2"
Expand Down

0 comments on commit f60e61d

Please sign in to comment.