update sqlcgen
This commit is contained in:
parent
9f317e2fa6
commit
b8f7fa08cb
@ -958,7 +958,7 @@ SELECT u.AmoID AS AccountID,$1 AS QuizID,$2 AS PerformerID,$3 AS PipelineID,
|
|||||||
-- name: ChangeQuizSettings :exec
|
-- name: ChangeQuizSettings :exec
|
||||||
UPDATE rules
|
UPDATE rules
|
||||||
SET PerformerID = $1,PipelineID = $2,StepID = $3,FieldsRule = $4
|
SET PerformerID = $1,PipelineID = $2,StepID = $3,FieldsRule = $4
|
||||||
WHERE AccountID = (SELECT AmoID FROM users WHERE users.AccountID = $6) AND QuizID = $7 AND Deleted = false;
|
WHERE AccountID = (SELECT AmoID FROM users WHERE users.AccountID = $5) AND QuizID = $6 AND Deleted = false;
|
||||||
|
|
||||||
-- name: GetUtmsByID :many
|
-- name: GetUtmsByID :many
|
||||||
-- SELECT ID,AmoFieldID,QuizID,AccountID,Name
|
-- SELECT ID,AmoFieldID,QuizID,AccountID,Name
|
||||||
|
@ -136,7 +136,6 @@ type Rule struct {
|
|||||||
Performerid int32 `db:"performerid" json:"performerid"`
|
Performerid int32 `db:"performerid" json:"performerid"`
|
||||||
Pipelineid int32 `db:"pipelineid" json:"pipelineid"`
|
Pipelineid int32 `db:"pipelineid" json:"pipelineid"`
|
||||||
Stepid int32 `db:"stepid" json:"stepid"`
|
Stepid int32 `db:"stepid" json:"stepid"`
|
||||||
Utms []int32 `db:"utms" json:"utms"`
|
|
||||||
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
||||||
Deleted bool `db:"deleted" json:"deleted"`
|
Deleted bool `db:"deleted" json:"deleted"`
|
||||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||||
@ -187,13 +186,3 @@ type User struct {
|
|||||||
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
||||||
Country string `db:"country" json:"country"`
|
Country string `db:"country" json:"country"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Utm struct {
|
|
||||||
ID int64 `db:"id" json:"id"`
|
|
||||||
Amofieldid int32 `db:"amofieldid" json:"amofieldid"`
|
|
||||||
Quizid int32 `db:"quizid" json:"quizid"`
|
|
||||||
Accountid int32 `db:"accountid" json:"accountid"`
|
|
||||||
Name string `db:"name" json:"name"`
|
|
||||||
Deleted bool `db:"deleted" json:"deleted"`
|
|
||||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
|
||||||
}
|
|
||||||
|
@ -116,15 +116,14 @@ func (q *Queries) ArchiveQuiz(ctx context.Context, arg ArchiveQuizParams) error
|
|||||||
|
|
||||||
const changeQuizSettings = `-- name: ChangeQuizSettings :exec
|
const changeQuizSettings = `-- name: ChangeQuizSettings :exec
|
||||||
UPDATE rules
|
UPDATE rules
|
||||||
SET PerformerID = $1,PipelineID = $2,StepID = $3,UTMS = $4,FieldsRule = $5
|
SET PerformerID = $1,PipelineID = $2,StepID = $3,FieldsRule = $4
|
||||||
WHERE AccountID = (SELECT AmoID FROM users WHERE users.AccountID = $6) AND QuizID = $7 AND Deleted = false
|
WHERE AccountID = (SELECT AmoID FROM users WHERE users.AccountID = $5) AND QuizID = $6 AND Deleted = false
|
||||||
`
|
`
|
||||||
|
|
||||||
type ChangeQuizSettingsParams struct {
|
type ChangeQuizSettingsParams struct {
|
||||||
Performerid int32 `db:"performerid" json:"performerid"`
|
Performerid int32 `db:"performerid" json:"performerid"`
|
||||||
Pipelineid int32 `db:"pipelineid" json:"pipelineid"`
|
Pipelineid int32 `db:"pipelineid" json:"pipelineid"`
|
||||||
Stepid int32 `db:"stepid" json:"stepid"`
|
Stepid int32 `db:"stepid" json:"stepid"`
|
||||||
Utms []int32 `db:"utms" json:"utms"`
|
|
||||||
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
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"`
|
||||||
@ -135,7 +134,6 @@ func (q *Queries) ChangeQuizSettings(ctx context.Context, arg ChangeQuizSettings
|
|||||||
arg.Performerid,
|
arg.Performerid,
|
||||||
arg.Pipelineid,
|
arg.Pipelineid,
|
||||||
arg.Stepid,
|
arg.Stepid,
|
||||||
pq.Array(arg.Utms),
|
|
||||||
arg.Fieldsrule,
|
arg.Fieldsrule,
|
||||||
arg.Accountid,
|
arg.Accountid,
|
||||||
arg.Quizid,
|
arg.Quizid,
|
||||||
@ -975,11 +973,47 @@ func (q *Queries) DeleteUsers(ctx context.Context, dollar_1 []int64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const deletingUTM = `-- name: DeletingUTM :exec
|
const deletingUTM = `-- name: DeletingUTM :exec
|
||||||
UPDATE utms SET Deleted = true WHERE ID = ANY($1::int[])
|
|
||||||
|
|
||||||
|
|
||||||
|
SELECT id, accountid, quizid, performerid, pipelineid, stepid, fieldsrule, deleted, createdat FROM rules WHERE QuizID = $1 AND Deleted = false
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) DeletingUTM(ctx context.Context, dollar_1 []int32) error {
|
// UPDATE utms SET Deleted = true WHERE ID = ANY($1::int[]);
|
||||||
_, err := q.db.ExecContext(ctx, deletingUTM, pq.Array(dollar_1))
|
// SELECT ut.*, COUNT(*) OVER() as total_count
|
||||||
|
// FROM utms ut JOIN (SELECT AmoID FROM users WHERE users.AccountID = $1) u ON ut.AccountID = u.AmoID
|
||||||
|
// WHERE ut.Deleted = false and ut.QuizID = $4
|
||||||
|
// ORDER BY ut.ID OFFSET ($2 - 1) * $3 LIMIT $3;
|
||||||
|
// WITH user_data AS (
|
||||||
|
//
|
||||||
|
// SELECT AmoID
|
||||||
|
// FROM users
|
||||||
|
// WHERE users.AccountID = $1
|
||||||
|
//
|
||||||
|
// ), new_UTMs AS (
|
||||||
|
//
|
||||||
|
// SELECT (utm->>'AmoFieldID')::INT AS amoFieldID,
|
||||||
|
// COALESCE(utm->>'QuizID', '')::INT AS quizID,
|
||||||
|
// COALESCE(utm->>'Name', '')::varchar(512) AS name,
|
||||||
|
// CURRENT_TIMESTAMP AS createdAt
|
||||||
|
// FROM json_array_elements($2::json) AS utm
|
||||||
|
//
|
||||||
|
// ), inserted_utms AS(
|
||||||
|
//
|
||||||
|
// INSERT INTO utms (AmoFieldID, QuizID, AccountID, Name, createdAt)
|
||||||
|
// SELECT nu.amoFieldID,
|
||||||
|
// nu.quizID,
|
||||||
|
// ud.AmoID,
|
||||||
|
// nu.name,
|
||||||
|
// nu.createdAt
|
||||||
|
// FROM new_UTMs nu
|
||||||
|
// JOIN user_data ud ON true
|
||||||
|
// RETURNING *
|
||||||
|
//
|
||||||
|
// )
|
||||||
|
// SELECT * from inserted_utms;
|
||||||
|
func (q *Queries) DeletingUTM(ctx context.Context, quizid int32) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, deletingUTM, quizid)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1925,47 +1959,6 @@ func (q *Queries) GetQuestionHistory(ctx context.Context, arg GetQuestionHistory
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const getQuestionListByIDs = `-- name: GetQuestionListByIDs :many
|
|
||||||
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at FROM question WHERE id = ANY($1::int[]) AND deleted = FALSE
|
|
||||||
`
|
|
||||||
|
|
||||||
func (q *Queries) GetQuestionListByIDs(ctx context.Context, dollar_1 []int32) ([]Question, error) {
|
|
||||||
rows, err := q.db.QueryContext(ctx, getQuestionListByIDs, pq.Array(dollar_1))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
var items []Question
|
|
||||||
for rows.Next() {
|
|
||||||
var i Question
|
|
||||||
if err := rows.Scan(
|
|
||||||
&i.ID,
|
|
||||||
&i.QuizID,
|
|
||||||
&i.Title,
|
|
||||||
&i.Description,
|
|
||||||
&i.Questiontype,
|
|
||||||
&i.Required,
|
|
||||||
&i.Deleted,
|
|
||||||
&i.Page,
|
|
||||||
&i.Content,
|
|
||||||
&i.Version,
|
|
||||||
pq.Array(&i.ParentIds),
|
|
||||||
&i.CreatedAt,
|
|
||||||
&i.UpdatedAt,
|
|
||||||
); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
items = append(items, i)
|
|
||||||
}
|
|
||||||
if err := rows.Close(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return items, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const getQuestionTitle = `-- name: GetQuestionTitle :one
|
const getQuestionTitle = `-- name: GetQuestionTitle :one
|
||||||
SELECT title, questiontype,page FROM question WHERE id = $1
|
SELECT title, questiontype,page FROM question WHERE id = $1
|
||||||
`
|
`
|
||||||
@ -2203,28 +2196,6 @@ func (q *Queries) GetQuizHistory(ctx context.Context, arg GetQuizHistoryParams)
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const getQuizRule = `-- name: GetQuizRule :one
|
|
||||||
SELECT id, accountid, quizid, performerid, pipelineid, stepid, utms, fieldsrule, deleted, createdat FROM rules WHERE QuizID = $1 AND Deleted = false
|
|
||||||
`
|
|
||||||
|
|
||||||
func (q *Queries) GetQuizRule(ctx context.Context, quizid int32) (Rule, error) {
|
|
||||||
row := q.db.QueryRowContext(ctx, getQuizRule, quizid)
|
|
||||||
var i Rule
|
|
||||||
err := row.Scan(
|
|
||||||
&i.ID,
|
|
||||||
&i.Accountid,
|
|
||||||
&i.Quizid,
|
|
||||||
&i.Performerid,
|
|
||||||
&i.Pipelineid,
|
|
||||||
&i.Stepid,
|
|
||||||
pq.Array(&i.Utms),
|
|
||||||
&i.Fieldsrule,
|
|
||||||
&i.Deleted,
|
|
||||||
&i.Createdat,
|
|
||||||
)
|
|
||||||
return i, err
|
|
||||||
}
|
|
||||||
|
|
||||||
const getResultAnswers = `-- name: GetResultAnswers :many
|
const getResultAnswers = `-- name: GetResultAnswers :many
|
||||||
SELECT DISTINCT on (question_id) id, content, quiz_id, question_id, fingerprint, session,created_at, result, new,deleted, device_type,device,os,browser,ip FROM answer WHERE session = (
|
SELECT DISTINCT on (question_id) id, content, quiz_id, question_id, fingerprint, session,created_at, result, new,deleted, device_type,device,os,browser,ip FROM answer WHERE session = (
|
||||||
SELECT session FROM answer WHERE answer.id = $1) ORDER BY question_id, created_at DESC
|
SELECT session FROM answer WHERE answer.id = $1) ORDER BY question_id, created_at DESC
|
||||||
@ -2427,115 +2398,6 @@ func (q *Queries) GetTokenById(ctx context.Context, accountid string) (Token, er
|
|||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
const getUTMsWithPagination = `-- name: GetUTMsWithPagination :many
|
|
||||||
SELECT ut.id, ut.amofieldid, ut.quizid, ut.accountid, ut.name, ut.deleted, ut.createdat, COUNT(*) OVER() as total_count
|
|
||||||
FROM utms ut JOIN (SELECT AmoID FROM users WHERE users.AccountID = $1) u ON ut.AccountID = u.AmoID
|
|
||||||
WHERE ut.Deleted = false and ut.QuizID = $4
|
|
||||||
ORDER BY ut.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
|
||||||
`
|
|
||||||
|
|
||||||
type GetUTMsWithPaginationParams struct {
|
|
||||||
Accountid string `db:"accountid" json:"accountid"`
|
|
||||||
Column2 interface{} `db:"column_2" json:"column_2"`
|
|
||||||
Limit int32 `db:"limit" json:"limit"`
|
|
||||||
Quizid int32 `db:"quizid" json:"quizid"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetUTMsWithPaginationRow struct {
|
|
||||||
ID int64 `db:"id" json:"id"`
|
|
||||||
Amofieldid int32 `db:"amofieldid" json:"amofieldid"`
|
|
||||||
Quizid int32 `db:"quizid" json:"quizid"`
|
|
||||||
Accountid int32 `db:"accountid" json:"accountid"`
|
|
||||||
Name string `db:"name" json:"name"`
|
|
||||||
Deleted bool `db:"deleted" json:"deleted"`
|
|
||||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
|
||||||
TotalCount int64 `db:"total_count" json:"total_count"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Queries) GetUTMsWithPagination(ctx context.Context, arg GetUTMsWithPaginationParams) ([]GetUTMsWithPaginationRow, error) {
|
|
||||||
rows, err := q.db.QueryContext(ctx, getUTMsWithPagination,
|
|
||||||
arg.Accountid,
|
|
||||||
arg.Column2,
|
|
||||||
arg.Limit,
|
|
||||||
arg.Quizid,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
var items []GetUTMsWithPaginationRow
|
|
||||||
for rows.Next() {
|
|
||||||
var i GetUTMsWithPaginationRow
|
|
||||||
if err := rows.Scan(
|
|
||||||
&i.ID,
|
|
||||||
&i.Amofieldid,
|
|
||||||
&i.Quizid,
|
|
||||||
&i.Accountid,
|
|
||||||
&i.Name,
|
|
||||||
&i.Deleted,
|
|
||||||
&i.Createdat,
|
|
||||||
&i.TotalCount,
|
|
||||||
); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
items = append(items, i)
|
|
||||||
}
|
|
||||||
if err := rows.Close(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return items, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const getUserFieldsByID = `-- name: GetUserFieldsByID :many
|
|
||||||
SELECT ID,AmoID,Code,AccountID,Name,Entity,Type
|
|
||||||
FROM fields
|
|
||||||
WHERE AccountID = $1 AND Deleted = false
|
|
||||||
`
|
|
||||||
|
|
||||||
type GetUserFieldsByIDRow struct {
|
|
||||||
ID int64 `db:"id" json:"id"`
|
|
||||||
Amoid int32 `db:"amoid" json:"amoid"`
|
|
||||||
Code string `db:"code" json:"code"`
|
|
||||||
Accountid int32 `db:"accountid" json:"accountid"`
|
|
||||||
Name string `db:"name" json:"name"`
|
|
||||||
Entity interface{} `db:"entity" json:"entity"`
|
|
||||||
Type interface{} `db:"type" json:"type"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Queries) GetUserFieldsByID(ctx context.Context, accountid int32) ([]GetUserFieldsByIDRow, error) {
|
|
||||||
rows, err := q.db.QueryContext(ctx, getUserFieldsByID, accountid)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
var items []GetUserFieldsByIDRow
|
|
||||||
for rows.Next() {
|
|
||||||
var i GetUserFieldsByIDRow
|
|
||||||
if err := rows.Scan(
|
|
||||||
&i.ID,
|
|
||||||
&i.Amoid,
|
|
||||||
&i.Code,
|
|
||||||
&i.Accountid,
|
|
||||||
&i.Name,
|
|
||||||
&i.Entity,
|
|
||||||
&i.Type,
|
|
||||||
); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
items = append(items, i)
|
|
||||||
}
|
|
||||||
if err := rows.Close(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return items, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const getUserPipelinesByID = `-- name: GetUserPipelinesByID :many
|
const getUserPipelinesByID = `-- name: GetUserPipelinesByID :many
|
||||||
SELECT ID,AmoID,AccountID,Name,IsArchive
|
SELECT ID,AmoID,AccountID,Name,IsArchive
|
||||||
FROM pipelines
|
FROM pipelines
|
||||||
@ -2793,35 +2655,54 @@ func (q *Queries) GetUsersWithPagination(ctx context.Context, arg GetUsersWithPa
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getUtmsByID = `-- name: GetUtmsByID :many
|
const getUtmsByID = `-- name: GetUtmsByID :many
|
||||||
SELECT ID,AmoFieldID,QuizID,AccountID,Name
|
|
||||||
FROM utms
|
|
||||||
WHERE
|
|
||||||
ID = ANY($1::int[]) AND Deleted = FALSE
|
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at FROM question WHERE id = ANY($1::int[]) AND deleted = FALSE
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetUtmsByIDRow struct {
|
// SELECT ID,AmoFieldID,QuizID,AccountID,Name
|
||||||
ID int64 `db:"id" json:"id"`
|
// FROM utms
|
||||||
Amofieldid int32 `db:"amofieldid" json:"amofieldid"`
|
// WHERE
|
||||||
Quizid int32 `db:"quizid" json:"quizid"`
|
//
|
||||||
Accountid int32 `db:"accountid" json:"accountid"`
|
// ID = ANY($1::int[]) AND Deleted = FALSE;
|
||||||
Name string `db:"name" json:"name"`
|
//
|
||||||
}
|
// -- name: GetUserFieldsByID :many
|
||||||
|
// SELECT ID,AmoID,Code,AccountID,Name,Entity,Type
|
||||||
func (q *Queries) GetUtmsByID(ctx context.Context, dollar_1 []int32) ([]GetUtmsByIDRow, error) {
|
// FROM fields
|
||||||
|
// WHERE AccountID = $1 AND Deleted = false;
|
||||||
|
// UPDATE utms AS u
|
||||||
|
// SET name = (update_data ->> 'Name')::varchar(512),
|
||||||
|
//
|
||||||
|
// AmoFieldID = (update_data ->> 'AmoFieldID')::INT
|
||||||
|
//
|
||||||
|
// FROM json_array_elements($1::json) AS update_data
|
||||||
|
// WHERE u.ID = (update_data ->> 'ID')::INT;
|
||||||
|
// UPDATE utms AS u SET AmoFieldID = f.AmoID FROM fields AS f
|
||||||
|
// WHERE u.Name = f.Name AND u.ID = ANY($1::int[]) AND u.Deleted = FALSE;
|
||||||
|
func (q *Queries) GetUtmsByID(ctx context.Context, dollar_1 []int32) ([]Question, error) {
|
||||||
rows, err := q.db.QueryContext(ctx, getUtmsByID, pq.Array(dollar_1))
|
rows, err := q.db.QueryContext(ctx, getUtmsByID, pq.Array(dollar_1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
var items []GetUtmsByIDRow
|
var items []Question
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i GetUtmsByIDRow
|
var i Question
|
||||||
if err := rows.Scan(
|
if err := rows.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Amofieldid,
|
&i.QuizID,
|
||||||
&i.Quizid,
|
&i.Title,
|
||||||
&i.Accountid,
|
&i.Description,
|
||||||
&i.Name,
|
&i.Questiontype,
|
||||||
|
&i.Required,
|
||||||
|
&i.Deleted,
|
||||||
|
&i.Page,
|
||||||
|
&i.Content,
|
||||||
|
&i.Version,
|
||||||
|
pq.Array(&i.ParentIds),
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.UpdatedAt,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -2837,7 +2718,7 @@ func (q *Queries) GetUtmsByID(ctx context.Context, dollar_1 []int32) ([]GetUtmsB
|
|||||||
}
|
}
|
||||||
|
|
||||||
const gettingAmoUsersTrueResults = `-- name: GettingAmoUsersTrueResults :many
|
const gettingAmoUsersTrueResults = `-- name: GettingAmoUsersTrueResults :many
|
||||||
SELECT a.quiz_id,a.id,a.result,a.question_id,a.content,a.session,t.accesstoken,r.accountid,r.utms,r.fieldsrule,r.performerid,r.stepid,r.pipelineid,(SELECT u.name FROM users u WHERE u.amoid = r.performerid) AS performer_name
|
SELECT a.quiz_id,a.id,a.result,a.question_id,a.content,a.session,t.accesstoken,r.accountid,a.utm,r.fieldsrule,r.performerid,r.stepid,r.pipelineid,(SELECT u.name FROM users u WHERE u.amoid = r.performerid) AS performer_name
|
||||||
FROM answer a
|
FROM answer a
|
||||||
INNER JOIN quiz q ON a.quiz_id = q.id
|
INNER JOIN quiz q ON a.quiz_id = q.id
|
||||||
LEFT JOIN amoCRMStatuses s ON a.id = s.AnswerID
|
LEFT JOIN amoCRMStatuses s ON a.id = s.AnswerID
|
||||||
@ -2860,7 +2741,7 @@ type GettingAmoUsersTrueResultsRow struct {
|
|||||||
Session sql.NullString `db:"session" json:"session"`
|
Session sql.NullString `db:"session" json:"session"`
|
||||||
Accesstoken string `db:"accesstoken" json:"accesstoken"`
|
Accesstoken string `db:"accesstoken" json:"accesstoken"`
|
||||||
Accountid int32 `db:"accountid" json:"accountid"`
|
Accountid int32 `db:"accountid" json:"accountid"`
|
||||||
Utms []int32 `db:"utms" json:"utms"`
|
Utm json.RawMessage `db:"utm" json:"utm"`
|
||||||
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
||||||
Performerid int32 `db:"performerid" json:"performerid"`
|
Performerid int32 `db:"performerid" json:"performerid"`
|
||||||
Stepid int32 `db:"stepid" json:"stepid"`
|
Stepid int32 `db:"stepid" json:"stepid"`
|
||||||
@ -2886,7 +2767,7 @@ func (q *Queries) GettingAmoUsersTrueResults(ctx context.Context) ([]GettingAmoU
|
|||||||
&i.Session,
|
&i.Session,
|
||||||
&i.Accesstoken,
|
&i.Accesstoken,
|
||||||
&i.Accountid,
|
&i.Accountid,
|
||||||
pq.Array(&i.Utms),
|
&i.Utm,
|
||||||
&i.Fieldsrule,
|
&i.Fieldsrule,
|
||||||
&i.Performerid,
|
&i.Performerid,
|
||||||
&i.Stepid,
|
&i.Stepid,
|
||||||
@ -3360,81 +3241,10 @@ func (q *Queries) QuizCopyQid(ctx context.Context, arg QuizCopyQidParams) (QuizC
|
|||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveUTMs = `-- name: SaveUTMs :many
|
|
||||||
WITH user_data AS (
|
|
||||||
SELECT AmoID
|
|
||||||
FROM users
|
|
||||||
WHERE users.AccountID = $1
|
|
||||||
), new_UTMs AS (
|
|
||||||
SELECT (utm->>'AmoFieldID')::INT AS amoFieldID,
|
|
||||||
COALESCE(utm->>'QuizID', '')::INT AS quizID,
|
|
||||||
COALESCE(utm->>'Name', '')::varchar(512) AS name,
|
|
||||||
CURRENT_TIMESTAMP AS createdAt
|
|
||||||
FROM json_array_elements($2::json) AS utm
|
|
||||||
), inserted_utms AS(
|
|
||||||
INSERT INTO utms (AmoFieldID, QuizID, AccountID, Name, createdAt)
|
|
||||||
SELECT nu.amoFieldID,
|
|
||||||
nu.quizID,
|
|
||||||
ud.AmoID,
|
|
||||||
nu.name,
|
|
||||||
nu.createdAt
|
|
||||||
FROM new_UTMs nu
|
|
||||||
JOIN user_data ud ON true
|
|
||||||
RETURNING id, amofieldid, quizid, accountid, name, deleted, createdat
|
|
||||||
)
|
|
||||||
SELECT id, amofieldid, quizid, accountid, name, deleted, createdat from inserted_utms
|
|
||||||
`
|
|
||||||
|
|
||||||
type SaveUTMsParams struct {
|
|
||||||
Accountid string `db:"accountid" json:"accountid"`
|
|
||||||
Column2 json.RawMessage `db:"column_2" json:"column_2"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SaveUTMsRow struct {
|
|
||||||
ID int64 `db:"id" json:"id"`
|
|
||||||
Amofieldid int32 `db:"amofieldid" json:"amofieldid"`
|
|
||||||
Quizid int32 `db:"quizid" json:"quizid"`
|
|
||||||
Accountid int32 `db:"accountid" json:"accountid"`
|
|
||||||
Name string `db:"name" json:"name"`
|
|
||||||
Deleted bool `db:"deleted" json:"deleted"`
|
|
||||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Queries) SaveUTMs(ctx context.Context, arg SaveUTMsParams) ([]SaveUTMsRow, error) {
|
|
||||||
rows, err := q.db.QueryContext(ctx, saveUTMs, arg.Accountid, arg.Column2)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
var items []SaveUTMsRow
|
|
||||||
for rows.Next() {
|
|
||||||
var i SaveUTMsRow
|
|
||||||
if err := rows.Scan(
|
|
||||||
&i.ID,
|
|
||||||
&i.Amofieldid,
|
|
||||||
&i.Quizid,
|
|
||||||
&i.Accountid,
|
|
||||||
&i.Name,
|
|
||||||
&i.Deleted,
|
|
||||||
&i.Createdat,
|
|
||||||
); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
items = append(items, i)
|
|
||||||
}
|
|
||||||
if err := rows.Close(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return items, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const setQuizSettings = `-- name: SetQuizSettings :exec
|
const setQuizSettings = `-- name: SetQuizSettings :exec
|
||||||
INSERT INTO rules (AccountID, QuizID, PerformerID, PipelineID, StepID, UTMS, FieldsRule)
|
INSERT INTO rules (AccountID, QuizID, PerformerID, PipelineID, StepID, FieldsRule)
|
||||||
SELECT u.AmoID AS AccountID,$1 AS QuizID,$2 AS PerformerID,$3 AS PipelineID,
|
SELECT u.AmoID AS AccountID,$1 AS QuizID,$2 AS PerformerID,$3 AS PipelineID,
|
||||||
$4 AS StepID,$5 AS UTMS,$6 AS FieldsRule FROM users u WHERE u.AccountID = $7
|
$4 AS StepID,$5 AS FieldsRule FROM users u WHERE u.AccountID = $6
|
||||||
`
|
`
|
||||||
|
|
||||||
type SetQuizSettingsParams struct {
|
type SetQuizSettingsParams struct {
|
||||||
@ -3442,7 +3252,6 @@ type SetQuizSettingsParams struct {
|
|||||||
Performerid int32 `db:"performerid" json:"performerid"`
|
Performerid int32 `db:"performerid" json:"performerid"`
|
||||||
Pipelineid int32 `db:"pipelineid" json:"pipelineid"`
|
Pipelineid int32 `db:"pipelineid" json:"pipelineid"`
|
||||||
Stepid int32 `db:"stepid" json:"stepid"`
|
Stepid int32 `db:"stepid" json:"stepid"`
|
||||||
Utms []int32 `db:"utms" json:"utms"`
|
|
||||||
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
||||||
Accountid string `db:"accountid" json:"accountid"`
|
Accountid string `db:"accountid" json:"accountid"`
|
||||||
}
|
}
|
||||||
@ -3453,7 +3262,6 @@ func (q *Queries) SetQuizSettings(ctx context.Context, arg SetQuizSettingsParams
|
|||||||
arg.Performerid,
|
arg.Performerid,
|
||||||
arg.Pipelineid,
|
arg.Pipelineid,
|
||||||
arg.Stepid,
|
arg.Stepid,
|
||||||
pq.Array(arg.Utms),
|
|
||||||
arg.Fieldsrule,
|
arg.Fieldsrule,
|
||||||
arg.Accountid,
|
arg.Accountid,
|
||||||
)
|
)
|
||||||
@ -3661,29 +3469,6 @@ func (q *Queries) UpdateUsers(ctx context.Context, dollar_1 json.RawMessage) err
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateUtms = `-- name: UpdateUtms :exec
|
|
||||||
UPDATE utms AS u
|
|
||||||
SET name = (update_data ->> 'Name')::varchar(512),
|
|
||||||
AmoFieldID = (update_data ->> 'AmoFieldID')::INT
|
|
||||||
FROM json_array_elements($1::json) AS update_data
|
|
||||||
WHERE u.ID = (update_data ->> 'ID')::INT
|
|
||||||
`
|
|
||||||
|
|
||||||
func (q *Queries) UpdateUtms(ctx context.Context, dollar_1 json.RawMessage) error {
|
|
||||||
_, err := q.db.ExecContext(ctx, updateUtms, dollar_1)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateUtmsFields = `-- name: UpdateUtmsFields :exec
|
|
||||||
UPDATE utms AS u SET AmoFieldID = f.AmoID FROM fields AS f
|
|
||||||
WHERE u.Name = f.Name AND u.ID = ANY($1::int[]) AND u.Deleted = FALSE
|
|
||||||
`
|
|
||||||
|
|
||||||
func (q *Queries) UpdateUtmsFields(ctx context.Context, dollar_1 []int32) error {
|
|
||||||
_, err := q.db.ExecContext(ctx, updateUtmsFields, pq.Array(dollar_1))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatingDealAmoStatus = `-- name: UpdatingDealAmoStatus :exec
|
const updatingDealAmoStatus = `-- name: UpdatingDealAmoStatus :exec
|
||||||
UPDATE amoCRMStatuses SET Status = $1
|
UPDATE amoCRMStatuses SET Status = $1
|
||||||
WHERE DealID = $2 AND AccountID = (SELECT u.AmoID FROM tokens AS t JOIN users AS u ON t.AccountID = u.AccountID WHERE t.AccessToken = $3)
|
WHERE DealID = $2 AND AccountID = (SELECT u.AmoID FROM tokens AS t JOIN users AS u ON t.AccountID = u.AccountID WHERE t.AccessToken = $3)
|
||||||
|
Loading…
Reference in New Issue
Block a user