chore: Introduce has many steps through flows for user model

This commit is contained in:
Faruk AYDIN
2022-01-29 19:48:59 +03:00
committed by Ömer Faruk Aydın
parent 700d0bfd32
commit 3429784309
5 changed files with 32 additions and 24 deletions

View File

@@ -2,6 +2,7 @@ import { QueryContext, ModelOptions } from 'objection';
import Base from './base';
import Connection from './connection';
import Flow from './flow';
import Step from './step';
import bcrypt from 'bcrypt';
class User extends Base {
@@ -10,6 +11,7 @@ class User extends Base {
password!: string;
connections?: [Connection];
flows?: [Flow];
steps?: [Step];
static tableName = 'users';
@@ -41,6 +43,18 @@ class User extends Base {
to: 'flows.user_id',
},
},
steps: {
relation: Base.ManyToManyRelation,
modelClass: Step,
join: {
from: 'users.id',
through: {
from: 'flows.user_id',
to: 'flows.id',
},
to: 'steps.flow_id',
},
},
});
login(password: string) {