mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-22 07:10:53 +00:00
fix models
This commit is contained in:
parent
e34599d18a
commit
0bdab474de
@ -70,15 +70,24 @@ export default class AnalyticsDataModel extends CommonModel {
|
||||
// check if primary keys are subset of tableColumns
|
||||
|
||||
data.primaryKeys.forEach((primaryKey: string) => {
|
||||
|
||||
const column: AnalyticsTableColumn | undefined = columns.find((column: AnalyticsTableColumn) => {
|
||||
return column.key === primaryKey;
|
||||
});
|
||||
|
||||
if (
|
||||
!columns.find((column: AnalyticsTableColumn) => {
|
||||
return column.key === primaryKey;
|
||||
})
|
||||
!column
|
||||
) {
|
||||
throw new BadDataException(
|
||||
'Primary key ' + primaryKey + ' is not part of tableColumns'
|
||||
);
|
||||
}
|
||||
|
||||
if(!column.required){
|
||||
throw new BadDataException(
|
||||
'Primary key ' + primaryKey + ' is not required. Primary keys must be required.'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
this.primaryKeys = data.primaryKeys;
|
||||
|
@ -59,6 +59,21 @@ export default class CommonModel {
|
||||
value = JSON.parse(value);
|
||||
}
|
||||
|
||||
if (
|
||||
column.type === TableColumnType.Number &&
|
||||
typeof value === 'string'
|
||||
) {
|
||||
value = parseInt(value);
|
||||
}
|
||||
|
||||
// decimal
|
||||
if (
|
||||
column.type === TableColumnType.Decimal &&
|
||||
typeof value === 'string'
|
||||
) {
|
||||
value = parseFloat(value);
|
||||
}
|
||||
|
||||
return (this.data[columnName] = value as any);
|
||||
}
|
||||
throw new BadDataException('Column ' + columnName + ' does not exist');
|
||||
|
@ -215,6 +215,7 @@ export default class StatementGenerator<TBaseModel extends AnalyticsBaseModel> {
|
||||
}
|
||||
|
||||
if (column.type === TableColumnType.Date && value instanceof Date) {
|
||||
|
||||
value = `parseDateTimeBestEffortOrNull('${OneUptimeDate.toString(
|
||||
value as Date
|
||||
)}')`;
|
||||
|
@ -51,7 +51,7 @@ export default class Metric extends AnalyticsBaseModel {
|
||||
key: 'time',
|
||||
title: 'Time',
|
||||
description: 'When did the Metric happen?',
|
||||
required: false,
|
||||
required: true,
|
||||
type: TableColumnType.Date,
|
||||
}),
|
||||
|
||||
@ -68,7 +68,7 @@ export default class Metric extends AnalyticsBaseModel {
|
||||
title: 'Time (in Unix Nano)',
|
||||
description: 'When did the Metric happen?',
|
||||
required: false,
|
||||
type: TableColumnType.Date,
|
||||
type: TableColumnType.Number,
|
||||
}),
|
||||
|
||||
new AnalyticsTableColumn({
|
||||
@ -76,7 +76,7 @@ export default class Metric extends AnalyticsBaseModel {
|
||||
title: 'Start Time (in Unix Nano)',
|
||||
description: 'When did the Metric happen?',
|
||||
required: false,
|
||||
type: TableColumnType.Date,
|
||||
type: TableColumnType.Number,
|
||||
}),
|
||||
|
||||
new AnalyticsTableColumn({
|
||||
|
@ -51,7 +51,7 @@ export default class Metric extends AnalyticsBaseModel {
|
||||
key: 'time',
|
||||
title: 'Time',
|
||||
description: 'When did the Metric happen?',
|
||||
required: false,
|
||||
required: true,
|
||||
type: TableColumnType.Date,
|
||||
}),
|
||||
|
||||
@ -68,7 +68,7 @@ export default class Metric extends AnalyticsBaseModel {
|
||||
title: 'Time (in Unix Nano)',
|
||||
description: 'When did the Metric happen?',
|
||||
required: false,
|
||||
type: TableColumnType.Date,
|
||||
type: TableColumnType.Number,
|
||||
}),
|
||||
|
||||
new AnalyticsTableColumn({
|
||||
@ -76,7 +76,7 @@ export default class Metric extends AnalyticsBaseModel {
|
||||
title: 'Start Time (in Unix Nano)',
|
||||
description: 'When did the Metric happen?',
|
||||
required: true,
|
||||
type: TableColumnType.Date,
|
||||
type: TableColumnType.Number,
|
||||
}),
|
||||
|
||||
new AnalyticsTableColumn({
|
||||
|
Loading…
Reference in New Issue
Block a user