Files
parcer/server/src/models/Robot.ts

94 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-10-09 03:22:36 +05:30
import { Model, DataTypes, Optional } from 'sequelize';
import sequelize from '../db/config';
2024-10-09 03:31:31 +05:30
import Run from './Run';
2024-10-09 03:22:36 +05:30
2024-10-09 03:59:31 +05:30
interface RobotMeta {
name: string;
id: string;
createdAt: Date;
pairs: number;
updatedAt: Date;
params: object[];
}
2024-10-09 03:59:31 +05:30
interface Robot {
workflow: Array<{
where: {
url: string;
};
what: Array<{
action: string;
args: any[];
}>;
}>;
}
2024-10-09 03:22:36 +05:30
interface RobotAttributes {
id: string;
name: string;
createdAt: Date;
updatedAt: Date;
pairs: number;
2024-10-09 03:59:31 +05:30
recording_meta: RobotMeta;
recording: Robot;
2024-10-09 03:22:36 +05:30
}
2024-10-09 03:27:28 +05:30
interface RobotCreationAttributes extends Optional<RobotAttributes, 'id'> { }
2024-10-09 03:22:36 +05:30
class Robot extends Model<RobotAttributes, RobotCreationAttributes> implements RobotAttributes {
public id!: string;
public name!: string;
public createdAt!: Date;
public updatedAt!: Date;
public pairs!: number;
2024-10-09 03:59:31 +05:30
public recording_meta!: RobotMeta;
public recording!: Robot;
2024-10-09 03:22:36 +05:30
}
Robot.init(
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
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,
},
// 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,
2024-10-09 03:22:36 +05:30
},
},
{
sequelize,
tableName: 'robot',
timestamps: true,
}
2024-10-09 03:22:36 +05:30
);
2024-10-09 03:31:31 +05:30
Robot.hasMany(Run, { foreignKey: 'robotId' });
2024-10-09 03:22:36 +05:30
export default Robot;