2025-06-16 17:49:27 +10:00
|
|
|
package models
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
2025-10-23 17:02:52 +11:00
|
|
|
|
|
|
|
|
"gorm.io/gorm"
|
2025-06-16 17:49:27 +10:00
|
|
|
)
|
|
|
|
|
|
2025-11-10 10:10:46 +11:00
|
|
|
// DBParticipant is a model that stores raw 'participant' payloads from GenesysCloud websockets and API requests.
|
|
|
|
|
//
|
|
|
|
|
// - The ExtractLive function handles the conversion from JSON data (map) into formatted JSON string for websocket payloads.
|
|
|
|
|
// - The ExtractWithoutAttributes function handles the conversion from JSON data (map) into formatted JSON string for gcq-details requests.
|
|
|
|
|
//
|
|
|
|
|
// Table Schema:
|
|
|
|
|
//
|
|
|
|
|
// Primary Key: Id
|
|
|
|
|
// Indexes: ConnectedTime, ConversationId, EndTime, Id, Name, Purpose
|
|
|
|
|
// JSON Fields: Attributes, MediaRoles, Wrapup
|
|
|
|
|
//
|
|
|
|
|
// GORM Specifics:
|
|
|
|
|
// - Can be preloaded with Sessions []DBSession
|
|
|
|
|
// - Can be preloaded with Calls []DBCall
|
|
|
|
|
// - Can be preloaded with User *GCUser
|
|
|
|
|
// - BeforeSave function, converts UserId into 'nil' if an empty string is returned, this prevents foreign key violations.
|
2025-06-16 17:49:27 +10:00
|
|
|
type DBParticipant struct {
|
|
|
|
|
Address *string
|
|
|
|
|
Attributes *string `gorm:"type:json"`
|
|
|
|
|
ConnectedTime *time.Time `gorm:"index"`
|
|
|
|
|
ConversationId string `gorm:"foreignKey;index"`
|
|
|
|
|
EndTime *time.Time `gorm:"index"`
|
|
|
|
|
ExternalContactId *string
|
|
|
|
|
ExternalContactInitialDivisionId *string
|
|
|
|
|
Id string `gorm:"primaryKey;index"`
|
|
|
|
|
MediaRoles *string `gorm:"type:json"`
|
|
|
|
|
Name *string `gorm:"index"`
|
|
|
|
|
Purpose *string `gorm:"index"`
|
|
|
|
|
QueueId *string
|
2025-10-19 19:16:41 +11:00
|
|
|
UserId *string
|
2025-06-16 17:49:27 +10:00
|
|
|
Wrapup *string `gorm:"type:json"`
|
|
|
|
|
WrapupExpected *bool
|
|
|
|
|
WrapupRequired *bool
|
2025-06-19 14:45:58 +10:00
|
|
|
|
|
|
|
|
Sessions []DBSession `gorm:"foreignKey:ParticipantId;references:Id"`
|
2025-10-23 16:32:18 +11:00
|
|
|
Calls []DBCall `gorm:"foreignKey:ParticipantId;references:Id"`
|
2025-10-23 16:55:59 +11:00
|
|
|
User *GCUser `gorm:"foreignKey:UserId;references:Id"`
|
2025-06-16 17:49:27 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (DBParticipant) TableName() string {
|
|
|
|
|
return "gc_participants"
|
|
|
|
|
}
|
2025-10-23 17:02:52 +11:00
|
|
|
|
|
|
|
|
func (p *DBParticipant) BeforeSave(tx *gorm.DB) error {
|
|
|
|
|
// Convert empty string to nil
|
|
|
|
|
if p.UserId != nil && *p.UserId == "" {
|
|
|
|
|
p.UserId = nil
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|