mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 03:39:29 +00:00
feat: add queue and assoc with whatsapps
This commit is contained in:
44
backend/src/models/Queue.ts
Normal file
44
backend/src/models/Queue.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import {
|
||||
Table,
|
||||
Column,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
Model,
|
||||
PrimaryKey,
|
||||
AutoIncrement,
|
||||
AllowNull,
|
||||
Unique,
|
||||
BelongsToMany
|
||||
} from "sequelize-typescript";
|
||||
|
||||
import Whatsapp from "./Whatsapp";
|
||||
import WhatsappQueue from "./WhatsappQueue";
|
||||
|
||||
@Table
|
||||
class Queue extends Model<Queue> {
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Column
|
||||
id: number;
|
||||
|
||||
@AllowNull(false)
|
||||
@Unique
|
||||
@Column
|
||||
name: string;
|
||||
|
||||
@AllowNull(false)
|
||||
@Unique
|
||||
@Column
|
||||
color: string;
|
||||
|
||||
@CreatedAt
|
||||
createdAt: Date;
|
||||
|
||||
@UpdatedAt
|
||||
updatedAt: Date;
|
||||
|
||||
@BelongsToMany(() => Whatsapp, () => WhatsappQueue)
|
||||
whatsapps: Array<Whatsapp & { WhatsappQueue: WhatsappQueue }>;
|
||||
}
|
||||
|
||||
export default Queue;
|
||||
@@ -10,9 +10,12 @@ import {
|
||||
Default,
|
||||
AllowNull,
|
||||
HasMany,
|
||||
Unique
|
||||
Unique,
|
||||
BelongsToMany
|
||||
} from "sequelize-typescript";
|
||||
import Queue from "./Queue";
|
||||
import Ticket from "./Ticket";
|
||||
import WhatsappQueue from "./WhatsappQueue";
|
||||
|
||||
@Table
|
||||
class Whatsapp extends Model<Whatsapp> {
|
||||
@@ -57,6 +60,9 @@ class Whatsapp extends Model<Whatsapp> {
|
||||
|
||||
@HasMany(() => Ticket)
|
||||
tickets: Ticket[];
|
||||
|
||||
@BelongsToMany(() => Queue, () => WhatsappQueue)
|
||||
queues: Array<Queue & { WhatsappQueue: WhatsappQueue }>;
|
||||
}
|
||||
|
||||
export default Whatsapp;
|
||||
|
||||
29
backend/src/models/WhatsappQueue.ts
Normal file
29
backend/src/models/WhatsappQueue.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import {
|
||||
Table,
|
||||
Column,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
Model,
|
||||
ForeignKey
|
||||
} from "sequelize-typescript";
|
||||
import Queue from "./Queue";
|
||||
import Whatsapp from "./Whatsapp";
|
||||
|
||||
@Table
|
||||
class WhatsappQueue extends Model<WhatsappQueue> {
|
||||
@ForeignKey(() => Whatsapp)
|
||||
@Column
|
||||
whatsappId: number;
|
||||
|
||||
@ForeignKey(() => Queue)
|
||||
@Column
|
||||
queueId: number;
|
||||
|
||||
@CreatedAt
|
||||
createdAt: Date;
|
||||
|
||||
@UpdatedAt
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export default WhatsappQueue;
|
||||
Reference in New Issue
Block a user