ccompany name

main
alex 2024-03-06 23:23:00 +01:00
parent 0a33f59345
commit 73b8fae588
4 changed files with 22 additions and 0 deletions

BIN
main

Binary file not shown.

View File

@ -51,6 +51,7 @@ type CrmTableCustomer struct {
DealPhase uint8
FirstName string
LastName string
Company string
CreatedAt time.Time
Telephone string
Email string

View File

@ -1200,6 +1200,12 @@
"CrmTableCustomer": {
"type": "object",
"properties": {
"AssignedEmployee": {
"type": "string"
},
"Company": {
"type": "string"
},
"CreatedAt": {
"type": "string",
"format": "date-time"

View File

@ -1,6 +1,7 @@
package crm
import (
"fmt"
"jannex/admin-dashboard-backend/modules/crm"
"jannex/admin-dashboard-backend/modules/database"
"jannex/admin-dashboard-backend/modules/logger"
@ -285,8 +286,22 @@ func CreateCrmCustomer(c *fiber.Ctx) error {
crmCustomer["CreatedBy"] = c.Locals("userId").(string)
crmCustomer["CreatedAt"] = time.Now()
// check if company name already exists
var count int64
database.DB.Model(&structs.CrmCustomer{}).Where("company = ?", crmCustomer["Company"]).Count(&count)
fmt.Println("count", count, crmCustomer["Company"])
if count > 0 {
logger.AddCrmLog(rslogger.LogTypeError, "Failed to create crm customer as company name already exists: %v", crmCustomer)
return c.SendStatus(fiber.StatusConflict)
}
result := database.DB.Model(&structs.CrmCustomer{}).Create(&crmCustomer)
// TODO: thats not working correctly
if err := handleError(result, c); err != nil {
return err
}