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

119 lines
2.3 KiB
TypeScript
Raw Normal View History

import { Model, DataTypes, Optional } from "sequelize";
import sequelize from "../storage/db";
import { WorkflowFile, Where, What, WhereWhatPair } from "maxun-core";
2024-10-09 03:22:36 +05:30
2024-10-09 03:59:31 +05:30
interface RobotMeta {
name: string;
id: string;
createdAt: string;
pairs: number;
updatedAt: string;
params: any[];
}
interface RobotWorkflow {
2024-10-09 14:34:43 +05:30
workflow: WhereWhatPair[];
}
interface IntegrationData {
google_sheets?: {
email: string;
sheet_id: string;
sheet_name: string;
access_token: string;
refresh_token: string;
};
airtable?: {
base_id: string;
table_name: string;
access_token: string;
refresh_token: string;
};
}
2024-10-09 03:22:36 +05:30
interface RobotAttributes {
id: string;
2024-10-21 22:31:58 +05:30
userId?: number;
2024-10-09 03:59:31 +05:30
recording_meta: RobotMeta;
recording: RobotWorkflow;
schedule?: ScheduleConfig | null;
integrations?: IntegrationData | null;
2024-10-09 03:22:36 +05:30
}
2024-10-22 18:32:27 +05:30
interface ScheduleConfig {
runEvery: number;
runEveryUnit: "MINUTES" | "HOURS" | "DAYS" | "WEEKS" | "MONTHS";
startFrom:
| "SUNDAY"
| "MONDAY"
| "TUESDAY"
| "WEDNESDAY"
| "THURSDAY"
| "FRIDAY"
| "SATURDAY";
2024-10-22 18:32:27 +05:30
atTimeStart?: string;
atTimeEnd?: string;
timezone: string;
lastRunAt?: Date;
nextRunAt?: Date;
2024-10-29 00:59:11 +05:30
dayOfMonth?: string;
2024-10-22 18:32:27 +05:30
cronExpression?: string;
}
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;
2024-10-21 22:31:58 +05:30
public userId!: number;
2024-10-09 03:59:31 +05:30
public recording_meta!: RobotMeta;
public recording!: RobotWorkflow;
public schedule!: ScheduleConfig | null;
public integrations!: IntegrationData | null;
2024-10-09 03:22:36 +05:30
}
Robot.init(
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
2024-10-21 20:39:42 +05:30
userId: {
2024-10-21 22:31:58 +05:30
type: DataTypes.INTEGER,
2024-10-21 20:39:42 +05:30
allowNull: false,
},
recording_meta: {
type: DataTypes.JSONB,
allowNull: false,
},
recording: {
type: DataTypes.JSONB,
allowNull: false,
2024-10-09 03:22:36 +05:30
},
integrations: {
type: DataTypes.JSONB,
2024-10-16 23:38:18 +05:30
allowNull: true,
defaultValue: {},
2024-10-16 23:38:34 +05:30
},
2024-10-22 18:34:38 +05:30
schedule: {
type: DataTypes.JSONB,
allowNull: true,
},
},
{
sequelize,
tableName: "robot",
2024-10-09 14:34:58 +05:30
timestamps: false,
}
2024-10-09 03:22:36 +05:30
);
2024-10-21 20:38:37 +05:30
// Robot.hasMany(Run, {
// foreignKey: 'robotId',
// as: 'runs', // Alias for the relation
// });
2024-10-21 19:50:15 +05:30
export default Robot;