From 23c7b323720ae520cb34c029f729658adcf16657 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 21 Oct 2024 19:50:15 +0530 Subject: [PATCH] feat: user and robot relation --- server/src/models/Robot.ts | 7 +++++++ server/src/models/User.ts | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/server/src/models/Robot.ts b/server/src/models/Robot.ts index a48b9af1..41e974f9 100644 --- a/server/src/models/Robot.ts +++ b/server/src/models/Robot.ts @@ -1,6 +1,8 @@ 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; @@ -82,4 +84,9 @@ Robot.init( } ); +Robot.hasMany(Run, { + foreignKey: 'robotId', + as: 'runs', // Alias for the relation +}); + export default Robot; \ No newline at end of file diff --git a/server/src/models/User.ts b/server/src/models/User.ts index 5a3d552c..f7c22b5b 100644 --- a/server/src/models/User.ts +++ b/server/src/models/User.ts @@ -1,5 +1,6 @@ import { DataTypes, Model, Optional } from 'sequelize'; import sequelize from '../storage/db'; +import Robot from './Robot'; interface UserAttributes { id: number; @@ -79,4 +80,9 @@ User.init( } ); +User.hasMany(Robot, { + foreignKey: 'userId', + as: 'robots', // Alias for the relation + }); + export default User;