From d5c56afd0b93862675a59d900970316e7163bac7 Mon Sep 17 00:00:00 2001 From: RohitR311 Date: Sat, 9 Nov 2024 18:36:23 +0530 Subject: [PATCH] feat: include integrations in robot model --- server/src/models/Robot.ts | 77 ++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/server/src/models/Robot.ts b/server/src/models/Robot.ts index 3b2717d6..4d6ef427 100644 --- a/server/src/models/Robot.ts +++ b/server/src/models/Robot.ts @@ -1,6 +1,6 @@ -import { Model, DataTypes, Optional } from 'sequelize'; -import sequelize from '../storage/db'; -import { WorkflowFile, Where, What, WhereWhatPair } from 'maxun-core'; +import { Model, DataTypes, Optional } from "sequelize"; +import sequelize from "../storage/db"; +import { WorkflowFile, Where, What, WhereWhatPair } from "maxun-core"; interface RobotMeta { name: string; @@ -15,23 +15,42 @@ interface RobotWorkflow { 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 { id: string; userId?: number; 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; schedule?: ScheduleConfig | null; + integrations?: IntegrationData | null; } interface ScheduleConfig { runEvery: number; - runEveryUnit: 'MINUTES' | 'HOURS' | 'DAYS' | 'WEEKS' | 'MONTHS'; - startFrom: 'SUNDAY' | 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY'; + runEveryUnit: "MINUTES" | "HOURS" | "DAYS" | "WEEKS" | "MONTHS"; + startFrom: + | "SUNDAY" + | "MONDAY" + | "TUESDAY" + | "WEDNESDAY" + | "THURSDAY" + | "FRIDAY" + | "SATURDAY"; atTimeStart?: string; atTimeEnd?: string; timezone: string; @@ -41,19 +60,18 @@ interface ScheduleConfig { cronExpression?: string; } -interface RobotCreationAttributes extends Optional { } +interface RobotCreationAttributes extends Optional {} -class Robot extends Model implements RobotAttributes { +class Robot + extends Model + implements RobotAttributes +{ public id!: string; public userId!: number; 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; public schedule!: ScheduleConfig | null; + public integrations!: IntegrationData | null; } Robot.init( @@ -75,25 +93,10 @@ Robot.init( 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, + integrations: { + type: DataTypes.JSONB, allowNull: true, + defaultValue: {}, }, schedule: { type: DataTypes.JSONB, @@ -102,7 +105,7 @@ Robot.init( }, { sequelize, - tableName: 'robot', + tableName: "robot", timestamps: false, } ); @@ -112,4 +115,4 @@ Robot.init( // as: 'runs', // Alias for the relation // }); -export default Robot; \ No newline at end of file +export default Robot;