refactor: convert IDs to uuid

This commit is contained in:
Ali BARIN
2022-03-03 21:42:16 +01:00
committed by Ömer Faruk Aydın
parent 0c183eeadd
commit 02af7948e5
17 changed files with 45 additions and 31 deletions

View File

@@ -1,5 +1,6 @@
import { Model, snakeCaseMappers } from 'objection';
import { AjvValidator, Model, snakeCaseMappers } from 'objection';
import type { QueryContext, ModelOptions, ColumnNameMappers } from 'objection';
import addFormats from 'ajv-formats';
class Base extends Model {
createdAt!: string;
@@ -9,6 +10,19 @@ class Base extends Model {
return snakeCaseMappers();
}
static createValidator() {
return new AjvValidator({
onCreateAjv: (ajv) => {
addFormats.default(ajv);
},
options: {
allErrors: true,
validateSchema: true,
ownProperties: true,
},
});
}
async $beforeInsert(queryContext: QueryContext): Promise<void> {
await super.$beforeInsert(queryContext);

View File

@@ -20,10 +20,10 @@ class Connection extends Base {
required: ['key', 'data'],
properties: {
id: { type: 'string' },
id: { type: 'string', format: 'uuid' },
key: { type: 'string', minLength: 1, maxLength: 255 },
data: { type: 'object' },
userId: { type: 'string' },
userId: { type: 'string', format: 'uuid' },
verified: { type: 'boolean' },
},
};

View File

@@ -16,8 +16,8 @@ class ExecutionStep extends Base {
type: 'object',
properties: {
id: { type: 'string' },
executionId: { type: 'string' },
id: { type: 'string', format: 'uuid' },
executionId: { type: 'string', format: 'uuid' },
stepId: { type: 'string' },
dataIn: { type: 'object' },
dataOut: { type: 'object' },

View File

@@ -14,8 +14,8 @@ class Execution extends Base {
type: 'object',
properties: {
id: { type: 'string' },
flowId: { type: 'integer' },
id: { type: 'string', format: 'uuid' },
flowId: { type: 'string', format: 'uuid' },
testRun: { type: 'boolean' },
},
};

View File

@@ -15,9 +15,9 @@ class Flow extends Base {
type: 'object',
properties: {
id: { type: 'string' },
id: { type: 'string', format: 'uuid' },
name: { type: 'string' },
userId: { type: 'string' },
userId: { type: 'string', format: 'uuid' },
active: { type: 'boolean' },
},
};

View File

@@ -25,12 +25,12 @@ class Step extends Base {
required: ['type'],
properties: {
id: { type: 'string' },
flowId: { type: 'string' },
id: { type: 'string', format: 'uuid' },
flowId: { type: 'string', format: 'uuid' },
key: { type: ['string', 'null'] },
appKey: { type: ['string', 'null'], minLength: 1, maxLength: 255 },
type: { type: 'string', enum: ['action', 'trigger'] },
connectionId: { type: ['string', 'null'] },
connectionId: { type: ['string', 'null'], format: 'uuid' },
status: { type: 'string', enum: ['incomplete', 'completed'] },
position: { type: 'integer' },
parameters: { type: 'object' },

View File

@@ -20,7 +20,7 @@ class User extends Base {
required: ['email', 'password'],
properties: {
id: { type: 'string' },
id: { type: 'string', format: 'uuid' },
email: { type: 'string', format: 'email', minLength: 1, maxLength: 255 },
password: { type: 'string', minLength: 1, maxLength: 255 },
},