feat: include integrations in robot model

This commit is contained in:
RohitR311
2024-11-09 18:36:23 +05:30
parent 273219894a
commit d5c56afd0b

View File

@@ -1,6 +1,6 @@
import { Model, DataTypes, Optional } from 'sequelize'; import { Model, DataTypes, Optional } from "sequelize";
import sequelize from '../storage/db'; import sequelize from "../storage/db";
import { WorkflowFile, Where, What, WhereWhatPair } from 'maxun-core'; import { WorkflowFile, Where, What, WhereWhatPair } from "maxun-core";
interface RobotMeta { interface RobotMeta {
name: string; name: string;
@@ -15,23 +15,42 @@ interface RobotWorkflow {
workflow: WhereWhatPair[]; 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;
};
}
interface RobotAttributes { interface RobotAttributes {
id: string; id: string;
userId?: number; userId?: number;
recording_meta: RobotMeta; recording_meta: RobotMeta;
recording: RobotWorkflow; 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;
schedule?: ScheduleConfig | null; schedule?: ScheduleConfig | null;
integrations?: IntegrationData | null;
} }
interface ScheduleConfig { interface ScheduleConfig {
runEvery: number; runEvery: number;
runEveryUnit: 'MINUTES' | 'HOURS' | 'DAYS' | 'WEEKS' | 'MONTHS'; runEveryUnit: "MINUTES" | "HOURS" | "DAYS" | "WEEKS" | "MONTHS";
startFrom: 'SUNDAY' | 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY'; startFrom:
| "SUNDAY"
| "MONDAY"
| "TUESDAY"
| "WEDNESDAY"
| "THURSDAY"
| "FRIDAY"
| "SATURDAY";
atTimeStart?: string; atTimeStart?: string;
atTimeEnd?: string; atTimeEnd?: string;
timezone: string; timezone: string;
@@ -41,19 +60,18 @@ interface ScheduleConfig {
cronExpression?: string; cronExpression?: string;
} }
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 userId!: number; public userId!: number;
public recording_meta!: RobotMeta; public recording_meta!: RobotMeta;
public recording!: RobotWorkflow; 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;
public schedule!: ScheduleConfig | null; public schedule!: ScheduleConfig | null;
public integrations!: IntegrationData | null;
} }
Robot.init( Robot.init(
@@ -75,25 +93,10 @@ Robot.init(
type: DataTypes.JSONB, type: DataTypes.JSONB,
allowNull: false, allowNull: false,
}, },
google_sheet_email: { integrations: {
type: DataTypes.STRING, type: DataTypes.JSONB,
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, allowNull: true,
defaultValue: {},
}, },
schedule: { schedule: {
type: DataTypes.JSONB, type: DataTypes.JSONB,
@@ -102,7 +105,7 @@ Robot.init(
}, },
{ {
sequelize, sequelize,
tableName: 'robot', tableName: "robot",
timestamps: false, timestamps: false,
} }
); );