feat: match exact format of file system robot

This commit is contained in:
karishmas6
2024-10-09 03:50:53 +05:30
parent 14d5de8084
commit 6acde9d958

View File

@@ -2,67 +2,90 @@ import { Model, DataTypes, Optional } from 'sequelize';
import sequelize from '../db/config'; import sequelize from '../db/config';
import Run from './Run'; import Run from './Run';
interface RecordingMeta {
name: string;
id: string;
createdAt: Date;
pairs: number;
updatedAt: Date;
params: object[];
}
interface Recording {
workflow: Array<{
where: {
url: string;
};
what: Array<{
action: string;
args: any[];
}>;
}>;
}
interface RobotAttributes { interface RobotAttributes {
id: string; id: string;
name: string; name: string;
createdAt: Date; createdAt: Date;
updatedAt: Date; updatedAt: Date;
pairs: number; pairs: number;
params: object; recording_meta: RecordingMeta;
workflow: object; // Store workflow details as JSONB recording: Recording;
} }
interface RobotCreationAttributes extends Optional<RobotAttributes, 'id'> { } interface RobotCreationAttributes extends Optional<RobotAttributes, 'id'> { }
class Robot extends Model<RobotAttributes, RobotCreationAttributes> implements RobotAttributes { class Robot extends Model<RobotAttributes, RobotCreationAttributes> implements RobotAttributes {
public id!: string; public id!: string;
public name!: string; public name!: string;
public createdAt!: Date; public createdAt!: Date;
public updatedAt!: Date; public updatedAt!: Date;
public pairs!: number; public pairs!: number;
public params!: object; public recording_meta!: RecordingMeta;
public workflow!: object; public recording!: Recording;
} }
Robot.init( Robot.init(
{ {
id: { id: {
type: DataTypes.UUID, type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4, defaultValue: DataTypes.UUIDV4,
primaryKey: true, primaryKey: true,
},
name: {
type: DataTypes.STRING(255),
allowNull: false,
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
},
pairs: {
type: DataTypes.INTEGER,
allowNull: false,
},
params: {
type: DataTypes.JSONB,
allowNull: true,
},
workflow: {
type: DataTypes.JSONB,
allowNull: true,
},
}, },
{ name: {
sequelize, type: DataTypes.STRING(255),
tableName: 'robot', allowNull: false,
timestamps: true, },
} createdAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
},
pairs: {
type: DataTypes.INTEGER,
allowNull: false,
},
// JSONB field for recording_meta (storing as a structured object)
recording_meta: {
type: DataTypes.JSONB,
allowNull: false,
},
// JSONB field for recording (storing as a structured object)
recording: {
type: DataTypes.JSONB,
allowNull: false,
},
},
{
sequelize,
tableName: 'robot',
timestamps: true,
}
); );
Robot.hasMany(Run, { foreignKey: 'robotId' }); Robot.hasMany(Run, { foreignKey: 'robotId' });