added new field in table YclientsRules

This commit is contained in:
Pasha 2025-10-27 17:33:35 +03:00
parent 3af23cc4d3
commit f1da78811b
6 changed files with 42 additions and 13 deletions

@ -1620,12 +1620,12 @@ SELECT 1;
SELECT * FROM YclientsRules WHERE QuizID = $1 AND Deleted = false; SELECT * FROM YclientsRules WHERE QuizID = $1 AND Deleted = false;
-- name: SetYclientsQuizSettings :one -- name: SetYclientsQuizSettings :one
INSERT INTO YclientsRules (SalonID, QuizID, Services, CustomColor) INSERT INTO YclientsRules (SalonID, QuizID, Services,FieldsRule, CustomColor)
SELECT ya.SalonID, $1 AS QuizID, $2 AS Services, $3 AS CustomColor SELECT ya.SalonID, $1 AS QuizID, $2 AS Services, $3 AS FieldsRule, $4 AS CustomColor
FROM YclientsAccounts ya WHERE ya.AccountID = $4 AND ya.Deleted = false FROM YclientsAccounts ya WHERE ya.AccountID = $5 AND ya.Deleted = false
RETURNING id; RETURNING id;
-- name: ChangeYclientsQuizSettings :one -- name: ChangeYclientsQuizSettings :one
UPDATE YclientsRules SET Services = $1, CustomColor = $2 UPDATE YclientsRules SET Services = $1, CustomColor = $2,FieldsRule = $3
WHERE SalonID = (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $3 AND YclientsAccounts.Deleted = false) WHERE SalonID = (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $4 AND YclientsAccounts.Deleted = false)
AND QuizID = $4 AND Deleted = false RETURNING id; AND QuizID = $5 AND Deleted = false RETURNING id;

@ -81,6 +81,7 @@ CREATE TABLE IF NOT EXISTS YclientsRules (
SalonID INT NOT NULL, -- ID компании SalonID INT NOT NULL, -- ID компании
QuizID INT NOT NULL, -- ID квиза на которое вешается правило QuizID INT NOT NULL, -- ID квиза на которое вешается правило
Services JSONB NOT NULL DEFAULT '{}', Services JSONB NOT NULL DEFAULT '{}',
FieldsRule JSONB NOT NULL DEFAULT '{}',
CustomColor text NOT NULL Default '', CustomColor text NOT NULL Default '',
Deleted BOOLEAN NOT NULL DEFAULT FALSE, Deleted BOOLEAN NOT NULL DEFAULT FALSE,
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP

@ -431,6 +431,7 @@ type Yclientsrule struct {
Salonid int32 `db:"salonid" json:"salonid"` Salonid int32 `db:"salonid" json:"salonid"`
Quizid int32 `db:"quizid" json:"quizid"` Quizid int32 `db:"quizid" json:"quizid"`
Services json.RawMessage `db:"services" json:"services"` Services json.RawMessage `db:"services" json:"services"`
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
Customcolor string `db:"customcolor" json:"customcolor"` Customcolor string `db:"customcolor" json:"customcolor"`
Deleted bool `db:"deleted" json:"deleted"` Deleted bool `db:"deleted" json:"deleted"`
Createdat time.Time `db:"createdat" json:"createdat"` Createdat time.Time `db:"createdat" json:"createdat"`

@ -342,14 +342,15 @@ func (q *Queries) ChangeQuizSettings(ctx context.Context, arg ChangeQuizSettings
} }
const changeYclientsQuizSettings = `-- name: ChangeYclientsQuizSettings :one const changeYclientsQuizSettings = `-- name: ChangeYclientsQuizSettings :one
UPDATE YclientsRules SET Services = $1, CustomColor = $2 UPDATE YclientsRules SET Services = $1, CustomColor = $2,FieldsRule = $3
WHERE SalonID = (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $3 AND YclientsAccounts.Deleted = false) WHERE SalonID = (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $4 AND YclientsAccounts.Deleted = false)
AND QuizID = $4 AND Deleted = false RETURNING id AND QuizID = $5 AND Deleted = false RETURNING id
` `
type ChangeYclientsQuizSettingsParams struct { type ChangeYclientsQuizSettingsParams struct {
Services json.RawMessage `db:"services" json:"services"` Services json.RawMessage `db:"services" json:"services"`
Customcolor string `db:"customcolor" json:"customcolor"` Customcolor string `db:"customcolor" json:"customcolor"`
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
Accountid string `db:"accountid" json:"accountid"` Accountid string `db:"accountid" json:"accountid"`
Quizid int32 `db:"quizid" json:"quizid"` Quizid int32 `db:"quizid" json:"quizid"`
} }
@ -358,6 +359,7 @@ func (q *Queries) ChangeYclientsQuizSettings(ctx context.Context, arg ChangeYcli
row := q.db.QueryRowContext(ctx, changeYclientsQuizSettings, row := q.db.QueryRowContext(ctx, changeYclientsQuizSettings,
arg.Services, arg.Services,
arg.Customcolor, arg.Customcolor,
arg.Fieldsrule,
arg.Accountid, arg.Accountid,
arg.Quizid, arg.Quizid,
) )
@ -4791,7 +4793,7 @@ func (q *Queries) GetUsersYclientsWithPagination(ctx context.Context, arg GetUse
} }
const getYclientsQuizRule = `-- name: GetYclientsQuizRule :one const getYclientsQuizRule = `-- name: GetYclientsQuizRule :one
SELECT id, salonid, quizid, services, customcolor, deleted, createdat FROM YclientsRules WHERE QuizID = $1 AND Deleted = false SELECT id, salonid, quizid, services, fieldsrule, customcolor, deleted, createdat FROM YclientsRules WHERE QuizID = $1 AND Deleted = false
` `
func (q *Queries) GetYclientsQuizRule(ctx context.Context, quizid int32) (Yclientsrule, error) { func (q *Queries) GetYclientsQuizRule(ctx context.Context, quizid int32) (Yclientsrule, error) {
@ -4802,6 +4804,7 @@ func (q *Queries) GetYclientsQuizRule(ctx context.Context, quizid int32) (Yclien
&i.Salonid, &i.Salonid,
&i.Quizid, &i.Quizid,
&i.Services, &i.Services,
&i.Fieldsrule,
&i.Customcolor, &i.Customcolor,
&i.Deleted, &i.Deleted,
&i.Createdat, &i.Createdat,
@ -5703,15 +5706,16 @@ func (q *Queries) SetQuizSettings(ctx context.Context, arg SetQuizSettingsParams
} }
const setYclientsQuizSettings = `-- name: SetYclientsQuizSettings :one const setYclientsQuizSettings = `-- name: SetYclientsQuizSettings :one
INSERT INTO YclientsRules (SalonID, QuizID, Services, CustomColor) INSERT INTO YclientsRules (SalonID, QuizID, Services,FieldsRule, CustomColor)
SELECT ya.SalonID, $1 AS QuizID, $2 AS Services, $3 AS CustomColor SELECT ya.SalonID, $1 AS QuizID, $2 AS Services, $3 AS FieldsRule, $4 AS CustomColor
FROM YclientsAccounts ya WHERE ya.AccountID = $4 AND ya.Deleted = false FROM YclientsAccounts ya WHERE ya.AccountID = $5 AND ya.Deleted = false
RETURNING id RETURNING id
` `
type SetYclientsQuizSettingsParams struct { type SetYclientsQuizSettingsParams struct {
Quizid int32 `db:"quizid" json:"quizid"` Quizid int32 `db:"quizid" json:"quizid"`
Services json.RawMessage `db:"services" json:"services"` Services json.RawMessage `db:"services" json:"services"`
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
Customcolor string `db:"customcolor" json:"customcolor"` Customcolor string `db:"customcolor" json:"customcolor"`
Accountid string `db:"accountid" json:"accountid"` Accountid string `db:"accountid" json:"accountid"`
} }
@ -5720,6 +5724,7 @@ func (q *Queries) SetYclientsQuizSettings(ctx context.Context, arg SetYclientsQu
row := q.db.QueryRowContext(ctx, setYclientsQuizSettings, row := q.db.QueryRowContext(ctx, setYclientsQuizSettings,
arg.Quizid, arg.Quizid,
arg.Services, arg.Services,
arg.Fieldsrule,
arg.Customcolor, arg.Customcolor,
arg.Accountid, arg.Accountid,
) )

@ -131,11 +131,16 @@ type YclientsRule struct {
SalonID int32 `json:"salon_id"` // ID "аккаунта который ГЛАВНЫЙ" SalonID int32 `json:"salon_id"` // ID "аккаунта который ГЛАВНЫЙ"
QuizID int32 `json:"quizID"` // ID квиза на которое вешается правило QuizID int32 `json:"quizID"` // ID квиза на которое вешается правило
Services ServiceYclientsRule `json:"services"` Services ServiceYclientsRule `json:"services"`
FieldsRule YclientsFieldRule `json:"fields_rule"`
CustomColor string `json:"custom_color"` CustomColor string `json:"custom_color"`
Deleted bool `json:"deleted"` Deleted bool `json:"deleted"`
CreatedAt time.Time `json:"createdAt"` CreatedAt time.Time `json:"createdAt"`
} }
type YclientsFieldRule struct {
QuestionID map[int]string `json:"question_id"`
}
type ServiceYclientsRule struct { type ServiceYclientsRule struct {
ID int `json:"id"` ID int `json:"id"`
FirstCost int `json:"first_cost"` FirstCost int `json:"first_cost"`

@ -614,11 +614,18 @@ func (r *YclientsRepository) GettingQuizRules(ctx context.Context, quizID int32)
return nil, err return nil, err
} }
var fieldsRule model.YclientsFieldRule
err = json.Unmarshal(row.Fieldsrule, &fieldsRule)
if err != nil {
return nil, err
}
return &model.YclientsRule{ return &model.YclientsRule{
ID: row.ID, ID: row.ID,
SalonID: row.Salonid, SalonID: row.Salonid,
QuizID: row.Quizid, QuizID: row.Quizid,
Services: services, Services: services,
FieldsRule: fieldsRule,
CustomColor: row.Customcolor, CustomColor: row.Customcolor,
Deleted: row.Deleted, Deleted: row.Deleted,
CreatedAt: row.Createdat, CreatedAt: row.Createdat,
@ -630,9 +637,14 @@ func (r *YclientsRepository) SetQuizSettings(ctx context.Context, rule model.Ycl
if err != nil { if err != nil {
return err return err
} }
jsonFieldsRule, err := json.Marshal(rule.FieldsRule)
if err != nil {
return err
}
_, err = r.queries.SetYclientsQuizSettings(ctx, sqlcgen.SetYclientsQuizSettingsParams{ _, err = r.queries.SetYclientsQuizSettings(ctx, sqlcgen.SetYclientsQuizSettingsParams{
Quizid: rule.QuizID, Quizid: rule.QuizID,
Services: jsonServices, Services: jsonServices,
Fieldsrule: jsonFieldsRule,
Customcolor: rule.CustomColor, Customcolor: rule.CustomColor,
Accountid: accountID, Accountid: accountID,
}) })
@ -649,9 +661,14 @@ func (r *YclientsRepository) ChangeQuizSettings(ctx context.Context, rule model.
if err != nil { if err != nil {
return err return err
} }
jsonFieldsRule, err := json.Marshal(rule.FieldsRule)
if err != nil {
return err
}
_, err = r.queries.ChangeYclientsQuizSettings(ctx, sqlcgen.ChangeYclientsQuizSettingsParams{ _, err = r.queries.ChangeYclientsQuizSettings(ctx, sqlcgen.ChangeYclientsQuizSettingsParams{
Quizid: rule.QuizID, Quizid: rule.QuizID,
Services: jsonServices, Services: jsonServices,
Fieldsrule: jsonFieldsRule,
Customcolor: rule.CustomColor, Customcolor: rule.CustomColor,
Accountid: accountID, Accountid: accountID,
}) })