801 lines
20 KiB
Go
801 lines
20 KiB
Go
package yclients
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"encoding/json"
|
|
"errors"
|
|
|
|
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
|
"gitea.pena/SQuiz/common/model"
|
|
)
|
|
|
|
type YclientsRepository struct {
|
|
queries *sqlcgen.Queries
|
|
pool *sql.DB
|
|
}
|
|
|
|
type Deps struct {
|
|
Queries *sqlcgen.Queries
|
|
Pool *sql.DB
|
|
}
|
|
|
|
func NewYclientsRepository(deps Deps) *YclientsRepository {
|
|
return &YclientsRepository{
|
|
queries: deps.Queries,
|
|
pool: deps.Pool,
|
|
}
|
|
}
|
|
|
|
// users
|
|
func (r *YclientsRepository) GetCurrentAccount(ctx context.Context, accountID string) (*model.YclientsAccount, error) {
|
|
row, err := r.queries.GetCurrentYclientsCompany(ctx, accountID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
user := model.YclientsAccount{
|
|
ID: row.ID,
|
|
AccountID: row.Accountid,
|
|
SalonID: row.Salonid,
|
|
Title: row.Title,
|
|
Deleted: row.Deleted,
|
|
CreatedAt: row.Createdat,
|
|
}
|
|
|
|
return &user, nil
|
|
}
|
|
|
|
func (r *YclientsRepository) GetAllYclientsAccounts(ctx context.Context) ([]model.YclientsAccount, error) {
|
|
rows, err := r.queries.GetAllYclientsAccounts(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var result []model.YclientsAccount
|
|
for _, row := range rows {
|
|
result = append(result, model.YclientsAccount{
|
|
ID: row.ID,
|
|
AccountID: row.Accountid,
|
|
SalonID: row.Salonid,
|
|
Title: row.Title,
|
|
Deleted: row.Deleted,
|
|
CreatedAt: row.Createdat,
|
|
})
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (r *YclientsRepository) GettingUserWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.UserListYclientsResp, error) {
|
|
rows, err := r.queries.GetUsersYclientsWithPagination(ctx, sqlcgen.GetUsersYclientsWithPaginationParams{
|
|
Accountid: accountID,
|
|
Column2: req.Page,
|
|
Limit: req.Size,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var users []model.YclientsAccountUser
|
|
var count int64
|
|
for _, row := range rows {
|
|
users = append(users, model.YclientsAccountUser{
|
|
ID: row.ID,
|
|
SalonID: row.Salonid,
|
|
YclientsID: row.Yclientsid,
|
|
Name: row.Name,
|
|
IDPosition: row.Idposition,
|
|
TitlePosition: row.Titleposition,
|
|
Fired: row.Fired,
|
|
Status: row.Status,
|
|
Hidden: row.Hidden,
|
|
YclientsUserID: row.Yclientsuserid,
|
|
Deleted: row.Deleted,
|
|
CreatedAt: row.Createdat,
|
|
})
|
|
count = row.TotalCount
|
|
}
|
|
|
|
resp := model.UserListYclientsResp{
|
|
Count: count,
|
|
Items: users,
|
|
}
|
|
|
|
return &resp, nil
|
|
}
|
|
|
|
func (r *YclientsRepository) CreateAccount(ctx context.Context, account model.YclientsAccount) (*model.YclientsAccount, error) {
|
|
row, err := r.queries.CreateYclientsAccount(ctx, sqlcgen.CreateYclientsAccountParams{
|
|
Accountid: account.AccountID,
|
|
Salonid: account.SalonID,
|
|
Title: account.Title,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &model.YclientsAccount{
|
|
ID: row.ID,
|
|
AccountID: row.Accountid,
|
|
SalonID: row.Salonid,
|
|
Title: row.Title,
|
|
Deleted: row.Deleted,
|
|
CreatedAt: row.Createdat,
|
|
}, nil
|
|
|
|
}
|
|
|
|
func (r *YclientsRepository) GetUserUsersByID(ctx context.Context, salonID int32) ([]model.YclientsAccountUser, error) {
|
|
rows, err := r.queries.GetUsersByIDYclients(ctx, salonID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var users []model.YclientsAccountUser
|
|
for _, row := range rows {
|
|
users = append(users, model.YclientsAccountUser{
|
|
ID: row.ID,
|
|
SalonID: row.Salonid,
|
|
YclientsID: row.Yclientsid,
|
|
Name: row.Name,
|
|
IDPosition: row.Idposition,
|
|
TitlePosition: row.Titleposition,
|
|
Fired: row.Fired,
|
|
Status: row.Status,
|
|
Hidden: row.Hidden,
|
|
YclientsUserID: row.Yclientsuserid,
|
|
Deleted: row.Deleted,
|
|
CreatedAt: row.Createdat,
|
|
})
|
|
}
|
|
return users, nil
|
|
}
|
|
|
|
func (r *YclientsRepository) UpdateAccountUser(ctx context.Context, user model.YclientsAccountUser) error {
|
|
err := r.queries.UpdateYclientsAccountUser(ctx, sqlcgen.UpdateYclientsAccountUserParams{
|
|
Salonid: user.SalonID,
|
|
Yclientsid: user.YclientsID,
|
|
Name: user.Name,
|
|
Specialization: user.Specialization,
|
|
Idposition: user.IDPosition,
|
|
Titleposition: user.TitlePosition,
|
|
Fired: user.Fired,
|
|
Status: user.Status,
|
|
Hidden: user.Hidden,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (r *YclientsRepository) AddAccountUser(ctx context.Context, user model.YclientsAccountUser) error {
|
|
err := r.queries.AddYclientsAccountUser(ctx, sqlcgen.AddYclientsAccountUserParams{
|
|
Salonid: user.SalonID,
|
|
Yclientsid: user.YclientsID,
|
|
Name: user.Name,
|
|
Specialization: user.Specialization,
|
|
Idposition: user.IDPosition,
|
|
Titleposition: user.TitlePosition,
|
|
Fired: user.Fired,
|
|
Status: user.Status,
|
|
Hidden: user.Hidden,
|
|
Yclientsuserid: user.YclientsUserID,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (r *YclientsRepository) DeleteUsers(ctx context.Context, ids []int64) error {
|
|
err := r.queries.DeleteYclientsUsers(ctx, ids)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (r *YclientsRepository) SoftDeleteAccount(ctx context.Context, accountID string) error {
|
|
err := r.queries.SoftDeleteYclientsAccount(ctx, accountID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// company
|
|
//func (r *YclientsRepository) GettingCompanyWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.CompanyListYclientsResp, error) {
|
|
// rows, err := r.queries.GetCompanyYclientsWithPagination(ctx, sqlcgen.GetCompanyYclientsWithPaginationParams{
|
|
// Accountid: accountID,
|
|
// Column2: req.Page,
|
|
// Limit: req.Size,
|
|
// })
|
|
// if err != nil {
|
|
// return nil, err
|
|
// }
|
|
// var users []model.YclientsCompany
|
|
// var count int64
|
|
// for _, row := range rows {
|
|
// users = append(users, model.YclientsCompany{
|
|
// ID: row.ID,
|
|
// SalonID: row.Salonid,
|
|
// Title: row.Title,
|
|
// ShortDecription: row.Shortdecription,
|
|
// Active: row.Active,
|
|
// Country: row.Country,
|
|
// GroupPriority: row.Grouppriority,
|
|
// Deleted: row.Deleted,
|
|
// CreatedAt: row.Createdat,
|
|
// })
|
|
// count = row.TotalCount
|
|
// }
|
|
//
|
|
// resp := model.CompanyListYclientsResp{
|
|
// Count: count,
|
|
// Items: users,
|
|
// }
|
|
//
|
|
// return &resp, nil
|
|
//}
|
|
//
|
|
//func (r *YclientsRepository) UpdateCompany() {
|
|
//
|
|
//}
|
|
|
|
// services
|
|
|
|
func (r *YclientsRepository) GettingServicesWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.ServicesListYclientsResp, error) {
|
|
rows, err := r.queries.GetServicesYclientsWithPagination(ctx, sqlcgen.GetServicesYclientsWithPaginationParams{
|
|
Accountid: accountID,
|
|
Column2: req.Page,
|
|
Limit: req.Size,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var services []model.YclientsServices
|
|
var count int64
|
|
for _, row := range rows {
|
|
var staff []model.YclientsServiceStaff
|
|
err = json.Unmarshal(row.Staff, &staff)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
services = append(services, model.YclientsServices{
|
|
ID: row.ID,
|
|
SalonID: row.Salonid,
|
|
ServiceID: row.Serviceid,
|
|
SalonServiceID: row.Salonserviceid,
|
|
Title: row.Title,
|
|
CategoryID: row.Categoryid,
|
|
PriceMin: row.Pricemin,
|
|
PriceMax: row.Pricemax,
|
|
Discount: row.Discount,
|
|
Comment: row.Comment,
|
|
Active: row.Active,
|
|
ApiID: row.Apiid,
|
|
Staff: staff,
|
|
Deleted: row.Deleted,
|
|
CreatedAt: row.Createdat,
|
|
})
|
|
count = row.TotalCount
|
|
}
|
|
|
|
resp := model.ServicesListYclientsResp{
|
|
Count: count,
|
|
Items: services,
|
|
}
|
|
|
|
return &resp, nil
|
|
}
|
|
|
|
func (r *YclientsRepository) GetAccountServicesByID(ctx context.Context, salonID int32) ([]model.YclientsServices, error) {
|
|
rows, err := r.queries.GetServicesByIDYclients(ctx, salonID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var services []model.YclientsServices
|
|
for _, row := range rows {
|
|
var staff []model.YclientsServiceStaff
|
|
err = json.Unmarshal(row.Staff, &staff)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
services = append(services, model.YclientsServices{
|
|
ID: row.ID,
|
|
SalonID: row.Salonid,
|
|
ServiceID: row.Serviceid,
|
|
SalonServiceID: row.Salonserviceid,
|
|
Title: row.Title,
|
|
CategoryID: row.Categoryid,
|
|
PriceMin: row.Pricemin,
|
|
PriceMax: row.Pricemax,
|
|
Discount: row.Discount,
|
|
Comment: row.Comment,
|
|
Active: row.Active,
|
|
ApiID: row.Apiid,
|
|
Staff: staff,
|
|
Deleted: row.Deleted,
|
|
CreatedAt: row.Createdat,
|
|
})
|
|
}
|
|
return services, nil
|
|
}
|
|
|
|
func (r *YclientsRepository) UpdateAccountServices(ctx context.Context, service model.YclientsServices) error {
|
|
staff, err := json.Marshal(service.Staff)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = r.queries.UpdateYclientsAccountServices(ctx, sqlcgen.UpdateYclientsAccountServicesParams{
|
|
Salonid: service.SalonID,
|
|
Serviceid: service.ServiceID,
|
|
Salonserviceid: service.SalonServiceID,
|
|
Title: service.Title,
|
|
Categoryid: service.CategoryID,
|
|
Pricemin: service.PriceMin,
|
|
Pricemax: service.PriceMax,
|
|
Discount: service.Discount,
|
|
Comment: service.Comment,
|
|
Active: service.Active,
|
|
Apiid: service.ApiID,
|
|
Staff: staff,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (r *YclientsRepository) AddAccountService(ctx context.Context, service model.YclientsServices) error {
|
|
staff, err := json.Marshal(service.Staff)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = r.queries.AddYclientsAccountService(ctx, sqlcgen.AddYclientsAccountServiceParams{
|
|
Salonid: service.SalonID,
|
|
Serviceid: service.ServiceID,
|
|
Salonserviceid: service.SalonServiceID,
|
|
Title: service.Title,
|
|
Categoryid: service.CategoryID,
|
|
Pricemin: service.PriceMin,
|
|
Pricemax: service.PriceMax,
|
|
Discount: service.Discount,
|
|
Comment: service.Comment,
|
|
Active: service.Active,
|
|
Apiid: service.ApiID,
|
|
Staff: staff,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (r *YclientsRepository) DeleteServices(ctx context.Context, ids []int64) error {
|
|
err := r.queries.DeleteYclientsServices(ctx, ids)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// timeslots
|
|
|
|
func (r *YclientsRepository) GettingTimeslotsWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.TimeslotsListYclientsResp, error) {
|
|
rows, err := r.queries.GetTimeslotsYclientsWithPagination(ctx, sqlcgen.GetTimeslotsYclientsWithPaginationParams{
|
|
Accountid: accountID,
|
|
Column2: req.Page,
|
|
Limit: req.Size,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var timeslots []model.Timeslots
|
|
var count int64
|
|
for _, row := range rows {
|
|
var weekdaysSettings []model.WeekdaySetting
|
|
err = json.Unmarshal(row.Weekdayssettings, &weekdaysSettings)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var datesSettings []model.DateSetting
|
|
err = json.Unmarshal(row.Datessettings, &datesSettings)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
timeslots = append(timeslots, model.Timeslots{
|
|
ID: row.ID,
|
|
SalonID: row.Salonid,
|
|
IsEnabled: row.Isenabled,
|
|
WeekdaysSettings: weekdaysSettings,
|
|
DatesSettings: datesSettings,
|
|
Deleted: row.Deleted,
|
|
CreatedAt: row.Createdat,
|
|
})
|
|
count = row.TotalCount
|
|
}
|
|
|
|
resp := model.TimeslotsListYclientsResp{
|
|
Count: count,
|
|
Items: timeslots,
|
|
}
|
|
|
|
return &resp, nil
|
|
}
|
|
|
|
func (r *YclientsRepository) UpdateAccountTimeslots(ctx context.Context, salonID int32, timeslots model.Timeslots) error {
|
|
weekdaysSettings, err := json.Marshal(timeslots.WeekdaysSettings)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
datesSettings, err := json.Marshal(timeslots.DatesSettings)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = r.queries.UpdateYclientsAccountTimeslots(ctx, sqlcgen.UpdateYclientsAccountTimeslotsParams{
|
|
Salonid: salonID,
|
|
Isenabled: timeslots.IsEnabled,
|
|
Weekdayssettings: weekdaysSettings,
|
|
Datessettings: datesSettings,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (r *YclientsRepository) AddAccountTimeslots(ctx context.Context, salonID int32, timeslots model.Timeslots) (int64, error) {
|
|
weekdaysSettings, err := json.Marshal(timeslots.WeekdaysSettings)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
datesSettings, err := json.Marshal(timeslots.DatesSettings)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
row, err := r.queries.AddYclientsAccountTimeslots(ctx, sqlcgen.AddYclientsAccountTimeslotsParams{
|
|
Salonid: salonID,
|
|
Isenabled: timeslots.IsEnabled,
|
|
Weekdayssettings: weekdaysSettings,
|
|
Datessettings: datesSettings,
|
|
})
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return row.ID, nil
|
|
}
|
|
|
|
func (r *YclientsRepository) DeleteTimeslots(ctx context.Context, ids []int64) error {
|
|
err := r.queries.DeleteYclientsTimeslots(ctx, ids)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (r *YclientsRepository) GetAccountTimeslotsByID(ctx context.Context, salonID int32) (*model.Timeslots, error) {
|
|
row, err := r.queries.GetTimeslotsByIDYclients(ctx, salonID)
|
|
if err != nil {
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return nil, nil
|
|
}
|
|
return nil, err
|
|
}
|
|
|
|
var weekdaysSettings []model.WeekdaySetting
|
|
err = json.Unmarshal(row.Weekdayssettings, &weekdaysSettings)
|
|
if err != nil {
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var datesSettings []model.DateSetting
|
|
err = json.Unmarshal(row.Datessettings, &datesSettings)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &model.Timeslots{
|
|
ID: row.ID,
|
|
SalonID: row.Salonid,
|
|
IsEnabled: row.Isenabled,
|
|
WeekdaysSettings: weekdaysSettings,
|
|
DatesSettings: datesSettings,
|
|
Deleted: row.Deleted,
|
|
CreatedAt: row.Createdat,
|
|
}, nil
|
|
}
|
|
|
|
// rule
|
|
|
|
func (r *YclientsRepository) GettingQuizRules(ctx context.Context, quizID int32) (*model.YclientsRule, error) {
|
|
row, err := r.queries.GetYclientsQuizRule(ctx, quizID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var services []model.ServiceYclientsRule
|
|
err = json.Unmarshal(row.Services, &services)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var fieldsRule model.YclientsFieldRule
|
|
err = json.Unmarshal(row.Fieldsrule, &fieldsRule)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &model.YclientsRule{
|
|
ID: row.ID,
|
|
SalonID: row.Salonid,
|
|
QuizID: row.Quizid,
|
|
Services: services,
|
|
FieldsRule: fieldsRule,
|
|
CustomColor: row.Customcolor,
|
|
Deleted: row.Deleted,
|
|
CreatedAt: row.Createdat,
|
|
StaffID: row.Staffid,
|
|
}, nil
|
|
}
|
|
|
|
func (r *YclientsRepository) SetQuizSettings(ctx context.Context, rule model.YclientsRule, accountID string) error {
|
|
jsonServices, err := json.Marshal(rule.Services)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
jsonFieldsRule, err := json.Marshal(rule.FieldsRule)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = r.queries.SetYclientsQuizSettings(ctx, sqlcgen.SetYclientsQuizSettingsParams{
|
|
Quizid: rule.QuizID,
|
|
Staffid: rule.StaffID,
|
|
Services: jsonServices,
|
|
Fieldsrule: jsonFieldsRule,
|
|
Customcolor: rule.CustomColor,
|
|
Accountid: accountID,
|
|
})
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (r *YclientsRepository) ChangeQuizSettings(ctx context.Context, rule model.YclientsRule, accountID string) error {
|
|
jsonServices, err := json.Marshal(rule.Services)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
jsonFieldsRule, err := json.Marshal(rule.FieldsRule)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = r.queries.ChangeYclientsQuizSettings(ctx, sqlcgen.ChangeYclientsQuizSettingsParams{
|
|
Quizid: rule.QuizID,
|
|
Staffid: rule.StaffID,
|
|
Services: jsonServices,
|
|
Fieldsrule: jsonFieldsRule,
|
|
Customcolor: rule.CustomColor,
|
|
Accountid: accountID,
|
|
})
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (r *YclientsRepository) UpdateFieldRules(ctx context.Context, fieldRules model.YclientsFieldRule, salonID int32, quizID int32) error {
|
|
jsonFieldsRule, err := json.Marshal(fieldRules)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = r.queries.UpdateYclientsFieldRules(ctx, sqlcgen.UpdateYclientsFieldRulesParams{
|
|
Fieldsrule: jsonFieldsRule,
|
|
Salonid: salonID,
|
|
Quizid: quizID,
|
|
})
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// fields
|
|
func (r *YclientsRepository) GetFieldsWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.UserListYclientsFieldsResp, error) {
|
|
rows, err := r.queries.GetYclientsFieldsWithPagination(ctx, sqlcgen.GetYclientsFieldsWithPaginationParams{
|
|
Accountid: accountID,
|
|
Column2: req.Page,
|
|
Limit: req.Size,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var count int64
|
|
var fields []model.YclientsField
|
|
|
|
for _, row := range rows {
|
|
count = row.TotalCount
|
|
|
|
var fieldType model.YclientsCustomFieldsType
|
|
f := string(row.Fieldtype.([]byte))
|
|
fieldType = model.YclientsCustomFieldsType(f)
|
|
|
|
fields = append(fields, model.YclientsField{
|
|
ID: row.ID,
|
|
YclientsID: row.Yclientsid,
|
|
SalonID: row.Salonid,
|
|
FieldType: fieldType,
|
|
Code: row.Code,
|
|
Title: row.Title,
|
|
ShowINUI: row.Showinui,
|
|
UserCanEdit: row.Usercanedit,
|
|
Deleted: row.Deleted,
|
|
CreatedAt: row.Createdat,
|
|
})
|
|
}
|
|
|
|
resp := model.UserListYclientsFieldsResp{
|
|
Count: count,
|
|
Items: fields,
|
|
}
|
|
|
|
return &resp, nil
|
|
}
|
|
|
|
func (r *YclientsRepository) AddAccountField(ctx context.Context, field model.YclientsField) error {
|
|
err := r.queries.AddYclientsAccountField(ctx, sqlcgen.AddYclientsAccountFieldParams{
|
|
Yclientsid: field.YclientsID,
|
|
Salonid: field.SalonID,
|
|
Fieldtype: field.FieldType,
|
|
Code: field.Code,
|
|
Title: field.Title,
|
|
Showinui: field.ShowINUI,
|
|
Usercanedit: field.UserCanEdit,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (r *YclientsRepository) UpdateAccountFields(ctx context.Context, salonID int32, field model.YclientsField) error {
|
|
err := r.queries.UpdateYclientsAccountFields(ctx, sqlcgen.UpdateYclientsAccountFieldsParams{
|
|
Salonid: salonID,
|
|
Yclientsid: field.YclientsID,
|
|
Fieldtype: field.FieldType,
|
|
Code: field.Code,
|
|
Title: field.Title,
|
|
Showinui: field.ShowINUI,
|
|
Usercanedit: field.UserCanEdit,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (r *YclientsRepository) GetUserFieldsByID(ctx context.Context, salonID int32) ([]model.YclientsField, error) {
|
|
rows, err := r.queries.GetUserYclientsFieldsByID(ctx, salonID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var fields []model.YclientsField
|
|
for _, row := range rows {
|
|
var fieldType model.YclientsCustomFieldsType
|
|
f := string(row.Fieldtype.([]byte))
|
|
fieldType = model.YclientsCustomFieldsType(f)
|
|
|
|
fields = append(fields, model.YclientsField{
|
|
ID: row.ID,
|
|
YclientsID: row.Yclientsid,
|
|
SalonID: row.Salonid,
|
|
FieldType: fieldType,
|
|
Code: row.Code,
|
|
Title: row.Title,
|
|
ShowINUI: row.Showinui,
|
|
UserCanEdit: row.Usercanedit,
|
|
Deleted: row.Deleted,
|
|
CreatedAt: row.Createdat,
|
|
})
|
|
}
|
|
return fields, nil
|
|
}
|
|
|
|
func (r *YclientsRepository) DeleteFields(ctx context.Context, ids []int64) error {
|
|
err := r.queries.DeleteYclientsFields(ctx, ids)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// true results fetch
|
|
// todo нужно хорошенько проверить
|
|
func (r *YclientsRepository) GettingYclientsUsersTrueResults(ctx context.Context) ([]model.YclientsUsersTrueResults, error) {
|
|
rows, err := r.queries.GettingYclientsUsersTrueResults(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var results []model.YclientsUsersTrueResults
|
|
|
|
for _, row := range rows {
|
|
var fieldsRule model.YclientsFieldRule
|
|
err = json.Unmarshal(row.Fieldsrule, &fieldsRule)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var utms model.UTMSavingMap
|
|
err = json.Unmarshal(row.Utm.([]byte), &utms)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var services []model.ServiceYclientsRule
|
|
err = json.Unmarshal(row.Services, &services)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
result := model.YclientsUsersTrueResults{
|
|
QuizID: row.QuizID,
|
|
AnswerID: row.AnswerID,
|
|
Result: row.Result.Bool,
|
|
QuestionID: row.QuestionID,
|
|
Content: row.Content.String,
|
|
Session: row.Session.String,
|
|
SalonID: row.Salonid,
|
|
UTMs: utms,
|
|
FieldsRule: fieldsRule,
|
|
StaffID: row.Staffid,
|
|
Services: services,
|
|
CustomColor: row.Customcolor,
|
|
QuizAccountID: row.QuizAccountid,
|
|
Datetime: row.Datetime.Time,
|
|
}
|
|
|
|
results = append(results, result)
|
|
}
|
|
|
|
return results, nil
|
|
}
|
|
|
|
type SaveDealYclientsDeps struct {
|
|
RecordID int32
|
|
AnswerID int64
|
|
Status string
|
|
SalonID int32
|
|
}
|
|
|
|
func (r *YclientsRepository) SaveDealYclientsStatus(ctx context.Context, deps SaveDealYclientsDeps) error {
|
|
err := r.queries.SaveDealYclientsStatus(ctx, sqlcgen.SaveDealYclientsStatusParams{
|
|
Recordid: deps.RecordID,
|
|
Answerid: deps.AnswerID,
|
|
Status: deps.Status,
|
|
Salonid: deps.SalonID,
|
|
})
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|