diff --git a/main b/main index 3cbad27..d3ba5ec 100755 Binary files a/main and b/main differ diff --git a/modules/structs/crm.go b/modules/structs/crm.go index 0b0af01..1fdee6a 100644 --- a/modules/structs/crm.go +++ b/modules/structs/crm.go @@ -37,6 +37,7 @@ type CrmCustomer struct { AmountsOfTheInstallments string BookedPackages string AssignedEmployee string + UpdatedAt time.Time } // swagger:model CrmTableCustomerResponse @@ -58,6 +59,7 @@ type CrmTableCustomer struct { LastContact time.Time AssignedEmployee string CreatedBy string + UpdatedAt time.Time } func (CrmTableCustomer) TableName() string { diff --git a/routers/router/api/v1/crm/crm.go b/routers/router/api/v1/crm/crm.go index 4691462..21258ef 100644 --- a/routers/router/api/v1/crm/crm.go +++ b/routers/router/api/v1/crm/crm.go @@ -220,6 +220,8 @@ func UpdateCrmCustomer(c *fiber.Ctx) error { return c.SendStatus(fiber.StatusBadRequest) } + crmCustomer["UpdatedAt"] = time.Now() + result := database.DB.Model(&structs.CrmCustomer{}). Where("id = ?", params.Id). Select("*"). // update all fields (even if they are empty) @@ -410,10 +412,36 @@ func CreateCrmCallProtocol(c *fiber.Ctx) error { return c.SendStatus(fiber.StatusInternalServerError) } + // update last contact date + + result = database.DB.Model(&structs.CrmCustomer{}). + Where("id = ?", body.CustomerId). + Update("last_contact", time.Now()) + + if result.Error != nil { + logger.AddCrmLog(rslogger.LogTypeError, "Failed to update last contact date: %v", result.Error.Error()) + return c.SendStatus(fiber.StatusInternalServerError) + } + socketclients.BroadcastMessageToTopicStartsWith(utils.SubscribedTopicCrm, structs.SendSocketMessage{ - Cmd: utils.SentCmdCrmCallProtocolCreated, - Body: crmCallProtocol, + Cmd: utils.SentCmdCrmCallProtocolCreated, + Body: struct { + CallProtocol structs.CrmCallProtocol + Customer struct { + Id string + LastContact time.Time + } + }{ + CallProtocol: crmCallProtocol, + Customer: struct { + Id string + LastContact time.Time + }{ + Id: body.CustomerId, + LastContact: time.Now(), + }, + }, }) logger.AddCrmLog(rslogger.LogTypeInfo, "Crm call protocol id: %s created: %v", crmCallProtocol.Id, crmCallProtocol) @@ -492,8 +520,6 @@ func DeleteCrmCallProtocol(c *fiber.Ctx) error { return c.SendStatus(fiber.StatusBadRequest) } - logger.AddCrmLog(rslogger.LogTypeInfo, "Crm call protocol id: %s delete requested", params.Id) - var crmCallProtocol structs.CrmCallProtocol database.DB.First(&crmCallProtocol, "id = ?", params.Id)