Skip to content

Commit

Permalink
fix: fix serial type error, console log errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dziraf committed Mar 15, 2022
1 parent 5fb695d commit d604c61
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/Property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export class Property extends BaseProperty {
return !!this.column.primary;
}

public isRequired(): boolean {
if (this.column.nullable === false) return true;

return false;
}

public isSortable(): boolean {
return this.type() !== 'reference';
}
Expand Down Expand Up @@ -53,12 +59,15 @@ export class Property extends BaseProperty {
}

public type(): PropertyType {
let type: PropertyType = DATA_TYPES[this.column.columnTypes[0]];
let type: PropertyType = DATA_TYPES[this.column.columnTypes[0]]
|| DATA_TYPES[this.column.type];

if (this.reference()) { type = 'reference'; }

// eslint-disable-next-line no-console
if (!type) { console.warn(`Unhandled type: ${this.column.type}`); }
if (!type) {
console.warn(`Unhandled type: ${this.column.type}`);
}

return type;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ export class Resource extends BaseResource {
try {
await this.orm.em.persistAndFlush(instance);
} catch (error) {
if (error.name === 'QueryFailedError') {
// TODO: figure out how to get column name from MikroORM's error metadata
// It currently seems to return only whole Entity
console.log(error);
if (error.name === 'QueryFailedError' || error.name === 'ValidationError') {
throw new ValidationError({
[error.column]: {
type: 'QueryFailedError',
Expand Down
1 change: 1 addition & 0 deletions src/utils/data-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const NUMBER = [
'fixed',
'numeric',
'number',
'serial',

// WithWidthColumnType:
'tinyint',
Expand Down

0 comments on commit d604c61

Please sign in to comment.