added new field in table YclientsRules
This commit is contained in:
parent
3af23cc4d3
commit
f1da78811b
@ -1620,12 +1620,12 @@ SELECT 1;
|
||||
SELECT * FROM YclientsRules WHERE QuizID = $1 AND Deleted = false;
|
||||
|
||||
-- name: SetYclientsQuizSettings :one
|
||||
INSERT INTO YclientsRules (SalonID, QuizID, Services, CustomColor)
|
||||
SELECT ya.SalonID, $1 AS QuizID, $2 AS Services, $3 AS CustomColor
|
||||
FROM YclientsAccounts ya WHERE ya.AccountID = $4 AND ya.Deleted = false
|
||||
INSERT INTO YclientsRules (SalonID, QuizID, Services,FieldsRule, CustomColor)
|
||||
SELECT ya.SalonID, $1 AS QuizID, $2 AS Services, $3 AS FieldsRule, $4 AS CustomColor
|
||||
FROM YclientsAccounts ya WHERE ya.AccountID = $5 AND ya.Deleted = false
|
||||
RETURNING id;
|
||||
|
||||
-- name: ChangeYclientsQuizSettings :one
|
||||
UPDATE YclientsRules SET Services = $1, CustomColor = $2
|
||||
WHERE SalonID = (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $3 AND YclientsAccounts.Deleted = false)
|
||||
AND QuizID = $4 AND Deleted = false RETURNING id;
|
||||
UPDATE YclientsRules SET Services = $1, CustomColor = $2,FieldsRule = $3
|
||||
WHERE SalonID = (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $4 AND YclientsAccounts.Deleted = false)
|
||||
AND QuizID = $5 AND Deleted = false RETURNING id;
|
||||
@ -81,6 +81,7 @@ CREATE TABLE IF NOT EXISTS YclientsRules (
|
||||
SalonID INT NOT NULL, -- ID компании
|
||||
QuizID INT NOT NULL, -- ID квиза на которое вешается правило
|
||||
Services JSONB NOT NULL DEFAULT '{}',
|
||||
FieldsRule JSONB NOT NULL DEFAULT '{}',
|
||||
CustomColor text NOT NULL Default '',
|
||||
Deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
|
||||
@ -431,6 +431,7 @@ type Yclientsrule struct {
|
||||
Salonid int32 `db:"salonid" json:"salonid"`
|
||||
Quizid int32 `db:"quizid" json:"quizid"`
|
||||
Services json.RawMessage `db:"services" json:"services"`
|
||||
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
||||
Customcolor string `db:"customcolor" json:"customcolor"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
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
|
||||
UPDATE YclientsRules SET Services = $1, CustomColor = $2
|
||||
WHERE SalonID = (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $3 AND YclientsAccounts.Deleted = false)
|
||||
AND QuizID = $4 AND Deleted = false RETURNING id
|
||||
UPDATE YclientsRules SET Services = $1, CustomColor = $2,FieldsRule = $3
|
||||
WHERE SalonID = (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $4 AND YclientsAccounts.Deleted = false)
|
||||
AND QuizID = $5 AND Deleted = false RETURNING id
|
||||
`
|
||||
|
||||
type ChangeYclientsQuizSettingsParams struct {
|
||||
Services json.RawMessage `db:"services" json:"services"`
|
||||
Customcolor string `db:"customcolor" json:"customcolor"`
|
||||
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
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,
|
||||
arg.Services,
|
||||
arg.Customcolor,
|
||||
arg.Fieldsrule,
|
||||
arg.Accountid,
|
||||
arg.Quizid,
|
||||
)
|
||||
@ -4791,7 +4793,7 @@ func (q *Queries) GetUsersYclientsWithPagination(ctx context.Context, arg GetUse
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -4802,6 +4804,7 @@ func (q *Queries) GetYclientsQuizRule(ctx context.Context, quizid int32) (Yclien
|
||||
&i.Salonid,
|
||||
&i.Quizid,
|
||||
&i.Services,
|
||||
&i.Fieldsrule,
|
||||
&i.Customcolor,
|
||||
&i.Deleted,
|
||||
&i.Createdat,
|
||||
@ -5703,15 +5706,16 @@ func (q *Queries) SetQuizSettings(ctx context.Context, arg SetQuizSettingsParams
|
||||
}
|
||||
|
||||
const setYclientsQuizSettings = `-- name: SetYclientsQuizSettings :one
|
||||
INSERT INTO YclientsRules (SalonID, QuizID, Services, CustomColor)
|
||||
SELECT ya.SalonID, $1 AS QuizID, $2 AS Services, $3 AS CustomColor
|
||||
FROM YclientsAccounts ya WHERE ya.AccountID = $4 AND ya.Deleted = false
|
||||
INSERT INTO YclientsRules (SalonID, QuizID, Services,FieldsRule, CustomColor)
|
||||
SELECT ya.SalonID, $1 AS QuizID, $2 AS Services, $3 AS FieldsRule, $4 AS CustomColor
|
||||
FROM YclientsAccounts ya WHERE ya.AccountID = $5 AND ya.Deleted = false
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
type SetYclientsQuizSettingsParams struct {
|
||||
Quizid int32 `db:"quizid" json:"quizid"`
|
||||
Services json.RawMessage `db:"services" json:"services"`
|
||||
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
||||
Customcolor string `db:"customcolor" json:"customcolor"`
|
||||
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,
|
||||
arg.Quizid,
|
||||
arg.Services,
|
||||
arg.Fieldsrule,
|
||||
arg.Customcolor,
|
||||
arg.Accountid,
|
||||
)
|
||||
|
||||
@ -131,11 +131,16 @@ type YclientsRule struct {
|
||||
SalonID int32 `json:"salon_id"` // ID "аккаунта который ГЛАВНЫЙ"
|
||||
QuizID int32 `json:"quizID"` // ID квиза на которое вешается правило
|
||||
Services ServiceYclientsRule `json:"services"`
|
||||
FieldsRule YclientsFieldRule `json:"fields_rule"`
|
||||
CustomColor string `json:"custom_color"`
|
||||
Deleted bool `json:"deleted"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
type YclientsFieldRule struct {
|
||||
QuestionID map[int]string `json:"question_id"`
|
||||
}
|
||||
|
||||
type ServiceYclientsRule struct {
|
||||
ID int `json:"id"`
|
||||
FirstCost int `json:"first_cost"`
|
||||
|
||||
@ -614,11 +614,18 @@ func (r *YclientsRepository) GettingQuizRules(ctx context.Context, quizID int32)
|
||||
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,
|
||||
@ -630,9 +637,14 @@ func (r *YclientsRepository) SetQuizSettings(ctx context.Context, rule model.Ycl
|
||||
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,
|
||||
Services: jsonServices,
|
||||
Fieldsrule: jsonFieldsRule,
|
||||
Customcolor: rule.CustomColor,
|
||||
Accountid: accountID,
|
||||
})
|
||||
@ -649,9 +661,14 @@ func (r *YclientsRepository) ChangeQuizSettings(ctx context.Context, rule model.
|
||||
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,
|
||||
Services: jsonServices,
|
||||
Fieldsrule: jsonFieldsRule,
|
||||
Customcolor: rule.CustomColor,
|
||||
Accountid: accountID,
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user