Skip to content

Commit

Permalink
chore: migrate to latest admin bro version
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtek-krysiak committed Apr 3, 2020
1 parent 546573a commit 107f0ea
Show file tree
Hide file tree
Showing 4 changed files with 1,248 additions and 595 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "admin-bro-typeorm",
"version": "0.1.5",
"version": "1.0.0",
"description": "TypeORM adapter for AdminBro",
"keywords": [
"typeorm",
Expand Down Expand Up @@ -28,15 +28,15 @@
"author": "Artem Zabolotnyi <1arteha1@gmail.com>",
"license": "MIT",
"peerDependencies": {
"admin-bro": ">=1.6.2",
"admin-bro": ">=2.2.0",
"typeorm": ">=0.2.1"
},
"optionalDependencies": {},
"devDependencies": {
"@types/chai": "^4.2.4",
"@types/mocha": "^5.2.7",
"@types/node": "12.0.10",
"admin-bro": "^1.6.2",
"admin-bro": ">=2.2.0",
"chai": "^4.2.0",
"class-validator": "^0.11.0",
"mocha": "^6.2.2",
Expand Down
6 changes: 3 additions & 3 deletions src/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class Resource extends BaseResource
await this.model.delete(pk);
} catch (error) {
if (error.name === "QueryFailedError") {
throw new ValidationError(`${this.name()} validation failed`, {}, {
throw new ValidationError({}, {
type: "QueryFailedError",
message: error.message
});
Expand Down Expand Up @@ -198,14 +198,14 @@ export class Resource extends BaseResource
message: Object.values(error.constraints)[0],
}
}), {});
throw new ValidationError(`${this.name()} validation failed`, validationErrors);
throw new ValidationError(validationErrors);
}
}
try {
await instance.save();
} catch (error) {
if (error.name === "QueryFailedError") {
throw new ValidationError(`${this.name()} validation failed`, {
throw new ValidationError({
[error.column]: {
type: "QueryFailedError",
message: error.message
Expand Down
8 changes: 4 additions & 4 deletions src/utils/convertFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export function convertFilter(filter?: Filter): FindConditions<BaseEntity>
{
const one = filters[ n ];
if ([ "boolean", "number", "float", "object", "array" ].includes(one.property.type()))
where[ n ] = safeParseJSON(one.value);
where[ n ] = safeParseJSON(one.value as string);
else if ([ "date", "datetime" ].includes(one.property.type()))
{
if (one.value.from && one.value.to)
if (typeof one.value !== "string" && one.value.from && one.value.to)
where[ n ] = Between(new Date(one.value.from), new Date(one.value.to));
else if (one.value.from)
else if (typeof one.value !== "string" && one.value.from)
where[ n ] = MoreThanOrEqual(new Date(one.value.from));
else if (one.value.to)
else if (typeof one.value !== "string" && one.value.to)
where[ n ] = LessThanOrEqual(new Date(one.value.to));
}
else
Expand Down
Loading

0 comments on commit 107f0ea

Please sign in to comment.