added delete crm user function

main
alex 2024-08-12 20:02:47 +02:00
parent e614829e76
commit 22c41ea006
5 changed files with 106 additions and 1 deletions

View File

@ -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."
}
}

BIN
main

Binary file not shown.

View File

@ -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,

View File

@ -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(&params); 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
// ---

View File

@ -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)