Files
libredesk/internal/user/contact.go
T
Abhinav Raut 50188352a5 fix: Use SyncedEnforcer in casbin, fixes panics.
feat: store user roles in user roles table, drops the roles table on users table.
feat: standardize column names in schema, renames disabled bool to enables.
- vue router fixes to allow components / pages to rerender after creating an object in db.
- minor fixes and refactors.
2025-01-22 03:40:32 +05:30

28 lines
828 B
Go

package user
import (
"fmt"
"strings"
"github.com/abhinavxd/libredesk/internal/user/models"
"github.com/volatiletech/null/v9"
)
// CreateContact creates a new contact user.
func (u *Manager) CreateContact(user *models.User) error {
password, err := u.generatePassword()
if err != nil {
u.lo.Error("generating password", "error", err)
return fmt.Errorf("generating password: %w", err)
}
// Normalize email address.
user.Email = null.NewString(strings.ToLower(user.Email.String), user.Email.Valid)
if err := u.q.InsertContact.QueryRow(user.Email, user.FirstName, user.LastName, password, user.AvatarURL, user.InboxID, user.SourceChannelID).Scan(&user.ID, &user.ContactChannelID); err != nil {
u.lo.Error("error inserting contact", "error", err)
return fmt.Errorf("insert contact: %w", err)
}
return nil
}