Skip to content

Commit d604c61

Browse files
committed
fix: fix serial type error, console log errors
1 parent 5fb695d commit d604c61

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/Property.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ export class Property extends BaseProperty {
2626
return !!this.column.primary;
2727
}
2828

29+
public isRequired(): boolean {
30+
if (this.column.nullable === false) return true;
31+
32+
return false;
33+
}
34+
2935
public isSortable(): boolean {
3036
return this.type() !== 'reference';
3137
}
@@ -53,12 +59,15 @@ export class Property extends BaseProperty {
5359
}
5460

5561
public type(): PropertyType {
56-
let type: PropertyType = DATA_TYPES[this.column.columnTypes[0]];
62+
let type: PropertyType = DATA_TYPES[this.column.columnTypes[0]]
63+
|| DATA_TYPES[this.column.type];
5764

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

6067
// eslint-disable-next-line no-console
61-
if (!type) { console.warn(`Unhandled type: ${this.column.type}`); }
68+
if (!type) {
69+
console.warn(`Unhandled type: ${this.column.type}`);
70+
}
6271

6372
return type;
6473
}

src/Resource.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ export class Resource extends BaseResource {
181181
try {
182182
await this.orm.em.persistAndFlush(instance);
183183
} catch (error) {
184-
if (error.name === 'QueryFailedError') {
184+
// TODO: figure out how to get column name from MikroORM's error metadata
185+
// It currently seems to return only whole Entity
186+
console.log(error);
187+
if (error.name === 'QueryFailedError' || error.name === 'ValidationError') {
185188
throw new ValidationError({
186189
[error.column]: {
187190
type: 'QueryFailedError',

src/utils/data-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const NUMBER = [
2626
'fixed',
2727
'numeric',
2828
'number',
29+
'serial',
2930

3031
// WithWidthColumnType:
3132
'tinyint',

0 commit comments

Comments
 (0)