Files
parcer/server/src/models/Robot.ts
2024-10-21 20:59:49 +05:30

98 lines
2.2 KiB
TypeScript

import { Model, DataTypes, Optional } from 'sequelize';
import sequelize from '../storage/db';
import { WorkflowFile, Where, What, WhereWhatPair } from 'maxun-core';
import User from './User'; // Import User model
import Run from './Run';
interface RobotMeta {
name: string;
id: string;
createdAt: string;
pairs: number;
updatedAt: string;
params: any[];
}
interface RobotWorkflow {
workflow: WhereWhatPair[];
}
interface RobotAttributes {
id: string;
userId?: string;
recording_meta: RobotMeta;
recording: RobotWorkflow;
google_sheet_email?: string | null;
google_sheet_name?: string | null;
google_sheet_id?: string | null;
google_access_token?: string | null;
google_refresh_token?: string | null;
}
interface RobotCreationAttributes extends Optional<RobotAttributes, 'id'> { }
class Robot extends Model<RobotAttributes, RobotCreationAttributes> implements RobotAttributes {
public id!: string;
public userId!: string;
public recording_meta!: RobotMeta;
public recording!: RobotWorkflow;
public google_sheet_email!: string | null;
public google_sheet_name?: string | null;
public google_sheet_id?: string | null;
public google_access_token!: string | null;
public google_refresh_token!: string | null;
}
Robot.init(
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
userId: {
type: DataTypes.UUID,
allowNull: false,
},
recording_meta: {
type: DataTypes.JSONB,
allowNull: false,
},
recording: {
type: DataTypes.JSONB,
allowNull: false,
},
google_sheet_email: {
type: DataTypes.STRING,
allowNull: true,
},
google_sheet_name: {
type: DataTypes.STRING,
allowNull: true,
},
google_sheet_id: {
type: DataTypes.STRING,
allowNull: true,
},
google_access_token: {
type: DataTypes.STRING,
allowNull: true,
},
google_refresh_token: {
type: DataTypes.STRING,
allowNull: true,
},
},
{
sequelize,
tableName: 'robot',
timestamps: false,
}
);
// Robot.hasMany(Run, {
// foreignKey: 'robotId',
// as: 'runs', // Alias for the relation
// });
export default Robot;