add user association with whatsapps

This commit is contained in:
Ricardo Paes
2022-02-23 11:06:31 -03:00
parent 504414496b
commit 67ad73a8bd
2 changed files with 28 additions and 1 deletions

View File

@@ -0,0 +1,17 @@
import { QueryInterface, DataTypes } from "sequelize";
module.exports = {
up: (queryInterface: QueryInterface) => {
return queryInterface.addColumn("Users", "whatsappId", {
type: DataTypes.INTEGER,
references: { model: "Whatsapps", key: "id" },
onUpdate: "CASCADE",
onDelete: "SET NULL",
allowNull: true
},);
},
down: (queryInterface: QueryInterface) => {
return queryInterface.removeColumn("Users", "whatsappId");
}
};

View File

@@ -11,12 +11,15 @@ import {
AutoIncrement,
Default,
HasMany,
BelongsToMany
BelongsToMany,
ForeignKey,
BelongsTo
} from "sequelize-typescript";
import { hash, compare } from "bcryptjs";
import Ticket from "./Ticket";
import Queue from "./Queue";
import UserQueue from "./UserQueue";
import Whatsapp from "./Whatsapp";
@Table
class User extends Model<User> {
@@ -45,6 +48,13 @@ class User extends Model<User> {
@Column
profile: string;
@ForeignKey(() => Whatsapp)
@Column
whatsappId: number;
@BelongsTo(() => Whatsapp)
whatsapp: Whatsapp;
@CreatedAt
createdAt: Date;