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

71 lines
1.6 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
interface RobotAttributes {
2024-10-09 03:27:28 +05:30
id: string;
name: string;
createdAt: Date;
updatedAt: Date;
pairs: number;
params: object;
workflow: object; // Store workflow details as JSONB
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 {
2024-10-09 03:27:28 +05:30
public id!: string;
public name!: string;
public createdAt!: Date;
public updatedAt!: Date;
public pairs!: number;
public params!: object;
public workflow!: object;
2024-10-09 03:22:36 +05:30
}
Robot.init(
2024-10-09 03:27:28 +05:30
{
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,
},
params: {
type: DataTypes.JSONB,
allowNull: true,
},
workflow: {
type: DataTypes.JSONB,
allowNull: true,
},
2024-10-09 03:22:36 +05:30
},
2024-10-09 03:27:28 +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;