create crm

main
alex 2023-12-07 22:58:44 +01:00
parent e789bfbb4e
commit 359736f693
4 changed files with 63 additions and 5 deletions

View File

@ -54,7 +54,6 @@ type CrmTableCustomer struct {
Email string Email string
LastContact time.Time LastContact time.Time
CreatedBy string CreatedBy string
Notes string
} }
func (CrmTableCustomer) TableName() string { func (CrmTableCustomer) TableName() string {

View File

@ -101,6 +101,7 @@ const (
SentCmdAdminAreaManageLogManagerServerConnectionAdded = 45 SentCmdAdminAreaManageLogManagerServerConnectionAdded = 45
SentCmdAdminAreaManageLogManagerServerConnectionRemoved = 46 SentCmdAdminAreaManageLogManagerServerConnectionRemoved = 46
SentCmdCrmCustomerUpdated = 47 SentCmdCrmCustomerUpdated = 47
SentCmdCrmCustomerCreated = 48
) )
// commands received from web clients // commands received from web clients
@ -218,6 +219,7 @@ const (
_crm = "crm." _crm = "crm."
PermissionCrmCustomersView = _crm + "customers.view" PermissionCrmCustomersView = _crm + "customers.view"
PermissionCrmCustomersEdit = _crm + "customers.edit" PermissionCrmCustomersEdit = _crm + "customers.edit"
PermissionCrmCustomersCreate = _crm + "customers.create"
PermissionCrmDmcPipelineView = _crm + "dmc_pipeline.view" PermissionCrmDmcPipelineView = _crm + "dmc_pipeline.view"
PermissionCrmSetterCloserView = _crm + "setter_closer.view" PermissionCrmSetterCloserView = _crm + "setter_closer.view"
) )
@ -253,6 +255,7 @@ var SystemPermissions = []string{
PermissionsRoboticsRobotsViewSwaggerDocumentation, PermissionsRoboticsRobotsViewSwaggerDocumentation,
PermissionCrmCustomersView, PermissionCrmCustomersView,
PermissionCrmCustomersEdit, PermissionCrmCustomersEdit,
PermissionCrmCustomersCreate,
PermissionCrmDmcPipelineView, PermissionCrmDmcPipelineView,
PermissionCrmSetterCloserView, PermissionCrmSetterCloserView,
} }

View File

@ -9,7 +9,7 @@ import (
"git.ex.umbach.dev/Alex/roese-utils/rspagination" "git.ex.umbach.dev/Alex/roese-utils/rspagination"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log" "github.com/google/uuid"
) )
func GetCrmTypeCustomers(c *fiber.Ctx) error { func GetCrmTypeCustomers(c *fiber.Ctx) error {
@ -188,19 +188,19 @@ func UpdateCrmCustomer(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusNotFound) return c.SendStatus(fiber.StatusNotFound)
} }
var crmCustomer structs.CrmCustomer var crmCustomer map[string]interface{}
if err := c.BodyParser(&crmCustomer); err != nil { if err := c.BodyParser(&crmCustomer); err != nil {
return c.SendStatus(fiber.StatusBadRequest) return c.SendStatus(fiber.StatusBadRequest)
} }
log.Info().Msgf("%+v %v", crmCustomer, crmCustomer.Telephone)
database.DB.Model(&structs.CrmCustomer{}). database.DB.Model(&structs.CrmCustomer{}).
Where("id = ?", params.Id). Where("id = ?", params.Id).
Select("*"). // update all fields (even if they are empty) Select("*"). // update all fields (even if they are empty)
Updates(crmCustomer) Updates(crmCustomer)
crmCustomer["Id"] = params.Id
socketclients.BroadcastMessageToTopicStartsWith(utils.SubscribedTopicCrm, structs.SendSocketMessage{ socketclients.BroadcastMessageToTopicStartsWith(utils.SubscribedTopicCrm, structs.SendSocketMessage{
Cmd: utils.SentCmdCrmCustomerUpdated, Cmd: utils.SentCmdCrmCustomerUpdated,
Body: crmCustomer, Body: crmCustomer,
@ -208,3 +208,58 @@ func UpdateCrmCustomer(c *fiber.Ctx) error {
return c.JSON(crmCustomer) return c.JSON(crmCustomer)
} }
func CreateCrmCustomer(c *fiber.Ctx) error {
// swagger:operation POST /crm/customer/create crm crmCreateCrmCustomer
// ---
// summary: Create crm customer
// produces:
// - application/json
// parameters:
// - name: crmCustomer
// in: body
// description: Crm customer
// schema:
// "$ref": "#/definitions/CrmCustomer"
// responses:
// '200':
// description: Crm customer
// schema:
// "$ref": "#/definitions/CrmCustomer"
// '400':
// description: Invalid request query
// '401':
// description: No permissions
// '500':
// description: Failed to create crm customer
if !socketclients.HasPermission(c.Locals("userId").(string), utils.PermissionCrmCustomersCreate) {
return c.SendStatus(fiber.StatusUnauthorized)
}
var crmCustomer map[string]interface{}
if err := c.BodyParser(&crmCustomer); err != nil {
return c.SendStatus(fiber.StatusBadRequest)
}
crmCustomer["Id"] = uuid.New().String()
if crmCustomer["Pipeline"] == nil {
crmCustomer["Pipeline"] = 1
}
if crmCustomer["DealPhase"] == nil {
crmCustomer["DealPhase"] = 1
}
database.DB.Model(&structs.CrmCustomer{}).Create(&crmCustomer)
socketclients.BroadcastMessageToTopicStartsWith(utils.SubscribedTopicCrm,
structs.SendSocketMessage{
Cmd: utils.SentCmdCrmCustomerCreated,
Body: crmCustomer,
})
return c.JSON(crmCustomer)
}

View File

@ -71,6 +71,7 @@ func SetupRoutes(app *fiber.App) {
c.Get("/pipeline/:type/:dealPhase", requestAccessValidation, crm.GetCrmTypeCustomers) c.Get("/pipeline/:type/:dealPhase", requestAccessValidation, crm.GetCrmTypeCustomers)
c.Get("/customer/view/:id", requestAccessValidation, crm.GetCrmCustomer) c.Get("/customer/view/:id", requestAccessValidation, crm.GetCrmCustomer)
c.Post("/customer/update/:id", requestAccessValidation, crm.UpdateCrmCustomer) c.Post("/customer/update/:id", requestAccessValidation, crm.UpdateCrmCustomer)
c.Post("/customer/create", requestAccessValidation, crm.CreateCrmCustomer)
app.Static("/", config.Cfg.FolderPaths.PublicStatic) app.Static("/", config.Cfg.FolderPaths.PublicStatic)
} }