diff --git a/groupTasks/groupsData/shx-order-voucher-codes/texte.json b/groupTasks/groupsData/shx-order-voucher-codes/texte.json index 61f8cee..43e24c4 100644 --- a/groupTasks/groupsData/shx-order-voucher-codes/texte.json +++ b/groupTasks/groupsData/shx-order-voucher-codes/texte.json @@ -47,6 +47,6 @@ } ], "additionalInfo": { - "Fehldrucke beigelegt": "ⓘ Wir haben bemerkt, dass der erste Druck des Schildes nicht unseren Qualitätsstandards entsprach, weshalb wir es für Dich erneut gedruckt haben. Anstatt den ersten Druck zu entsorgen, legen wir ihn als kostenlose Zugabe bei. Vielleicht findest Du eine Verwendung dafür 😊" + "Fehldrucke beigelegt": "ⓘ Wir haben bemerkt, dass der erste Druck des Schildes nicht unseren Qualitätsstandards entsprach, weshalb wir es für Dich erneut gedruckt haben. Anstatt den ersten Druck zu entsorgen, legen wir ihn als kostenlose Zugabe bei. Vielleicht findest Du eine Verwendung dafür." } } diff --git a/main b/main index 8c552bb..4a43363 100755 Binary files a/main and b/main differ diff --git a/modules/utils/globals.go b/modules/utils/globals.go index 24ac04f..72f96e8 100644 --- a/modules/utils/globals.go +++ b/modules/utils/globals.go @@ -110,6 +110,7 @@ const ( SentCmdCrmLinkUsed = 52 SentCmdCrmLinkDeleted = 53 SendCmdCustomerFeedbackAddFeedback = 54 + SentCmdCrmCustomerDeleted = 55 ) // commands received from web clients @@ -228,6 +229,7 @@ const ( PermissionCrmCustomersView = _crm + "customers.view" PermissionCrmCustomersEdit = _crm + "customers.edit" PermissionCrmCustomersCreate = _crm + "customers.create" + PermissionCrmCustomersDelete = _crm + "customers.delete" PermissionCrmDmcPipelineView = _crm + "dmc_pipeline.view" PermissionCrmSetterCloserView = _crm + "setter_closer.view" PermissionCrmCallProtocolCreate = _crm + "call_protocol.create" @@ -273,6 +275,7 @@ var SystemPermissions = []string{ PermissionCrmCustomersView, PermissionCrmCustomersEdit, PermissionCrmCustomersCreate, + PermissionCrmCustomersDelete, PermissionCrmDmcPipelineView, PermissionCrmSetterCloserView, PermissionCrmCallProtocolCreate, diff --git a/routers/router/api/v1/crm/crm.go b/routers/router/api/v1/crm/crm.go index 95f87b1..973c5fa 100644 --- a/routers/router/api/v1/crm/crm.go +++ b/routers/router/api/v1/crm/crm.go @@ -392,6 +392,107 @@ func handleError(result *gorm.DB, c *fiber.Ctx) error { return nil } +func DeleteCrmCustomer(c *fiber.Ctx) error { + // swagger:operation DELETE /crm/customer/delete/{id} crm crmDeleteCrmCustomer + // --- + // summary: Delete crm customer + // produces: + // - application/json + // parameters: + // - name: id + // in: path + // description: Customer id + // responses: + // '200': + // description: Crm customer deleted + // '400': + // description: Invalid request query + // '401': + // description: No permissions + // '404': + // description: Crm customer not found + // '500': + // description: Failed to delete crm customer + + if !socketclients.HasPermission(c.Locals("userId").(string), utils.PermissionCrmCustomersDelete) { + return c.SendStatus(fiber.StatusUnauthorized) + } + + var params structs.CrmGetCustomerRequest + + if err := c.ParamsParser(¶ms); err != nil { + return c.SendStatus(fiber.StatusBadRequest) + } + + // check if customer exists + + var customer structs.CrmCustomer + + database.DB.First(&customer, "id = ?", params.Id) + + if customer.Id != params.Id { + return c.SendStatus(fiber.StatusNotFound) + } + + // delete customer + + result := database.DB.Delete(&customer, "id = ?", params.Id) + + logger.AddCrmLog(rslogger.LogTypeInfo, "Crm customer id: %s deleted: %v by user: %s", params.Id, customer, c.Locals("userId").(string)) + + if result.Error != nil { + return c.SendStatus(fiber.StatusInternalServerError) + } + + // delete all call protocols + + result = database.DB.Delete(&structs.CrmCallProtocol{}, "customer_id = ?", params.Id) + + logger.AddCrmLog(rslogger.LogTypeInfo, "Crm call protocols for customer id: %s deleted: %v by user: %s", params.Id, customer, c.Locals("userId").(string)) + + if result.Error != nil { + return c.SendStatus(fiber.StatusInternalServerError) + } + + // we need the crmLink Id to delete the link history + + var crmLinks []structs.CrmLink + + database.DB.Find(&crmLinks, "customer_id = ?", params.Id) + + // delete all link history + + for _, link := range crmLinks { + result = database.DB.Delete(&structs.CrmLinkHistory{}, "link_id = ?", link.Id) + + logger.AddCrmLog(rslogger.LogTypeInfo, "Crm link history for link id: %s deleted: %v by user: %s", link.Id, link, c.Locals("userId").(string)) + + if result.Error != nil { + return c.SendStatus(fiber.StatusInternalServerError) + } + } + + // delete all links + + result = database.DB.Delete(&structs.CrmLink{}, "customer_id = ?", params.Id) + + logger.AddCrmLog(rslogger.LogTypeInfo, "Crm links for customer id: %s deleted: %v by user: %s", params.Id, customer, c.Locals("userId").(string)) + + if result.Error != nil { + return c.SendStatus(fiber.StatusInternalServerError) + } + + socketclients.BroadcastMessageToTopicStartsWith(utils.SubscribedTopicCrm, + structs.SendSocketMessage{ + Cmd: utils.SentCmdCrmCustomerDeleted, + Body: params.Id, + }) + + logger.AddCrmLog(rslogger.LogTypeInfo, "Crm customer id: %s deleted: %v by user: %s", params.Id, customer, c.Locals("userId").(string)) + + return c.SendStatus(fiber.StatusOK) +} + func CreateCrmCallProtocol(c *fiber.Ctx) error { // swagger:operation POST /crm/calls/create crm crmCreateCrmCallProtocol // --- diff --git a/routers/router/router.go b/routers/router/router.go index 4aade9a..f6052a2 100644 --- a/routers/router/router.go +++ b/routers/router/router.go @@ -78,6 +78,7 @@ func SetupRoutes(app *fiber.App) { c.Get("/customer/view/:id", requestAccessValidation, crm.GetCrmCustomerById) c.Post("/customer/update/:id", requestAccessValidation, crm.UpdateCrmCustomer) c.Post("/customer/create", requestAccessValidation, crm.CreateCrmCustomer) + c.Delete("/customer/delete/:id", requestAccessValidation, crm.DeleteCrmCustomer) c.Get("/customers", requestAccessValidation, crm.GetAllCustomers) c.Post("/calls/create", requestAccessValidation, crm.CreateCrmCallProtocol)