2024-02-19 16:33:15 +00:00
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
|
|
// versions:
|
2024-06-03 08:33:19 +00:00
|
|
|
// sqlc v1.26.0
|
2024-02-19 16:33:15 +00:00
|
|
|
// source: queries.sql
|
|
|
|
|
|
|
|
package sqlcgen
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql"
|
2024-04-18 10:16:03 +00:00
|
|
|
"encoding/json"
|
2024-03-16 19:56:08 +00:00
|
|
|
"time"
|
2024-02-19 16:33:15 +00:00
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/lib/pq"
|
|
|
|
)
|
|
|
|
|
|
|
|
const accountPagination = `-- name: AccountPagination :many
|
|
|
|
SELECT a.id, a.user_id, a.created_at, a.deleted
|
|
|
|
FROM account a ORDER BY a.created_at DESC LIMIT $1 OFFSET $2
|
|
|
|
`
|
|
|
|
|
|
|
|
type AccountPaginationParams struct {
|
|
|
|
Limit int32 `db:"limit" json:"limit"`
|
|
|
|
Offset int32 `db:"offset" json:"offset"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type AccountPaginationRow struct {
|
|
|
|
ID uuid.UUID `db:"id" json:"id"`
|
|
|
|
UserID sql.NullString `db:"user_id" json:"user_id"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
|
|
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) AccountPagination(ctx context.Context, arg AccountPaginationParams) ([]AccountPaginationRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, accountPagination, arg.Limit, arg.Offset)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []AccountPaginationRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i AccountPaginationRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.UserID,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.Deleted,
|
|
|
|
); 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
|
|
|
|
}
|
|
|
|
|
2024-03-25 08:34:07 +00:00
|
|
|
const allServiceStatistics = `-- name: AllServiceStatistics :one
|
|
|
|
WITH Registrations AS (
|
|
|
|
SELECT COUNT(*) AS registration_count
|
|
|
|
FROM account
|
|
|
|
WHERE created_at >= to_timestamp($1) AND created_at <= to_timestamp($2)
|
|
|
|
),
|
|
|
|
Quizes AS (
|
|
|
|
SELECT COUNT(*) AS quiz_count
|
|
|
|
FROM quiz
|
|
|
|
WHERE deleted = false AND created_at >= to_timestamp($1) AND created_at <= to_timestamp($2)
|
|
|
|
),
|
|
|
|
Results AS (
|
|
|
|
SELECT COUNT(*) AS result_count
|
|
|
|
FROM answer
|
|
|
|
WHERE result = true AND created_at >= to_timestamp($1) AND created_at <= to_timestamp($2)
|
|
|
|
)
|
|
|
|
SELECT
|
|
|
|
(SELECT registration_count FROM Registrations) AS registrations,
|
|
|
|
(SELECT quiz_count FROM Quizes) AS quizes,
|
|
|
|
(SELECT result_count FROM Results) AS results
|
|
|
|
`
|
|
|
|
|
|
|
|
type AllServiceStatisticsParams struct {
|
|
|
|
ToTimestamp float64 `db:"to_timestamp" json:"to_timestamp"`
|
|
|
|
ToTimestamp_2 float64 `db:"to_timestamp_2" json:"to_timestamp_2"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type AllServiceStatisticsRow struct {
|
|
|
|
Registrations int64 `db:"registrations" json:"registrations"`
|
|
|
|
Quizes int64 `db:"quizes" json:"quizes"`
|
|
|
|
Results int64 `db:"results" json:"results"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) AllServiceStatistics(ctx context.Context, arg AllServiceStatisticsParams) (AllServiceStatisticsRow, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, allServiceStatistics, arg.ToTimestamp, arg.ToTimestamp_2)
|
|
|
|
var i AllServiceStatisticsRow
|
|
|
|
err := row.Scan(&i.Registrations, &i.Quizes, &i.Results)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:33:15 +00:00
|
|
|
const archiveQuiz = `-- name: ArchiveQuiz :exec
|
|
|
|
UPDATE quiz SET archived = true WHERE id=$1 AND accountId=$2
|
|
|
|
`
|
|
|
|
|
|
|
|
type ArchiveQuizParams struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) ArchiveQuiz(ctx context.Context, arg ArchiveQuizParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, archiveQuiz, arg.ID, arg.Accountid)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-06-04 15:53:06 +00:00
|
|
|
const changeQuizSettings = `-- name: ChangeQuizSettings :one
|
2024-04-23 11:48:15 +00:00
|
|
|
UPDATE rules
|
2024-05-17 18:46:36 +00:00
|
|
|
SET PerformerID = $1,PipelineID = $2,StepID = $3,FieldsRule = $4
|
2024-06-04 15:32:14 +00:00
|
|
|
WHERE AccountID = (SELECT AmoID FROM users WHERE users.AccountID = $5 AND users.Deleted = false) AND QuizID = $6 AND Deleted = false
|
2024-06-04 15:53:06 +00:00
|
|
|
RETURNING id
|
2024-04-23 11:48:15 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type ChangeQuizSettingsParams struct {
|
|
|
|
Performerid int32 `db:"performerid" json:"performerid"`
|
|
|
|
Pipelineid int32 `db:"pipelineid" json:"pipelineid"`
|
|
|
|
Stepid int32 `db:"stepid" json:"stepid"`
|
|
|
|
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
Quizid int32 `db:"quizid" json:"quizid"`
|
|
|
|
}
|
|
|
|
|
2024-06-04 15:53:06 +00:00
|
|
|
func (q *Queries) ChangeQuizSettings(ctx context.Context, arg ChangeQuizSettingsParams) (int64, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, changeQuizSettings,
|
2024-04-23 11:48:15 +00:00
|
|
|
arg.Performerid,
|
|
|
|
arg.Pipelineid,
|
|
|
|
arg.Stepid,
|
|
|
|
arg.Fieldsrule,
|
|
|
|
arg.Accountid,
|
|
|
|
arg.Quizid,
|
|
|
|
)
|
2024-06-04 15:53:06 +00:00
|
|
|
var id int64
|
|
|
|
err := row.Scan(&id)
|
|
|
|
return id, err
|
2024-04-23 11:48:15 +00:00
|
|
|
}
|
|
|
|
|
2024-02-19 16:33:15 +00:00
|
|
|
const checkAndAddDefault = `-- name: CheckAndAddDefault :exec
|
|
|
|
UPDATE privileges
|
|
|
|
SET amount = $1, created_at = NOW()
|
|
|
|
WHERE privilege_name = $2
|
|
|
|
AND (amount < $3 OR created_at <= NOW() - INTERVAL '1 month')
|
|
|
|
`
|
|
|
|
|
|
|
|
type CheckAndAddDefaultParams struct {
|
|
|
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
|
|
|
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
|
|
|
Amount_2 sql.NullInt32 `db:"amount_2" json:"amount_2"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CheckAndAddDefault(ctx context.Context, arg CheckAndAddDefaultParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, checkAndAddDefault, arg.Amount, arg.PrivilegeName, arg.Amount_2)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-04-17 17:18:52 +00:00
|
|
|
const checkExpired = `-- name: CheckExpired :many
|
2024-04-18 10:16:03 +00:00
|
|
|
SELECT accountid, refreshtoken, accesstoken, authcode, expiration, createdat FROM tokens WHERE Expiration <= TO_TIMESTAMP(EXTRACT(EPOCH FROM NOW()) + (10 * 60))
|
2024-04-17 17:18:52 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) CheckExpired(ctx context.Context) ([]Token, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, checkExpired)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []Token
|
|
|
|
for rows.Next() {
|
|
|
|
var i Token
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Refreshtoken,
|
|
|
|
&i.Accesstoken,
|
|
|
|
&i.Authcode,
|
|
|
|
&i.Expiration,
|
|
|
|
&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
|
|
|
|
}
|
|
|
|
|
2024-04-19 08:02:20 +00:00
|
|
|
const checkFields = `-- name: CheckFields :many
|
|
|
|
WITH user_data AS (
|
2024-04-22 14:45:39 +00:00
|
|
|
SELECT AmoID
|
2024-04-19 08:02:20 +00:00
|
|
|
FROM users
|
|
|
|
WHERE users.AccountID = $1
|
|
|
|
), new_fields AS (
|
2024-04-19 08:31:54 +00:00
|
|
|
SELECT (field->>'AmoID')::INT AS amoID,
|
|
|
|
COALESCE(field->>'Code', '')::varchar(255) AS code,
|
2024-05-03 07:09:06 +00:00
|
|
|
COALESCE(field->>'Name', '')::varchar(512) AS name,
|
2024-04-19 08:31:54 +00:00
|
|
|
CAST(field->>'Entity' AS entitytype) AS Entity,
|
2024-04-28 13:06:06 +00:00
|
|
|
COALESCE(field->>'Type', '')::fieldtype AS type,
|
2024-04-19 08:31:54 +00:00
|
|
|
CURRENT_TIMESTAMP AS createdAt
|
2024-04-19 08:02:20 +00:00
|
|
|
FROM json_array_elements($2::json) AS field
|
|
|
|
), inserted_fields AS(
|
|
|
|
INSERT INTO fields (amoID, code, accountID, name, Entity, type, createdAt)
|
|
|
|
SELECT nf.amoID,
|
|
|
|
nf.code,
|
|
|
|
ud.AmoID,
|
|
|
|
nf.name,
|
|
|
|
nf.Entity,
|
|
|
|
nf.type,
|
2024-04-19 08:31:54 +00:00
|
|
|
nf.createdAt
|
2024-04-19 08:02:20 +00:00
|
|
|
FROM new_fields nf
|
|
|
|
JOIN user_data ud ON true
|
|
|
|
ON CONFLICT (amoID, accountID, entity) DO NOTHING
|
|
|
|
RETURNING id, amoid, code, accountid, name, entity, type, deleted, createdat
|
|
|
|
)
|
2024-04-22 14:45:39 +00:00
|
|
|
SELECT nf.amoid, nf.code, nf.name, nf.entity, nf.type, nf.createdat,ud.AmoID
|
2024-04-22 14:25:42 +00:00
|
|
|
FROM new_fields nf
|
2024-04-22 14:43:11 +00:00
|
|
|
JOIN user_data ud ON true
|
2024-04-22 14:25:42 +00:00
|
|
|
WHERE NOT EXISTS (
|
2024-04-22 14:45:39 +00:00
|
|
|
SELECT id, ins.amoid, code, accountid, name, entity, type, deleted, createdat, ud.amoid
|
2024-04-22 14:25:42 +00:00
|
|
|
FROM inserted_fields ins
|
|
|
|
JOIN user_data ud ON true
|
|
|
|
WHERE ins.amoID = nf.amoID AND ins.accountID = ud.amoid AND ins.Entity = nf.Entity
|
|
|
|
)
|
2024-04-19 08:02:20 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type CheckFieldsParams struct {
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
Column2 json.RawMessage `db:"column_2" json:"column_2"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type CheckFieldsRow struct {
|
2024-04-22 14:25:42 +00:00
|
|
|
Amoid int32 `db:"amoid" json:"amoid"`
|
|
|
|
Code string `db:"code" json:"code"`
|
|
|
|
Name string `db:"name" json:"name"`
|
|
|
|
Entity interface{} `db:"entity" json:"entity"`
|
2024-04-28 13:06:06 +00:00
|
|
|
Type interface{} `db:"type" json:"type"`
|
2024-04-22 14:25:42 +00:00
|
|
|
Createdat interface{} `db:"createdat" json:"createdat"`
|
2024-04-22 14:45:39 +00:00
|
|
|
Amoid_2 int32 `db:"amoid_2" json:"amoid_2"`
|
2024-04-19 08:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CheckFields(ctx context.Context, arg CheckFieldsParams) ([]CheckFieldsRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, checkFields, arg.Accountid, arg.Column2)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []CheckFieldsRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i CheckFieldsRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.Amoid,
|
|
|
|
&i.Code,
|
|
|
|
&i.Name,
|
|
|
|
&i.Entity,
|
|
|
|
&i.Type,
|
|
|
|
&i.Createdat,
|
2024-04-22 14:45:39 +00:00
|
|
|
&i.Amoid_2,
|
2024-04-19 08:02:20 +00:00
|
|
|
); 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
|
|
|
|
}
|
|
|
|
|
2024-04-20 09:01:25 +00:00
|
|
|
const checkMainUser = `-- name: CheckMainUser :exec
|
|
|
|
UPDATE users SET Name = $1, "Group" = $2, Email = $3, Role = $4 WHERE AmoID = $5
|
|
|
|
`
|
|
|
|
|
|
|
|
type CheckMainUserParams struct {
|
|
|
|
Name string `db:"name" json:"name"`
|
|
|
|
Group int32 `db:"Group" json:"Group"`
|
|
|
|
Email string `db:"email" json:"email"`
|
|
|
|
Role int32 `db:"role" json:"role"`
|
|
|
|
Amoid int32 `db:"amoid" json:"amoid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CheckMainUser(ctx context.Context, arg CheckMainUserParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, checkMainUser,
|
|
|
|
arg.Name,
|
|
|
|
arg.Group,
|
|
|
|
arg.Email,
|
|
|
|
arg.Role,
|
|
|
|
arg.Amoid,
|
|
|
|
)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-04-19 08:02:20 +00:00
|
|
|
const checkPipelines = `-- name: CheckPipelines :many
|
|
|
|
WITH new_pipelines AS (
|
2024-04-19 08:31:54 +00:00
|
|
|
SELECT (pipeline->>'AmoID')::INT AS amoID,
|
|
|
|
(pipeline->>'AccountID')::INT AS accountID,
|
2024-05-03 07:09:06 +00:00
|
|
|
COALESCE(pipeline->>'Name', '')::varchar(512) AS name,
|
2024-04-19 08:31:54 +00:00
|
|
|
CASE WHEN (pipeline->>'IsArchive') = 'true' THEN TRUE ELSE FALSE END AS isArchive,
|
|
|
|
CURRENT_TIMESTAMP AS createdAt
|
2024-04-19 08:02:20 +00:00
|
|
|
FROM json_array_elements($1::json) AS pipeline
|
|
|
|
), inserted_pipelines AS(
|
|
|
|
INSERT INTO pipelines (amoID, accountID, name, isArchive, createdAt)
|
|
|
|
SELECT np.amoID,
|
|
|
|
np.accountID,
|
|
|
|
np.name,
|
|
|
|
np.isArchive,
|
2024-04-19 08:31:54 +00:00
|
|
|
np.createdAt
|
2024-04-19 08:02:20 +00:00
|
|
|
FROM new_pipelines np
|
|
|
|
ON CONFLICT (amoID, accountID) DO NOTHING
|
|
|
|
RETURNING id, amoid, accountid, name, isarchive, deleted, createdat
|
|
|
|
)
|
2024-04-22 14:25:42 +00:00
|
|
|
SELECT np.amoid, np.accountid, np.name, np.isarchive, np.createdat
|
|
|
|
FROM new_pipelines np
|
|
|
|
WHERE NOT EXISTS (
|
|
|
|
SELECT id, amoid, accountid, name, isarchive, deleted, createdat
|
|
|
|
FROM inserted_pipelines ins
|
|
|
|
WHERE ins.amoID = np.amoID AND ins.accountID = np.accountID
|
|
|
|
)
|
2024-04-19 08:02:20 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type CheckPipelinesRow struct {
|
2024-04-22 14:25:42 +00:00
|
|
|
Amoid int32 `db:"amoid" json:"amoid"`
|
|
|
|
Accountid int32 `db:"accountid" json:"accountid"`
|
|
|
|
Name string `db:"name" json:"name"`
|
|
|
|
Isarchive bool `db:"isarchive" json:"isarchive"`
|
|
|
|
Createdat interface{} `db:"createdat" json:"createdat"`
|
2024-04-19 08:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CheckPipelines(ctx context.Context, dollar_1 json.RawMessage) ([]CheckPipelinesRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, checkPipelines, dollar_1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []CheckPipelinesRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i CheckPipelinesRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.Amoid,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Name,
|
|
|
|
&i.Isarchive,
|
|
|
|
&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
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:33:15 +00:00
|
|
|
const checkResultOwner = `-- name: CheckResultOwner :one
|
2024-03-15 11:32:26 +00:00
|
|
|
SELECT q.accountid FROM answer a JOIN quiz q ON a.quiz_id = q.id WHERE a.id = $1 AND a.deleted = FALSE AND a.start = false
|
2024-02-19 16:33:15 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) CheckResultOwner(ctx context.Context, id int64) (string, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, checkResultOwner, id)
|
|
|
|
var accountid string
|
|
|
|
err := row.Scan(&accountid)
|
|
|
|
return accountid, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const checkResultsOwner = `-- name: CheckResultsOwner :many
|
|
|
|
SELECT a.id
|
|
|
|
FROM answer a
|
|
|
|
JOIN quiz q ON a.quiz_id = q.id
|
2024-03-15 11:32:26 +00:00
|
|
|
WHERE a.id = ANY($1::bigint[]) AND a.deleted = FALSE AND q.accountid = $2 AND a.start = false
|
2024-02-19 16:33:15 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type CheckResultsOwnerParams struct {
|
|
|
|
Column1 []int64 `db:"column_1" json:"column_1"`
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CheckResultsOwner(ctx context.Context, arg CheckResultsOwnerParams) ([]int64, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, checkResultsOwner, pq.Array(arg.Column1), arg.Accountid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []int64
|
|
|
|
for rows.Next() {
|
|
|
|
var id int64
|
|
|
|
if err := rows.Scan(&id); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
items = append(items, id)
|
|
|
|
}
|
|
|
|
if err := rows.Close(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
|
|
|
|
2024-04-19 08:02:20 +00:00
|
|
|
const checkSteps = `-- name: CheckSteps :many
|
|
|
|
WITH new_steps AS (
|
2024-04-19 08:31:54 +00:00
|
|
|
SELECT (step->>'AmoID')::INT AS amoID,
|
|
|
|
(step->>'PipelineID')::INT AS pipelineID,
|
|
|
|
(step->>'AccountID')::INT AS accountID,
|
2024-05-03 07:09:06 +00:00
|
|
|
COALESCE(step->>'Name', '')::varchar(512) AS name,
|
2024-04-19 08:31:54 +00:00
|
|
|
COALESCE(step->>'Color', '')::varchar(50) AS color,
|
|
|
|
CURRENT_TIMESTAMP AS createdAt
|
2024-04-19 08:02:20 +00:00
|
|
|
FROM json_array_elements($1::json) AS step
|
|
|
|
), inserted_steps AS (
|
|
|
|
INSERT INTO steps (amoID, pipelineID, accountID, name, color, createdAt)
|
|
|
|
SELECT ns.amoID,
|
|
|
|
ns.pipelineID,
|
|
|
|
ns.accountID,
|
|
|
|
ns.name,
|
|
|
|
ns.color,
|
2024-04-19 08:31:54 +00:00
|
|
|
ns.createdAt
|
2024-04-19 08:02:20 +00:00
|
|
|
FROM new_steps ns
|
|
|
|
ON CONFLICT (amoID, accountID, PipelineID) DO NOTHING
|
|
|
|
RETURNING id, amoid, pipelineid, accountid, name, color, deleted, createdat
|
|
|
|
)
|
2024-04-22 14:25:42 +00:00
|
|
|
SELECT ns.amoid, ns.pipelineid, ns.accountid, ns.name, ns.color, ns.createdat
|
|
|
|
FROM new_steps ns
|
|
|
|
WHERE NOT EXISTS (
|
|
|
|
SELECT id, amoid, pipelineid, accountid, name, color, deleted, createdat
|
|
|
|
FROM inserted_steps ins
|
|
|
|
WHERE ins.amoID = ns.amoID AND ins.accountID = ns.accountID AND ins.pipelineID = ns.pipelineID
|
|
|
|
)
|
2024-04-19 08:02:20 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type CheckStepsRow struct {
|
2024-04-22 14:25:42 +00:00
|
|
|
Amoid int32 `db:"amoid" json:"amoid"`
|
|
|
|
Pipelineid int32 `db:"pipelineid" json:"pipelineid"`
|
|
|
|
Accountid int32 `db:"accountid" json:"accountid"`
|
|
|
|
Name string `db:"name" json:"name"`
|
|
|
|
Color string `db:"color" json:"color"`
|
|
|
|
Createdat interface{} `db:"createdat" json:"createdat"`
|
2024-04-19 08:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CheckSteps(ctx context.Context, dollar_1 json.RawMessage) ([]CheckStepsRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, checkSteps, dollar_1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []CheckStepsRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i CheckStepsRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.Amoid,
|
|
|
|
&i.Pipelineid,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Name,
|
|
|
|
&i.Color,
|
|
|
|
&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
|
|
|
|
}
|
|
|
|
|
2024-04-18 10:16:03 +00:00
|
|
|
const checkTags = `-- name: CheckTags :many
|
|
|
|
WITH user_data AS (
|
2024-04-22 14:45:39 +00:00
|
|
|
SELECT AmoID
|
2024-04-18 10:16:03 +00:00
|
|
|
FROM users
|
|
|
|
WHERE users.AccountID = $1
|
2024-04-18 20:05:49 +00:00
|
|
|
), new_tags AS (
|
|
|
|
SELECT (tag->>'AmoID')::INT AS amoID,
|
|
|
|
(tag->>'Entity')::entitytype AS Entity,
|
2024-05-03 07:09:06 +00:00
|
|
|
COALESCE(tag->>'Name', '')::VARCHAR(512) AS name,
|
2024-04-18 20:05:49 +00:00
|
|
|
COALESCE(tag->>'Color', '')::VARCHAR(50) AS color
|
|
|
|
FROM json_array_elements($2::json) AS tag
|
|
|
|
), inserted_tags AS (
|
|
|
|
INSERT INTO tags (amoID, accountID, Entity, name, color, createdAt)
|
|
|
|
SELECT nt.amoID,
|
|
|
|
ud.AmoID,
|
|
|
|
nt.Entity,
|
|
|
|
nt.name,
|
|
|
|
nt.color,
|
|
|
|
CURRENT_TIMESTAMP
|
|
|
|
FROM new_tags nt
|
|
|
|
JOIN user_data ud ON true
|
|
|
|
ON CONFLICT (amoID, accountID, Entity) DO NOTHING
|
|
|
|
RETURNING id, amoid, accountid, entity, name, color, deleted, createdat
|
2024-04-18 10:16:03 +00:00
|
|
|
)
|
2024-04-22 14:45:39 +00:00
|
|
|
SELECT nt.amoid, nt.entity, nt.name, nt.color,ud.AmoID
|
2024-04-22 14:25:42 +00:00
|
|
|
FROM new_tags nt
|
2024-04-22 14:43:11 +00:00
|
|
|
JOIN user_data ud ON true
|
2024-04-22 14:25:42 +00:00
|
|
|
WHERE NOT EXISTS (
|
2024-04-22 14:45:39 +00:00
|
|
|
SELECT id, ins.amoid, accountid, entity, name, color, deleted, createdat, ud.amoid
|
2024-04-22 14:25:42 +00:00
|
|
|
FROM inserted_tags ins
|
|
|
|
JOIN user_data ud ON true
|
|
|
|
WHERE ins.amoID = nt.amoID AND ins.accountID = ud.amoid AND ins.Entity = nt.Entity
|
|
|
|
)
|
2024-04-18 10:16:03 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type CheckTagsParams struct {
|
2024-04-18 13:50:25 +00:00
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
Column2 json.RawMessage `db:"column_2" json:"column_2"`
|
2024-04-18 10:16:03 +00:00
|
|
|
}
|
|
|
|
|
2024-04-18 20:05:49 +00:00
|
|
|
type CheckTagsRow struct {
|
2024-04-22 14:45:39 +00:00
|
|
|
Amoid int32 `db:"amoid" json:"amoid"`
|
|
|
|
Entity interface{} `db:"entity" json:"entity"`
|
|
|
|
Name string `db:"name" json:"name"`
|
|
|
|
Color string `db:"color" json:"color"`
|
|
|
|
Amoid_2 int32 `db:"amoid_2" json:"amoid_2"`
|
2024-04-18 20:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CheckTags(ctx context.Context, arg CheckTagsParams) ([]CheckTagsRow, error) {
|
2024-04-18 13:50:25 +00:00
|
|
|
rows, err := q.db.QueryContext(ctx, checkTags, arg.Accountid, arg.Column2)
|
2024-04-18 10:16:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
2024-04-18 20:05:49 +00:00
|
|
|
var items []CheckTagsRow
|
2024-04-18 10:16:03 +00:00
|
|
|
for rows.Next() {
|
2024-04-18 20:05:49 +00:00
|
|
|
var i CheckTagsRow
|
2024-04-18 10:16:03 +00:00
|
|
|
if err := rows.Scan(
|
|
|
|
&i.Amoid,
|
|
|
|
&i.Entity,
|
|
|
|
&i.Name,
|
|
|
|
&i.Color,
|
2024-04-22 14:45:39 +00:00
|
|
|
&i.Amoid_2,
|
2024-04-18 10:16:03 +00:00
|
|
|
); 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
|
|
|
|
}
|
|
|
|
|
2024-05-03 15:00:30 +00:00
|
|
|
const checkUsers = `-- name: CheckUsers :many
|
|
|
|
WITH new_users AS (
|
|
|
|
SELECT (u->>'AmocrmID')::INT AS AmoID,
|
|
|
|
(u->>'Name')::VARCHAR(512) AS Name,
|
|
|
|
(u->>'Group')::INT AS "Group",
|
|
|
|
(u->>'Role')::INT AS Role,
|
|
|
|
(u->>'Email')::VARCHAR(50) AS Email,
|
|
|
|
(u->>'AmoUserID')::INT AS AmoUserID,
|
|
|
|
CURRENT_TIMESTAMP AS createdAt
|
|
|
|
FROM json_array_elements($1::json) AS u
|
|
|
|
), inserted_users AS (
|
|
|
|
INSERT INTO users (AmoID, Name, "Group", Role, Email, AmoUserID,createdAt)
|
|
|
|
SELECT nu.AmoID,
|
|
|
|
nu.Name,
|
|
|
|
nu."Group",
|
|
|
|
nu.Role,
|
|
|
|
nu.Email,
|
|
|
|
nu.AmoUserID,
|
|
|
|
nu.createdAt
|
|
|
|
FROM new_users nu
|
|
|
|
ON CONFLICT (amoID) DO NOTHING
|
|
|
|
RETURNING id, accountid, amoid, name, email, role, "Group", deleted, createdat, subdomain, amouserid, country
|
|
|
|
)
|
|
|
|
SELECT nu.amoid, nu.name, nu."Group", nu.role, nu.email, nu.amouserid, nu.createdat
|
|
|
|
FROM new_users nu
|
|
|
|
WHERE NOT EXISTS (
|
|
|
|
SELECT id, accountid, amoid, name, email, role, "Group", deleted, createdat, subdomain, amouserid, country
|
|
|
|
FROM inserted_users ins
|
|
|
|
WHERE ins.amoID = nu.amoID
|
|
|
|
)
|
2024-04-17 17:18:52 +00:00
|
|
|
`
|
|
|
|
|
2024-05-03 15:00:30 +00:00
|
|
|
type CheckUsersRow struct {
|
|
|
|
Amoid int32 `db:"amoid" json:"amoid"`
|
|
|
|
Name string `db:"name" json:"name"`
|
|
|
|
Group int32 `db:"Group" json:"Group"`
|
|
|
|
Role int32 `db:"role" json:"role"`
|
|
|
|
Email string `db:"email" json:"email"`
|
|
|
|
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
|
|
|
Createdat interface{} `db:"createdat" json:"createdat"`
|
2024-04-17 17:18:52 +00:00
|
|
|
}
|
|
|
|
|
2024-05-03 15:00:30 +00:00
|
|
|
func (q *Queries) CheckUsers(ctx context.Context, dollar_1 json.RawMessage) ([]CheckUsersRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, checkUsers, dollar_1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []CheckUsersRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i CheckUsersRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.Amoid,
|
|
|
|
&i.Name,
|
|
|
|
&i.Group,
|
|
|
|
&i.Role,
|
|
|
|
&i.Email,
|
|
|
|
&i.Amouserid,
|
|
|
|
&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
|
2024-04-17 17:18:52 +00:00
|
|
|
}
|
|
|
|
|
2024-02-19 16:33:15 +00:00
|
|
|
const copyQuestion = `-- name: CopyQuestion :one
|
|
|
|
INSERT INTO question(
|
|
|
|
quiz_id, title, description, questiontype, required,
|
|
|
|
page, content, version, parent_ids
|
|
|
|
)
|
|
|
|
SELECT $1, title, description, questiontype, required,
|
|
|
|
page, content, version, parent_ids
|
|
|
|
FROM question WHERE question.id=$2
|
|
|
|
RETURNING question.id, quiz_id, created_at, updated_at
|
|
|
|
`
|
|
|
|
|
|
|
|
type CopyQuestionParams struct {
|
|
|
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type CopyQuestionRow struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
|
|
|
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CopyQuestion(ctx context.Context, arg CopyQuestionParams) (CopyQuestionRow, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, copyQuestion, arg.QuizID, arg.ID)
|
|
|
|
var i CopyQuestionRow
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.QuizID,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.UpdatedAt,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
2024-03-19 16:13:03 +00:00
|
|
|
const copyQuestionQuizID = `-- name: CopyQuestionQuizID :exec
|
|
|
|
INSERT INTO question (
|
|
|
|
quiz_id, title, description, questiontype, required,
|
|
|
|
page, content, version, parent_ids, created_at, updated_at
|
|
|
|
)
|
|
|
|
SELECT
|
|
|
|
$2, title, description, questiontype, required,
|
|
|
|
page, content, version, parent_ids, created_at, updated_at
|
|
|
|
FROM
|
|
|
|
question
|
|
|
|
WHERE
|
|
|
|
question.quiz_id = $1 AND deleted = false
|
|
|
|
`
|
|
|
|
|
|
|
|
type CopyQuestionQuizIDParams struct {
|
|
|
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
|
|
|
QuizID_2 int64 `db:"quiz_id_2" json:"quiz_id_2"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CopyQuestionQuizID(ctx context.Context, arg CopyQuestionQuizIDParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, copyQuestionQuizID, arg.QuizID, arg.QuizID_2)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:33:15 +00:00
|
|
|
const copyQuiz = `-- name: CopyQuiz :one
|
|
|
|
INSERT INTO quiz(
|
|
|
|
accountid, archived,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,name,description,config,
|
2024-05-07 16:22:48 +00:00
|
|
|
status,limit_answers,due_to,time_of_passing,pausable,version,version_comment,parent_ids,questions_count, super, group_id
|
2024-02-19 16:33:15 +00:00
|
|
|
)
|
|
|
|
SELECT accountid, archived,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,name,description,config,
|
2024-05-07 16:22:48 +00:00
|
|
|
status,limit_answers,due_to,time_of_passing,pausable,version,version_comment,parent_ids,questions_count, super, group_id
|
2024-02-19 16:33:15 +00:00
|
|
|
FROM quiz WHERE quiz.id=$1 AND quiz.accountId=$2
|
|
|
|
RETURNING id, qid,created_at, updated_at
|
|
|
|
`
|
|
|
|
|
|
|
|
type CopyQuizParams struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type CopyQuizRow struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Qid uuid.NullUUID `db:"qid" json:"qid"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
|
|
|
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CopyQuiz(ctx context.Context, arg CopyQuizParams) (CopyQuizRow, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, copyQuiz, arg.ID, arg.Accountid)
|
|
|
|
var i CopyQuizRow
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Qid,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.UpdatedAt,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const copyQuizQuestions = `-- name: CopyQuizQuestions :exec
|
|
|
|
INSERT INTO question(
|
|
|
|
quiz_id, title, description, questiontype, required, page, content, version, parent_ids
|
|
|
|
)
|
|
|
|
SELECT $2, title, description, questiontype, required, page, content, version, parent_ids
|
|
|
|
FROM question WHERE question.quiz_id=$1 AND deleted=false
|
|
|
|
`
|
|
|
|
|
|
|
|
type CopyQuizQuestionsParams struct {
|
|
|
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
|
|
|
QuizID_2 int64 `db:"quiz_id_2" json:"quiz_id_2"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CopyQuizQuestions(ctx context.Context, arg CopyQuizQuestionsParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, copyQuizQuestions, arg.QuizID, arg.QuizID_2)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-06-02 08:38:41 +00:00
|
|
|
const createAccount = `-- name: CreateAccount :one
|
|
|
|
INSERT INTO account (id, user_id, email, created_at, deleted) VALUES ($1, $2, $3, $4, $5) RETURNING id, user_id, email, created_at, deleted
|
2024-02-19 16:33:15 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type CreateAccountParams struct {
|
|
|
|
ID uuid.UUID `db:"id" json:"id"`
|
|
|
|
UserID sql.NullString `db:"user_id" json:"user_id"`
|
|
|
|
Email sql.NullString `db:"email" json:"email"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
|
|
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
|
|
|
}
|
|
|
|
|
2024-06-02 08:38:41 +00:00
|
|
|
func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (Account, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, createAccount,
|
2024-02-19 16:33:15 +00:00
|
|
|
arg.ID,
|
|
|
|
arg.UserID,
|
|
|
|
arg.Email,
|
|
|
|
arg.CreatedAt,
|
|
|
|
arg.Deleted,
|
|
|
|
)
|
2024-06-02 08:38:41 +00:00
|
|
|
var i Account
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.UserID,
|
|
|
|
&i.Email,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.Deleted,
|
|
|
|
)
|
|
|
|
return i, err
|
2024-02-19 16:33:15 +00:00
|
|
|
}
|
|
|
|
|
2024-04-17 17:18:52 +00:00
|
|
|
const createAmoAccount = `-- name: CreateAmoAccount :exec
|
|
|
|
|
|
|
|
INSERT INTO users (AccountID, AmoID, Name, Email, Role, "Group", Deleted, CreatedAt, Subdomain, AmoUserID, Country)
|
|
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
|
|
|
`
|
|
|
|
|
|
|
|
type CreateAmoAccountParams struct {
|
2024-04-20 09:01:25 +00:00
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
Amoid int32 `db:"amoid" json:"amoid"`
|
|
|
|
Name string `db:"name" json:"name"`
|
|
|
|
Email string `db:"email" json:"email"`
|
|
|
|
Role int32 `db:"role" json:"role"`
|
|
|
|
Group int32 `db:"Group" json:"Group"`
|
|
|
|
Deleted bool `db:"deleted" json:"deleted"`
|
|
|
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
|
|
|
Subdomain string `db:"subdomain" json:"subdomain"`
|
|
|
|
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
|
|
|
Country string `db:"country" json:"country"`
|
2024-04-17 17:18:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// amo methods:
|
|
|
|
func (q *Queries) CreateAmoAccount(ctx context.Context, arg CreateAmoAccountParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, createAmoAccount,
|
|
|
|
arg.Accountid,
|
|
|
|
arg.Amoid,
|
|
|
|
arg.Name,
|
|
|
|
arg.Email,
|
|
|
|
arg.Role,
|
|
|
|
arg.Group,
|
|
|
|
arg.Deleted,
|
|
|
|
arg.Createdat,
|
|
|
|
arg.Subdomain,
|
|
|
|
arg.Amouserid,
|
|
|
|
arg.Country,
|
|
|
|
)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const createWebHook = `-- name: CreateWebHook :exec
|
|
|
|
INSERT INTO tokens (AccountID, RefreshToken, AccessToken, AuthCode, Expiration, CreatedAt)
|
|
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
|
|
`
|
|
|
|
|
|
|
|
type CreateWebHookParams struct {
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
Refreshtoken string `db:"refreshtoken" json:"refreshtoken"`
|
|
|
|
Accesstoken string `db:"accesstoken" json:"accesstoken"`
|
|
|
|
Authcode string `db:"authcode" json:"authcode"`
|
|
|
|
Expiration time.Time `db:"expiration" json:"expiration"`
|
|
|
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CreateWebHook(ctx context.Context, arg CreateWebHookParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, createWebHook,
|
|
|
|
arg.Accountid,
|
|
|
|
arg.Refreshtoken,
|
|
|
|
arg.Accesstoken,
|
|
|
|
arg.Authcode,
|
|
|
|
arg.Expiration,
|
|
|
|
arg.Createdat,
|
|
|
|
)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-06-03 13:49:05 +00:00
|
|
|
const decrementManual = `-- name: DecrementManual :one
|
|
|
|
UPDATE privileges p SET amount = amount - 1 FROM account a
|
|
|
|
WHERE p.account_id = a.id AND a.user_id = $1 AND p.privilegeID = $2 AND p.amount > 0
|
|
|
|
RETURNING p.id, p.privilegeID, p.account_id, p.privilege_name, p.amount, p.created_at
|
|
|
|
`
|
|
|
|
|
|
|
|
type DecrementManualParams struct {
|
|
|
|
UserID sql.NullString `db:"user_id" json:"user_id"`
|
|
|
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) DecrementManual(ctx context.Context, arg DecrementManualParams) (Privilege, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, decrementManual, arg.UserID, arg.Privilegeid)
|
|
|
|
var i Privilege
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Privilegeid,
|
|
|
|
&i.AccountID,
|
|
|
|
&i.PrivilegeName,
|
|
|
|
&i.Amount,
|
|
|
|
&i.CreatedAt,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:33:15 +00:00
|
|
|
const deleteAccountById = `-- name: DeleteAccountById :exec
|
|
|
|
DELETE FROM account WHERE id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) DeleteAccountById(ctx context.Context, id uuid.UUID) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, deleteAccountById, id)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-05-07 17:20:07 +00:00
|
|
|
const deleteFields = `-- name: DeleteFields :exec
|
2024-05-07 17:26:13 +00:00
|
|
|
UPDATE fields SET Deleted = true WHERE ID = ANY($1::bigint[])
|
2024-05-07 17:20:07 +00:00
|
|
|
`
|
|
|
|
|
2024-05-07 17:26:13 +00:00
|
|
|
func (q *Queries) DeleteFields(ctx context.Context, dollar_1 []int64) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, deleteFields, pq.Array(dollar_1))
|
2024-05-07 17:20:07 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const deletePipelines = `-- name: DeletePipelines :exec
|
2024-05-07 17:26:13 +00:00
|
|
|
UPDATE pipelines SET Deleted = true WHERE ID = ANY($1::bigint[])
|
2024-05-07 17:20:07 +00:00
|
|
|
`
|
|
|
|
|
2024-05-07 17:26:13 +00:00
|
|
|
func (q *Queries) DeletePipelines(ctx context.Context, dollar_1 []int64) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, deletePipelines, pq.Array(dollar_1))
|
2024-05-07 17:20:07 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:33:15 +00:00
|
|
|
const deletePrivilegeByAccID = `-- name: DeletePrivilegeByAccID :exec
|
|
|
|
DELETE FROM privileges WHERE account_id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) DeletePrivilegeByAccID(ctx context.Context, accountID uuid.NullUUID) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, deletePrivilegeByAccID, accountID)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const deletePrivilegeByID = `-- name: DeletePrivilegeByID :exec
|
|
|
|
DELETE FROM privileges WHERE id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) DeletePrivilegeByID(ctx context.Context, id int32) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, deletePrivilegeByID, id)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const deleteQuestion = `-- name: DeleteQuestion :one
|
|
|
|
UPDATE question SET deleted=true WHERE id=$1 RETURNING question.id, question.quiz_id, question.title, question.description, question.questiontype, question.required, question.deleted, question.page, question.content, question.version, question.parent_ids, question.created_at, question.updated_at
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) DeleteQuestion(ctx context.Context, id int64) (Question, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, deleteQuestion, id)
|
|
|
|
var i Question
|
|
|
|
err := row.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,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const deleteQuizByID = `-- name: DeleteQuizByID :one
|
|
|
|
UPDATE quiz SET deleted=true WHERE quiz.id=$1 AND accountid=$2 RETURNING quiz.id, quiz.qid, quiz.accountid, quiz.deleted, quiz.archived, quiz.fingerprinting, quiz.repeatable, quiz.note_prevented, quiz.mail_notifications, quiz.unique_answers, quiz.super, quiz.group_id, quiz.name, quiz.description, quiz.config, quiz.status, quiz.limit_answers, quiz.due_to, quiz.time_of_passing, quiz.pausable, quiz.version, quiz.version_comment, quiz.parent_ids, quiz.created_at, quiz.updated_at, quiz.questions_count, quiz.answers_count, quiz.average_time_passing, quiz.sessions_count
|
|
|
|
`
|
|
|
|
|
|
|
|
type DeleteQuizByIDParams struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) DeleteQuizByID(ctx context.Context, arg DeleteQuizByIDParams) (Quiz, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, deleteQuizByID, arg.ID, arg.Accountid)
|
|
|
|
var i Quiz
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Qid,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Deleted,
|
|
|
|
&i.Archived,
|
|
|
|
&i.Fingerprinting,
|
|
|
|
&i.Repeatable,
|
|
|
|
&i.NotePrevented,
|
|
|
|
&i.MailNotifications,
|
|
|
|
&i.UniqueAnswers,
|
|
|
|
&i.Super,
|
|
|
|
&i.GroupID,
|
|
|
|
&i.Name,
|
|
|
|
&i.Description,
|
|
|
|
&i.Config,
|
|
|
|
&i.Status,
|
|
|
|
&i.LimitAnswers,
|
|
|
|
&i.DueTo,
|
|
|
|
&i.TimeOfPassing,
|
|
|
|
&i.Pausable,
|
|
|
|
&i.Version,
|
|
|
|
&i.VersionComment,
|
|
|
|
pq.Array(&i.ParentIds),
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.UpdatedAt,
|
|
|
|
&i.QuestionsCount,
|
|
|
|
&i.AnswersCount,
|
|
|
|
&i.AverageTimePassing,
|
|
|
|
&i.SessionsCount,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
2024-05-07 17:20:07 +00:00
|
|
|
const deleteSteps = `-- name: DeleteSteps :exec
|
2024-05-07 17:26:13 +00:00
|
|
|
UPDATE steps SET Deleted = true WHERE ID = ANY($1::bigint[])
|
2024-05-07 17:20:07 +00:00
|
|
|
`
|
|
|
|
|
2024-05-07 17:26:13 +00:00
|
|
|
func (q *Queries) DeleteSteps(ctx context.Context, dollar_1 []int64) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, deleteSteps, pq.Array(dollar_1))
|
2024-05-07 17:20:07 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const deleteTags = `-- name: DeleteTags :exec
|
2024-05-07 17:26:13 +00:00
|
|
|
UPDATE tags SET Deleted = true WHERE ID = ANY($1::bigint[])
|
2024-05-07 17:20:07 +00:00
|
|
|
`
|
|
|
|
|
2024-05-07 17:26:13 +00:00
|
|
|
func (q *Queries) DeleteTags(ctx context.Context, dollar_1 []int64) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, deleteTags, pq.Array(dollar_1))
|
2024-05-07 17:20:07 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const deleteUsers = `-- name: DeleteUsers :exec
|
2024-05-07 17:26:13 +00:00
|
|
|
UPDATE users SET Deleted = true WHERE ID = ANY($1::bigint[])
|
2024-05-07 17:20:07 +00:00
|
|
|
`
|
|
|
|
|
2024-05-07 17:26:13 +00:00
|
|
|
func (q *Queries) DeleteUsers(ctx context.Context, dollar_1 []int64) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, deleteUsers, pq.Array(dollar_1))
|
2024-05-07 17:20:07 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-03-15 13:11:42 +00:00
|
|
|
const deviceStatistics = `-- name: DeviceStatistics :many
|
|
|
|
WITH DeviceStats AS (
|
|
|
|
SELECT
|
|
|
|
device_type,
|
|
|
|
COUNT(*) AS device_count
|
|
|
|
FROM
|
|
|
|
answer
|
|
|
|
WHERE
|
|
|
|
answer.quiz_id = $1
|
|
|
|
AND created_at >= to_timestamp($2)
|
|
|
|
AND created_at <= to_timestamp($3)
|
|
|
|
AND result = TRUE
|
|
|
|
GROUP BY
|
|
|
|
device_type
|
|
|
|
),
|
|
|
|
OSStats AS (
|
|
|
|
SELECT
|
|
|
|
os,
|
|
|
|
COUNT(*) AS os_count
|
|
|
|
FROM
|
|
|
|
answer
|
|
|
|
WHERE
|
|
|
|
answer.quiz_id = $1
|
|
|
|
AND created_at >= to_timestamp($2)
|
|
|
|
AND created_at <= to_timestamp($3)
|
|
|
|
AND result = TRUE
|
|
|
|
GROUP BY
|
|
|
|
os
|
|
|
|
),
|
|
|
|
BrowserStats AS (
|
|
|
|
SELECT
|
|
|
|
browser,
|
|
|
|
COUNT(*) AS browser_count
|
|
|
|
FROM
|
|
|
|
answer
|
|
|
|
WHERE
|
|
|
|
answer.quiz_id = $1
|
|
|
|
AND created_at >= to_timestamp($2)
|
|
|
|
AND created_at <= to_timestamp($3)
|
|
|
|
AND result = TRUE
|
|
|
|
GROUP BY
|
|
|
|
browser
|
|
|
|
),
|
|
|
|
TotalStats AS (
|
|
|
|
SELECT
|
|
|
|
COUNT(*) AS total_count
|
|
|
|
FROM
|
|
|
|
answer
|
|
|
|
WHERE
|
|
|
|
answer.quiz_id = $1
|
|
|
|
AND created_at >= to_timestamp($2)
|
|
|
|
AND created_at <= to_timestamp($3)
|
|
|
|
AND result = TRUE
|
|
|
|
)
|
|
|
|
SELECT
|
|
|
|
DeviceStats.device_type,
|
2024-03-17 20:20:55 +00:00
|
|
|
CAST((DeviceStats.device_count::FLOAT / TotalStats.total_count) * 100.0 AS FLOAT8) AS device_percentage,
|
2024-03-15 13:11:42 +00:00
|
|
|
OSStats.os,
|
2024-03-17 20:20:55 +00:00
|
|
|
CAST((OSStats.os_count::FLOAT / TotalStats.total_count) * 100.0 AS FLOAT8) AS os_percentage,
|
2024-03-15 13:11:42 +00:00
|
|
|
BrowserStats.browser,
|
2024-03-17 20:20:55 +00:00
|
|
|
CAST((BrowserStats.browser_count::FLOAT / TotalStats.total_count) * 100.0 AS FLOAT8) AS browser_percentage
|
2024-03-15 13:11:42 +00:00
|
|
|
FROM
|
2024-03-16 19:46:28 +00:00
|
|
|
DeviceStats,
|
|
|
|
OSStats,
|
|
|
|
BrowserStats,
|
|
|
|
TotalStats
|
2024-03-15 13:11:42 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type DeviceStatisticsParams struct {
|
|
|
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
|
|
|
ToTimestamp float64 `db:"to_timestamp" json:"to_timestamp"`
|
|
|
|
ToTimestamp_2 float64 `db:"to_timestamp_2" json:"to_timestamp_2"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type DeviceStatisticsRow struct {
|
2024-03-17 20:20:55 +00:00
|
|
|
DeviceType string `db:"device_type" json:"device_type"`
|
|
|
|
DevicePercentage float64 `db:"device_percentage" json:"device_percentage"`
|
|
|
|
Os string `db:"os" json:"os"`
|
|
|
|
OsPercentage float64 `db:"os_percentage" json:"os_percentage"`
|
|
|
|
Browser string `db:"browser" json:"browser"`
|
|
|
|
BrowserPercentage float64 `db:"browser_percentage" json:"browser_percentage"`
|
2024-03-15 13:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) DeviceStatistics(ctx context.Context, arg DeviceStatisticsParams) ([]DeviceStatisticsRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, deviceStatistics, arg.QuizID, arg.ToTimestamp, arg.ToTimestamp_2)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []DeviceStatisticsRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i DeviceStatisticsRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.DeviceType,
|
|
|
|
&i.DevicePercentage,
|
|
|
|
&i.Os,
|
|
|
|
&i.OsPercentage,
|
|
|
|
&i.Browser,
|
|
|
|
&i.BrowserPercentage,
|
|
|
|
); 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
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:33:15 +00:00
|
|
|
const duplicateQuestion = `-- name: DuplicateQuestion :one
|
|
|
|
INSERT INTO question(
|
|
|
|
quiz_id, title, description, questiontype, required,
|
|
|
|
page, content, version, parent_ids
|
|
|
|
)
|
|
|
|
SELECT quiz_id, title, description, questiontype, required,
|
|
|
|
page, content, version, parent_ids
|
|
|
|
FROM question WHERE question.id=$1
|
|
|
|
RETURNING question.id, quiz_id, created_at, updated_at
|
|
|
|
`
|
|
|
|
|
|
|
|
type DuplicateQuestionRow struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
|
|
|
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) DuplicateQuestion(ctx context.Context, id int64) (DuplicateQuestionRow, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, duplicateQuestion, id)
|
|
|
|
var i DuplicateQuestionRow
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.QuizID,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.UpdatedAt,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
2024-03-15 17:02:01 +00:00
|
|
|
const generalStatistics = `-- name: GeneralStatistics :many
|
|
|
|
WITH TimeBucket AS (
|
|
|
|
SELECT
|
2024-04-07 00:15:31 +00:00
|
|
|
date_trunc('hour', timestamp_bucket)::TIMESTAMP AS time_interval_start,
|
|
|
|
COALESCE(LEAD(
|
|
|
|
date_trunc('hour', timestamp_bucket)::TIMESTAMP
|
|
|
|
) OVER (ORDER BY timestamp_bucket), NOW()) AS time_interval_end
|
2024-03-15 17:02:01 +00:00
|
|
|
FROM
|
2024-04-07 00:15:31 +00:00
|
|
|
generate_series(TO_TIMESTAMP($1), TO_TIMESTAMP($2), CASE
|
|
|
|
WHEN EXTRACT(epoch FROM TO_TIMESTAMP($2)) - EXTRACT(epoch FROM TO_TIMESTAMP($1)) > 172800 THEN '1 day'::interval
|
|
|
|
ELSE '1 hour'::interval
|
|
|
|
END) AS timestamp_bucket
|
2024-03-15 17:02:01 +00:00
|
|
|
),
|
|
|
|
OpenStats AS (
|
|
|
|
SELECT
|
2024-03-18 10:01:58 +00:00
|
|
|
tb.time_interval_start,
|
|
|
|
tb.time_interval_end,
|
2024-03-15 17:02:01 +00:00
|
|
|
COUNT(DISTINCT session) AS open_count
|
2024-03-18 10:01:58 +00:00
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
session,
|
|
|
|
MIN(created_at) AS first_start_time
|
|
|
|
FROM
|
|
|
|
answer
|
|
|
|
WHERE
|
|
|
|
answer.quiz_id = $3
|
|
|
|
AND start = TRUE
|
2024-04-07 00:15:31 +00:00
|
|
|
AND created_at >= TO_TIMESTAMP($1)
|
|
|
|
AND created_at <= TO_TIMESTAMP($2)
|
2024-03-18 10:01:58 +00:00
|
|
|
GROUP BY
|
|
|
|
session
|
|
|
|
) AS first_starts
|
|
|
|
JOIN TimeBucket tb ON date_trunc('hour', first_starts.first_start_time) >= tb.time_interval_start
|
|
|
|
AND date_trunc('hour', first_starts.first_start_time) < tb.time_interval_end
|
2024-03-15 17:02:01 +00:00
|
|
|
GROUP BY
|
2024-03-18 10:01:58 +00:00
|
|
|
tb.time_interval_start, tb.time_interval_end
|
2024-03-15 17:02:01 +00:00
|
|
|
),
|
|
|
|
ResultStats AS (
|
|
|
|
SELECT
|
2024-03-18 10:01:58 +00:00
|
|
|
tb.time_interval_start,
|
|
|
|
tb.time_interval_end,
|
2024-03-18 11:13:31 +00:00
|
|
|
COUNT(DISTINCT session) AS true_result_count
|
2024-03-15 17:02:01 +00:00
|
|
|
FROM
|
2024-03-18 11:13:31 +00:00
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
session,
|
|
|
|
MIN(created_at) AS first_result_time
|
|
|
|
FROM
|
|
|
|
answer
|
|
|
|
WHERE
|
|
|
|
answer.quiz_id = $3
|
|
|
|
AND result = TRUE
|
2024-04-07 00:15:31 +00:00
|
|
|
AND created_at >= TO_TIMESTAMP($1)
|
|
|
|
AND created_at <= TO_TIMESTAMP($2)
|
2024-03-18 11:13:31 +00:00
|
|
|
GROUP BY
|
|
|
|
session
|
|
|
|
) AS first_results
|
|
|
|
JOIN TimeBucket tb ON date_trunc('hour', first_results.first_result_time) >= tb.time_interval_start
|
|
|
|
AND date_trunc('hour', first_results.first_result_time) < tb.time_interval_end
|
2024-03-15 17:02:01 +00:00
|
|
|
GROUP BY
|
2024-03-18 10:01:58 +00:00
|
|
|
tb.time_interval_start, tb.time_interval_end
|
2024-03-15 17:02:01 +00:00
|
|
|
),
|
|
|
|
AvTimeStats AS (
|
|
|
|
SELECT
|
2024-03-18 10:01:58 +00:00
|
|
|
tb.time_interval_start,
|
|
|
|
tb.time_interval_end,
|
2024-04-07 00:15:31 +00:00
|
|
|
AVG(EXTRACT(epoch FROM (a.created_at)) - EXTRACT(epoch FROM (b.created_at))) AS avg_time
|
2024-03-15 17:02:01 +00:00
|
|
|
FROM
|
|
|
|
answer a
|
2024-03-18 10:01:58 +00:00
|
|
|
JOIN answer b ON a.session = b.session
|
|
|
|
JOIN TimeBucket tb ON date_trunc('hour', a.created_at) >= tb.time_interval_start
|
|
|
|
AND date_trunc('hour', a.created_at) < tb.time_interval_end
|
2024-03-15 17:02:01 +00:00
|
|
|
WHERE
|
|
|
|
a.quiz_id = $3
|
|
|
|
AND a.result = TRUE
|
|
|
|
AND b.start = TRUE
|
2024-03-18 10:01:58 +00:00
|
|
|
AND b.quiz_id = $3
|
2024-04-07 00:15:31 +00:00
|
|
|
AND a.created_at >= TO_TIMESTAMP($1)
|
|
|
|
AND a.created_at <= TO_TIMESTAMP($2)
|
|
|
|
AND b.created_at >= TO_TIMESTAMP($1)
|
|
|
|
AND b.created_at <= TO_TIMESTAMP($2)
|
2024-03-15 17:02:01 +00:00
|
|
|
GROUP BY
|
2024-03-18 10:01:58 +00:00
|
|
|
tb.time_interval_start, tb.time_interval_end
|
2024-03-15 17:02:01 +00:00
|
|
|
)
|
|
|
|
SELECT
|
2024-03-18 10:01:58 +00:00
|
|
|
tb.time_interval_start AS time_bucket,
|
2024-03-15 17:02:01 +00:00
|
|
|
COALESCE(os.open_count, 0) AS open_count,
|
2024-03-18 10:01:58 +00:00
|
|
|
COALESCE(rs.true_result_count, 0) AS true_result_count,
|
2024-03-15 17:02:01 +00:00
|
|
|
CASE
|
2024-04-07 00:15:31 +00:00
|
|
|
WHEN COALESCE(os.open_count, 0) > 0 THEN COALESCE(rs.true_result_count, 0)::float / COALESCE(os.open_count, 0)::float
|
2024-03-15 17:02:01 +00:00
|
|
|
ELSE 0
|
2024-04-07 00:15:31 +00:00
|
|
|
END::float AS conversion,
|
2024-03-18 10:01:58 +00:00
|
|
|
COALESCE(at.avg_time, 0) AS avg_time
|
2024-03-15 17:02:01 +00:00
|
|
|
FROM
|
|
|
|
TimeBucket tb
|
|
|
|
LEFT JOIN
|
2024-03-18 10:01:58 +00:00
|
|
|
OpenStats os ON tb.time_interval_start = os.time_interval_start
|
|
|
|
AND tb.time_interval_end = os.time_interval_end
|
2024-03-15 17:02:01 +00:00
|
|
|
LEFT JOIN
|
2024-03-18 10:01:58 +00:00
|
|
|
ResultStats rs ON tb.time_interval_start = rs.time_interval_start
|
|
|
|
AND tb.time_interval_end = rs.time_interval_end
|
2024-03-15 17:02:01 +00:00
|
|
|
LEFT JOIN
|
2024-03-18 10:01:58 +00:00
|
|
|
AvTimeStats at ON tb.time_interval_start = at.time_interval_start
|
|
|
|
AND tb.time_interval_end = at.time_interval_end
|
2024-03-15 17:02:01 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type GeneralStatisticsParams struct {
|
2024-04-07 00:15:31 +00:00
|
|
|
ToTimestamp float64 `db:"to_timestamp" json:"to_timestamp"`
|
|
|
|
ToTimestamp_2 float64 `db:"to_timestamp_2" json:"to_timestamp_2"`
|
|
|
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
2024-03-15 17:02:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type GeneralStatisticsRow struct {
|
2024-03-18 10:01:58 +00:00
|
|
|
TimeBucket time.Time `db:"time_bucket" json:"time_bucket"`
|
|
|
|
OpenCount int64 `db:"open_count" json:"open_count"`
|
|
|
|
TrueResultCount int64 `db:"true_result_count" json:"true_result_count"`
|
2024-04-07 00:15:31 +00:00
|
|
|
Conversion float64 `db:"conversion" json:"conversion"`
|
2024-03-18 10:01:58 +00:00
|
|
|
AvgTime float64 `db:"avg_time" json:"avg_time"`
|
2024-03-15 17:02:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GeneralStatistics(ctx context.Context, arg GeneralStatisticsParams) ([]GeneralStatisticsRow, error) {
|
2024-04-07 00:15:31 +00:00
|
|
|
rows, err := q.db.QueryContext(ctx, generalStatistics, arg.ToTimestamp, arg.ToTimestamp_2, arg.QuizID)
|
2024-03-15 17:02:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GeneralStatisticsRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GeneralStatisticsRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.TimeBucket,
|
|
|
|
&i.OpenCount,
|
2024-03-18 10:01:58 +00:00
|
|
|
&i.TrueResultCount,
|
2024-03-15 17:02:01 +00:00
|
|
|
&i.Conversion,
|
2024-03-18 10:01:58 +00:00
|
|
|
&i.AvgTime,
|
2024-03-15 17:02:01 +00:00
|
|
|
); 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
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:33:15 +00:00
|
|
|
const getAccAndPrivilegeByEmail = `-- name: GetAccAndPrivilegeByEmail :one
|
|
|
|
SELECT
|
|
|
|
a.id,
|
|
|
|
a.user_id,
|
|
|
|
a.email,
|
|
|
|
a.created_at,
|
2024-03-13 16:21:37 +00:00
|
|
|
COALESCE(p.ID,0),
|
|
|
|
coalesce(p.privilegeid,''),
|
|
|
|
coalesce(p.amount,0),
|
|
|
|
coalesce(p.created_at,Now())
|
2024-02-19 16:33:15 +00:00
|
|
|
FROM
|
|
|
|
account AS a
|
|
|
|
LEFT JOIN privileges AS p ON a.id = p.account_id
|
|
|
|
WHERE
|
|
|
|
a.user_id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetAccAndPrivilegeByEmailRow struct {
|
|
|
|
ID uuid.UUID `db:"id" json:"id"`
|
|
|
|
UserID sql.NullString `db:"user_id" json:"user_id"`
|
|
|
|
Email sql.NullString `db:"email" json:"email"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
2024-03-13 16:21:37 +00:00
|
|
|
ID_2 int32 `db:"id_2" json:"id_2"`
|
|
|
|
Privilegeid string `db:"privilegeid" json:"privilegeid"`
|
|
|
|
Amount int32 `db:"amount" json:"amount"`
|
2024-02-19 16:33:15 +00:00
|
|
|
CreatedAt_2 sql.NullTime `db:"created_at_2" json:"created_at_2"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetAccAndPrivilegeByEmail(ctx context.Context, userID sql.NullString) (GetAccAndPrivilegeByEmailRow, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, getAccAndPrivilegeByEmail, userID)
|
|
|
|
var i GetAccAndPrivilegeByEmailRow
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.UserID,
|
|
|
|
&i.Email,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.ID_2,
|
|
|
|
&i.Privilegeid,
|
|
|
|
&i.Amount,
|
|
|
|
&i.CreatedAt_2,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const getAccountWithPrivileges = `-- name: GetAccountWithPrivileges :many
|
|
|
|
SELECT a.id, a.user_id, a.created_at, a.deleted,
|
2024-03-13 16:21:37 +00:00
|
|
|
coalesce(p.id,0) AS privilege_id,
|
|
|
|
coalesce(p.privilegeID,''),
|
|
|
|
coalesce(p.privilege_name,''),
|
|
|
|
coalesce(p.amount,0), coalesce(p.created_at,Now()) AS privilege_created_at
|
2024-02-19 16:33:15 +00:00
|
|
|
FROM account a
|
|
|
|
LEFT JOIN privileges AS p ON a.id = p.account_id
|
|
|
|
WHERE a.user_id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetAccountWithPrivilegesRow struct {
|
|
|
|
ID uuid.UUID `db:"id" json:"id"`
|
|
|
|
UserID sql.NullString `db:"user_id" json:"user_id"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
|
|
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
2024-03-13 16:21:37 +00:00
|
|
|
PrivilegeID int32 `db:"privilege_id" json:"privilege_id"`
|
|
|
|
Privilegeid string `db:"privilegeid" json:"privilegeid"`
|
|
|
|
PrivilegeName string `db:"privilege_name" json:"privilege_name"`
|
|
|
|
Amount int32 `db:"amount" json:"amount"`
|
2024-02-19 16:33:15 +00:00
|
|
|
PrivilegeCreatedAt sql.NullTime `db:"privilege_created_at" json:"privilege_created_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetAccountWithPrivileges(ctx context.Context, userID sql.NullString) ([]GetAccountWithPrivilegesRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getAccountWithPrivileges, userID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetAccountWithPrivilegesRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetAccountWithPrivilegesRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.UserID,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.Deleted,
|
|
|
|
&i.PrivilegeID,
|
|
|
|
&i.Privilegeid,
|
|
|
|
&i.PrivilegeName,
|
|
|
|
&i.Amount,
|
|
|
|
&i.PrivilegeCreatedAt,
|
|
|
|
); 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 getAllAnswersByQuizID = `-- name: GetAllAnswersByQuizID :many
|
2024-03-28 10:37:43 +00:00
|
|
|
SELECT DISTINCT ON (a.question_id)
|
2024-04-11 16:26:02 +00:00
|
|
|
a.content, a.created_at, a.question_id, a.id, q.questiontype::Text as questiontype, quiz.qid
|
2024-03-28 10:37:43 +00:00
|
|
|
FROM
|
|
|
|
answer a
|
|
|
|
JOIN
|
|
|
|
question q ON a.question_id = q.id
|
|
|
|
JOIN
|
|
|
|
quiz ON q.quiz_id = quiz.id
|
|
|
|
WHERE
|
|
|
|
a.session = $1 AND a.start = false AND a.deleted = false
|
|
|
|
ORDER BY
|
|
|
|
a.question_id ASC, a.created_at DESC
|
2024-02-19 16:33:15 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type GetAllAnswersByQuizIDRow struct {
|
2024-03-28 10:37:43 +00:00
|
|
|
Content sql.NullString `db:"content" json:"content"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
|
|
|
QuestionID int64 `db:"question_id" json:"question_id"`
|
|
|
|
ID int64 `db:"id" json:"id"`
|
2024-04-11 16:26:02 +00:00
|
|
|
Questiontype string `db:"questiontype" json:"questiontype"`
|
2024-03-28 10:37:43 +00:00
|
|
|
Qid uuid.NullUUID `db:"qid" json:"qid"`
|
2024-02-19 16:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetAllAnswersByQuizID(ctx context.Context, session sql.NullString) ([]GetAllAnswersByQuizIDRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getAllAnswersByQuizID, session)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetAllAnswersByQuizIDRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetAllAnswersByQuizIDRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.Content,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.QuestionID,
|
|
|
|
&i.ID,
|
2024-03-28 10:37:43 +00:00
|
|
|
&i.Questiontype,
|
|
|
|
&i.Qid,
|
2024-02-19 16:33:15 +00:00
|
|
|
); 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
|
|
|
|
}
|
|
|
|
|
2024-04-17 17:18:52 +00:00
|
|
|
const getAllTokens = `-- name: GetAllTokens :many
|
|
|
|
SELECT accountid, refreshtoken, accesstoken, authcode, expiration, createdat FROM tokens
|
2024-02-19 16:33:15 +00:00
|
|
|
`
|
|
|
|
|
2024-04-17 17:18:52 +00:00
|
|
|
func (q *Queries) GetAllTokens(ctx context.Context) ([]Token, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getAllTokens)
|
2024-02-19 16:33:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
2024-04-17 17:18:52 +00:00
|
|
|
var items []Token
|
2024-02-19 16:33:15 +00:00
|
|
|
for rows.Next() {
|
2024-04-17 17:18:52 +00:00
|
|
|
var i Token
|
2024-02-19 16:33:15 +00:00
|
|
|
if err := rows.Scan(
|
2024-04-17 17:18:52 +00:00
|
|
|
&i.Accountid,
|
|
|
|
&i.Refreshtoken,
|
|
|
|
&i.Accesstoken,
|
|
|
|
&i.Authcode,
|
|
|
|
&i.Expiration,
|
|
|
|
&i.Createdat,
|
2024-02-19 16:33:15 +00:00
|
|
|
); 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
|
|
|
|
}
|
|
|
|
|
2024-04-17 18:10:42 +00:00
|
|
|
const getCurrentAccount = `-- name: GetCurrentAccount :one
|
2024-06-04 13:55:20 +00:00
|
|
|
SELECT id, accountid, amoid, name, email, role, "Group", deleted, createdat, subdomain, amouserid, country FROM users WHERE AccountID = $1 AND Deleted = false
|
2024-04-17 17:18:52 +00:00
|
|
|
`
|
|
|
|
|
2024-04-17 18:10:42 +00:00
|
|
|
func (q *Queries) GetCurrentAccount(ctx context.Context, accountid string) (User, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, getCurrentAccount, accountid)
|
|
|
|
var i User
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Amoid,
|
|
|
|
&i.Name,
|
|
|
|
&i.Email,
|
|
|
|
&i.Role,
|
|
|
|
&i.Group,
|
|
|
|
&i.Deleted,
|
|
|
|
&i.Createdat,
|
|
|
|
&i.Subdomain,
|
|
|
|
&i.Amouserid,
|
|
|
|
&i.Country,
|
|
|
|
)
|
|
|
|
return i, err
|
2024-04-17 17:18:52 +00:00
|
|
|
}
|
|
|
|
|
2024-06-03 08:33:19 +00:00
|
|
|
const getExpiredCountPrivilege = `-- name: GetExpiredCountPrivilege :many
|
2024-06-03 08:34:42 +00:00
|
|
|
SELECT p.id, p.privilegeID, p.privilege_name, p.amount, p.created_at, a.user_id
|
|
|
|
FROM privileges p
|
|
|
|
JOIN account a ON p.account_id = a.id
|
|
|
|
WHERE p.amount = 0
|
|
|
|
AND p.privilegeID = $1
|
2024-06-03 08:33:19 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type GetExpiredCountPrivilegeRow struct {
|
|
|
|
ID int32 `db:"id" json:"id"`
|
|
|
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
|
|
|
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
|
|
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
2024-06-03 08:34:42 +00:00
|
|
|
UserID sql.NullString `db:"user_id" json:"user_id"`
|
2024-06-03 08:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetExpiredCountPrivilege(ctx context.Context, privilegeid sql.NullString) ([]GetExpiredCountPrivilegeRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getExpiredCountPrivilege, privilegeid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetExpiredCountPrivilegeRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetExpiredCountPrivilegeRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Privilegeid,
|
|
|
|
&i.PrivilegeName,
|
|
|
|
&i.Amount,
|
|
|
|
&i.CreatedAt,
|
2024-06-03 08:34:42 +00:00
|
|
|
&i.UserID,
|
2024-06-03 08:33:19 +00:00
|
|
|
); 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 getExpiredDayPrivilege = `-- name: GetExpiredDayPrivilege :many
|
2024-06-03 08:34:42 +00:00
|
|
|
SELECT p.id, p.privilegeID, p.privilege_name, p.amount, p.created_at, a.user_id
|
|
|
|
FROM privileges p
|
|
|
|
JOIN account a ON p.account_id = a.id
|
|
|
|
WHERE p.created_at + p.amount * interval '1 day' < NOW()
|
|
|
|
AND p.privilegeID = $1
|
2024-02-19 16:33:15 +00:00
|
|
|
`
|
|
|
|
|
2024-06-03 08:33:19 +00:00
|
|
|
type GetExpiredDayPrivilegeRow struct {
|
2024-02-19 16:33:15 +00:00
|
|
|
ID int32 `db:"id" json:"id"`
|
|
|
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
|
|
|
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
|
|
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
2024-06-03 08:34:42 +00:00
|
|
|
UserID sql.NullString `db:"user_id" json:"user_id"`
|
2024-02-19 16:33:15 +00:00
|
|
|
}
|
|
|
|
|
2024-06-03 08:33:19 +00:00
|
|
|
func (q *Queries) GetExpiredDayPrivilege(ctx context.Context, privilegeid sql.NullString) ([]GetExpiredDayPrivilegeRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getExpiredDayPrivilege, privilegeid)
|
2024-02-19 16:33:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
2024-06-03 08:33:19 +00:00
|
|
|
var items []GetExpiredDayPrivilegeRow
|
2024-02-19 16:33:15 +00:00
|
|
|
for rows.Next() {
|
2024-06-03 08:33:19 +00:00
|
|
|
var i GetExpiredDayPrivilegeRow
|
2024-02-19 16:33:15 +00:00
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Privilegeid,
|
|
|
|
&i.PrivilegeName,
|
|
|
|
&i.Amount,
|
|
|
|
&i.CreatedAt,
|
2024-06-03 08:34:42 +00:00
|
|
|
&i.UserID,
|
2024-02-19 16:33:15 +00:00
|
|
|
); 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
|
|
|
|
}
|
|
|
|
|
2024-05-10 09:02:17 +00:00
|
|
|
const getFieldByAmoID = `-- name: GetFieldByAmoID :one
|
|
|
|
SELECT id, amoid, code, accountid, name, entity, type, deleted, createdat FROM fields WHERE AmoID = $1 AND Deleted = false
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) GetFieldByAmoID(ctx context.Context, amoid int32) (Field, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, getFieldByAmoID, amoid)
|
|
|
|
var i Field
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Amoid,
|
|
|
|
&i.Code,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Name,
|
|
|
|
&i.Entity,
|
|
|
|
&i.Type,
|
|
|
|
&i.Deleted,
|
|
|
|
&i.Createdat,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
2024-04-18 10:16:03 +00:00
|
|
|
const getFieldsWithPagination = `-- name: GetFieldsWithPagination :many
|
2024-04-21 15:18:53 +00:00
|
|
|
SELECT f.id, f.amoid, f.code, f.accountid, f.name, f.entity, f.type, f.deleted, f.createdat, COUNT(*) OVER() as total_count
|
2024-06-04 16:16:00 +00:00
|
|
|
FROM fields f JOIN (SELECT AmoID FROM users WHERE users.AccountID = $1 AND Deleted = false) u ON f.AccountID = u.AmoID
|
2024-04-21 15:18:53 +00:00
|
|
|
WHERE f.Deleted = false
|
|
|
|
ORDER BY f.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
2024-04-18 10:16:03 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type GetFieldsWithPaginationParams struct {
|
2024-04-21 15:18:53 +00:00
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
Column2 interface{} `db:"column_2" json:"column_2"`
|
|
|
|
Limit int32 `db:"limit" json:"limit"`
|
2024-04-18 10:16:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type GetFieldsWithPaginationRow 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"`
|
2024-04-28 13:06:06 +00:00
|
|
|
Type interface{} `db:"type" json:"type"`
|
2024-04-18 10:16:03 +00:00
|
|
|
Deleted bool `db:"deleted" json:"deleted"`
|
|
|
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
|
|
|
TotalCount int64 `db:"total_count" json:"total_count"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetFieldsWithPagination(ctx context.Context, arg GetFieldsWithPaginationParams) ([]GetFieldsWithPaginationRow, error) {
|
2024-04-21 15:18:53 +00:00
|
|
|
rows, err := q.db.QueryContext(ctx, getFieldsWithPagination, arg.Accountid, arg.Column2, arg.Limit)
|
2024-04-18 10:16:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetFieldsWithPaginationRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetFieldsWithPaginationRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Amoid,
|
|
|
|
&i.Code,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Name,
|
|
|
|
&i.Entity,
|
|
|
|
&i.Type,
|
|
|
|
&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
|
|
|
|
}
|
|
|
|
|
2024-05-13 16:25:48 +00:00
|
|
|
const getListCreatedQuizzes = `-- name: GetListCreatedQuizzes :many
|
2024-04-03 16:08:10 +00:00
|
|
|
SELECT id
|
|
|
|
FROM quiz
|
|
|
|
WHERE accountid = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) GetListCreatedQuizzes(ctx context.Context, accountid string) ([]int64, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getListCreatedQuizzes, accountid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []int64
|
|
|
|
for rows.Next() {
|
|
|
|
var id int64
|
|
|
|
if err := rows.Scan(&id); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
items = append(items, id)
|
|
|
|
}
|
|
|
|
if err := rows.Close(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const getListStartQuiz = `-- name: GetListStartQuiz :many
|
2024-04-22 18:36:31 +00:00
|
|
|
SELECT id FROM quiz WHERE accountid = $1 AND status = 'start'
|
2024-04-03 16:08:10 +00:00
|
|
|
`
|
|
|
|
|
2024-04-22 18:36:31 +00:00
|
|
|
func (q *Queries) GetListStartQuiz(ctx context.Context, accountid string) ([]int64, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getListStartQuiz, accountid)
|
2024-04-03 16:08:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []int64
|
|
|
|
for rows.Next() {
|
2024-04-22 18:33:18 +00:00
|
|
|
var id int64
|
|
|
|
if err := rows.Scan(&id); err != nil {
|
2024-04-03 16:08:10 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2024-04-22 18:33:18 +00:00
|
|
|
items = append(items, id)
|
2024-04-03 16:08:10 +00:00
|
|
|
}
|
|
|
|
if err := rows.Close(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
|
|
|
|
2024-04-18 10:16:03 +00:00
|
|
|
const getPipelinesWithPagination = `-- name: GetPipelinesWithPagination :many
|
2024-04-21 15:18:53 +00:00
|
|
|
SELECT p.id, p.amoid, p.accountid, p.name, p.isarchive, p.deleted, p.createdat, COUNT(*) OVER() as total_count
|
2024-06-04 16:16:00 +00:00
|
|
|
FROM pipelines p JOIN (SELECT AmoID FROM users WHERE users.AccountID = $1 AND Deleted = false) u ON p.AccountID = u.AmoID
|
2024-04-21 15:18:53 +00:00
|
|
|
WHERE p.Deleted = false
|
|
|
|
ORDER BY p.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
2024-04-18 10:16:03 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type GetPipelinesWithPaginationParams struct {
|
2024-04-21 15:18:53 +00:00
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
Column2 interface{} `db:"column_2" json:"column_2"`
|
|
|
|
Limit int32 `db:"limit" json:"limit"`
|
2024-04-18 10:16:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type GetPipelinesWithPaginationRow struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Amoid int32 `db:"amoid" json:"amoid"`
|
|
|
|
Accountid int32 `db:"accountid" json:"accountid"`
|
|
|
|
Name string `db:"name" json:"name"`
|
|
|
|
Isarchive bool `db:"isarchive" json:"isarchive"`
|
|
|
|
Deleted bool `db:"deleted" json:"deleted"`
|
|
|
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
|
|
|
TotalCount int64 `db:"total_count" json:"total_count"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetPipelinesWithPagination(ctx context.Context, arg GetPipelinesWithPaginationParams) ([]GetPipelinesWithPaginationRow, error) {
|
2024-04-21 15:18:53 +00:00
|
|
|
rows, err := q.db.QueryContext(ctx, getPipelinesWithPagination, arg.Accountid, arg.Column2, arg.Limit)
|
2024-04-18 10:16:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetPipelinesWithPaginationRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetPipelinesWithPaginationRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Amoid,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Name,
|
|
|
|
&i.Isarchive,
|
|
|
|
&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
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:33:15 +00:00
|
|
|
const getPrivilegesByAccountID = `-- name: GetPrivilegesByAccountID :many
|
|
|
|
SELECT id,privilegeID,privilege_name,amount, created_at FROM privileges WHERE account_id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetPrivilegesByAccountIDRow struct {
|
|
|
|
ID int32 `db:"id" json:"id"`
|
|
|
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
|
|
|
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
|
|
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetPrivilegesByAccountID(ctx context.Context, accountID uuid.NullUUID) ([]GetPrivilegesByAccountIDRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getPrivilegesByAccountID, accountID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetPrivilegesByAccountIDRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetPrivilegesByAccountIDRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Privilegeid,
|
|
|
|
&i.PrivilegeName,
|
|
|
|
&i.Amount,
|
|
|
|
&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 getPrivilegesByAccountIDWC = `-- name: GetPrivilegesByAccountIDWC :many
|
|
|
|
SELECT p.id,p.privilegeID,p.privilege_name,p.amount, p.created_at FROM privileges as p JOIN account as a on p.account_id = a.id WHERE a.user_id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetPrivilegesByAccountIDWCRow struct {
|
|
|
|
ID int32 `db:"id" json:"id"`
|
|
|
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
|
|
|
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
|
|
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetPrivilegesByAccountIDWC(ctx context.Context, userID sql.NullString) ([]GetPrivilegesByAccountIDWCRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getPrivilegesByAccountIDWC, userID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetPrivilegesByAccountIDWCRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetPrivilegesByAccountIDWCRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Privilegeid,
|
|
|
|
&i.PrivilegeName,
|
|
|
|
&i.Amount,
|
|
|
|
&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 getPrivilegesQuizAccount = `-- name: GetPrivilegesQuizAccount :many
|
|
|
|
SELECT
|
|
|
|
p.privilegeID,
|
|
|
|
p.privilege_name,
|
|
|
|
p.amount,
|
|
|
|
p.created_at,
|
|
|
|
a.id,
|
|
|
|
a.email,
|
|
|
|
qz.config
|
|
|
|
FROM
|
|
|
|
privileges AS p
|
|
|
|
INNER JOIN account AS a ON p.account_id = a.id
|
|
|
|
INNER JOIN quiz AS qz ON qz.accountid = a.user_id
|
|
|
|
WHERE
|
|
|
|
qz.id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetPrivilegesQuizAccountRow struct {
|
|
|
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
|
|
|
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
|
|
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
|
|
|
ID uuid.UUID `db:"id" json:"id"`
|
|
|
|
Email sql.NullString `db:"email" json:"email"`
|
|
|
|
Config sql.NullString `db:"config" json:"config"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetPrivilegesQuizAccount(ctx context.Context, id int64) ([]GetPrivilegesQuizAccountRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getPrivilegesQuizAccount, id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetPrivilegesQuizAccountRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetPrivilegesQuizAccountRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.Privilegeid,
|
|
|
|
&i.PrivilegeName,
|
|
|
|
&i.Amount,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.ID,
|
|
|
|
&i.Email,
|
|
|
|
&i.Config,
|
|
|
|
); 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
|
|
|
|
}
|
|
|
|
|
2024-03-19 17:09:44 +00:00
|
|
|
const getQidOwner = `-- name: GetQidOwner :one
|
|
|
|
SELECT accountid FROM quiz where qid=$1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) GetQidOwner(ctx context.Context, qid uuid.NullUUID) (string, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, getQidOwner, qid)
|
|
|
|
var accountid string
|
|
|
|
err := row.Scan(&accountid)
|
|
|
|
return accountid, err
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:33:15 +00:00
|
|
|
const getQuestionHistory = `-- name: GetQuestionHistory :many
|
|
|
|
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at FROM question WHERE question.id = $1 OR question.id = ANY(
|
|
|
|
SELECT unnest(parent_ids) FROM question WHERE id = $1
|
|
|
|
) ORDER BY question.id DESC LIMIT $2 OFFSET $3
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetQuestionHistoryParams struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Limit int32 `db:"limit" json:"limit"`
|
|
|
|
Offset int32 `db:"offset" json:"offset"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetQuestionHistory(ctx context.Context, arg GetQuestionHistoryParams) ([]Question, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getQuestionHistory, arg.ID, arg.Limit, arg.Offset)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-05-02 07:35:17 +00:00
|
|
|
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 {
|
2024-02-19 16:33:15 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const getQuestionTitle = `-- name: GetQuestionTitle :one
|
2024-04-16 11:07:18 +00:00
|
|
|
SELECT title, questiontype,page FROM question WHERE id = $1
|
2024-02-19 16:33:15 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type GetQuestionTitleRow struct {
|
2024-04-16 11:07:18 +00:00
|
|
|
Title string `db:"title" json:"title"`
|
|
|
|
Questiontype interface{} `db:"questiontype" json:"questiontype"`
|
|
|
|
Page sql.NullInt16 `db:"page" json:"page"`
|
2024-02-19 16:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetQuestionTitle(ctx context.Context, id int64) (GetQuestionTitleRow, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, getQuestionTitle, id)
|
|
|
|
var i GetQuestionTitleRow
|
2024-04-16 11:07:18 +00:00
|
|
|
err := row.Scan(&i.Title, &i.Questiontype, &i.Page)
|
2024-02-19 16:33:15 +00:00
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const getQuestions = `-- name: GetQuestions :many
|
2024-04-16 08:43:59 +00:00
|
|
|
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at FROM question WHERE quiz_id = $1 AND deleted = FALSE ORDER BY page ASC
|
2024-02-19 16:33:15 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) GetQuestions(ctx context.Context, quizID int64) ([]Question, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getQuestions, quizID)
|
|
|
|
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 getQuizById = `-- name: GetQuizById :one
|
|
|
|
SELECT id, qid, accountid, deleted, archived, fingerprinting, repeatable, note_prevented, mail_notifications, unique_answers, super, group_id, name, description, config, status, limit_answers, due_to, time_of_passing, pausable, version, version_comment, parent_ids, created_at, updated_at, questions_count, answers_count, average_time_passing, sessions_count FROM quiz WHERE id=$1 AND accountId=$2
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetQuizByIdParams struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetQuizById(ctx context.Context, arg GetQuizByIdParams) (Quiz, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, getQuizById, arg.ID, arg.Accountid)
|
|
|
|
var i Quiz
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Qid,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Deleted,
|
|
|
|
&i.Archived,
|
|
|
|
&i.Fingerprinting,
|
|
|
|
&i.Repeatable,
|
|
|
|
&i.NotePrevented,
|
|
|
|
&i.MailNotifications,
|
|
|
|
&i.UniqueAnswers,
|
|
|
|
&i.Super,
|
|
|
|
&i.GroupID,
|
|
|
|
&i.Name,
|
|
|
|
&i.Description,
|
|
|
|
&i.Config,
|
|
|
|
&i.Status,
|
|
|
|
&i.LimitAnswers,
|
|
|
|
&i.DueTo,
|
|
|
|
&i.TimeOfPassing,
|
|
|
|
&i.Pausable,
|
|
|
|
&i.Version,
|
|
|
|
&i.VersionComment,
|
|
|
|
pq.Array(&i.ParentIds),
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.UpdatedAt,
|
|
|
|
&i.QuestionsCount,
|
|
|
|
&i.AnswersCount,
|
|
|
|
&i.AverageTimePassing,
|
|
|
|
&i.SessionsCount,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const getQuizByQid = `-- name: GetQuizByQid :one
|
|
|
|
SELECT id, qid, accountid, deleted, archived, fingerprinting, repeatable, note_prevented, mail_notifications, unique_answers, super, group_id, name, description, config, status, limit_answers, due_to, time_of_passing, pausable, version, version_comment, parent_ids, created_at, updated_at, questions_count, answers_count, average_time_passing, sessions_count FROM quiz
|
|
|
|
WHERE
|
|
|
|
deleted = false AND
|
|
|
|
archived = false AND
|
|
|
|
status = 'start' AND
|
|
|
|
qid = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) GetQuizByQid(ctx context.Context, qid uuid.NullUUID) (Quiz, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, getQuizByQid, qid)
|
|
|
|
var i Quiz
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Qid,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Deleted,
|
|
|
|
&i.Archived,
|
|
|
|
&i.Fingerprinting,
|
|
|
|
&i.Repeatable,
|
|
|
|
&i.NotePrevented,
|
|
|
|
&i.MailNotifications,
|
|
|
|
&i.UniqueAnswers,
|
|
|
|
&i.Super,
|
|
|
|
&i.GroupID,
|
|
|
|
&i.Name,
|
|
|
|
&i.Description,
|
|
|
|
&i.Config,
|
|
|
|
&i.Status,
|
|
|
|
&i.LimitAnswers,
|
|
|
|
&i.DueTo,
|
|
|
|
&i.TimeOfPassing,
|
|
|
|
&i.Pausable,
|
|
|
|
&i.Version,
|
|
|
|
&i.VersionComment,
|
|
|
|
pq.Array(&i.ParentIds),
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.UpdatedAt,
|
|
|
|
&i.QuestionsCount,
|
|
|
|
&i.AnswersCount,
|
|
|
|
&i.AverageTimePassing,
|
|
|
|
&i.SessionsCount,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const getQuizConfig = `-- name: GetQuizConfig :one
|
|
|
|
SELECT config, accountid FROM quiz WHERE id = $1 AND deleted = false
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetQuizConfigRow struct {
|
|
|
|
Config sql.NullString `db:"config" json:"config"`
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetQuizConfig(ctx context.Context, id int64) (GetQuizConfigRow, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, getQuizConfig, id)
|
|
|
|
var i GetQuizConfigRow
|
|
|
|
err := row.Scan(&i.Config, &i.Accountid)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const getQuizHistory = `-- name: GetQuizHistory :many
|
2024-04-22 10:44:18 +00:00
|
|
|
SELECT id, qid, accountid, deleted, archived, fingerprinting, repeatable, note_prevented, mail_notifications, unique_answers, super, group_id, name, description, config, status, limit_answers, due_to, time_of_passing, pausable, version, version_comment, parent_ids, created_at, updated_at, questions_count, answers_count, average_time_passing, sessions_count FROM quiz WHERE quiz.id = $1 AND quiz.accountId = $4 OR quiz.id = ANY(
|
2024-02-19 16:33:15 +00:00
|
|
|
SELECT unnest(parent_ids) FROM quiz WHERE id = $1
|
|
|
|
) ORDER BY quiz.id DESC LIMIT $2 OFFSET $3
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetQuizHistoryParams struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Limit int32 `db:"limit" json:"limit"`
|
|
|
|
Offset int32 `db:"offset" json:"offset"`
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetQuizHistory(ctx context.Context, arg GetQuizHistoryParams) ([]Quiz, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getQuizHistory,
|
|
|
|
arg.ID,
|
|
|
|
arg.Limit,
|
|
|
|
arg.Offset,
|
|
|
|
arg.Accountid,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []Quiz
|
|
|
|
for rows.Next() {
|
|
|
|
var i Quiz
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Qid,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Deleted,
|
|
|
|
&i.Archived,
|
|
|
|
&i.Fingerprinting,
|
|
|
|
&i.Repeatable,
|
|
|
|
&i.NotePrevented,
|
|
|
|
&i.MailNotifications,
|
|
|
|
&i.UniqueAnswers,
|
|
|
|
&i.Super,
|
|
|
|
&i.GroupID,
|
|
|
|
&i.Name,
|
|
|
|
&i.Description,
|
|
|
|
&i.Config,
|
|
|
|
&i.Status,
|
|
|
|
&i.LimitAnswers,
|
|
|
|
&i.DueTo,
|
|
|
|
&i.TimeOfPassing,
|
|
|
|
&i.Pausable,
|
|
|
|
&i.Version,
|
|
|
|
&i.VersionComment,
|
|
|
|
pq.Array(&i.ParentIds),
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.UpdatedAt,
|
|
|
|
&i.QuestionsCount,
|
|
|
|
&i.AnswersCount,
|
|
|
|
&i.AverageTimePassing,
|
|
|
|
&i.SessionsCount,
|
|
|
|
); 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
|
|
|
|
}
|
|
|
|
|
2024-04-23 11:48:15 +00:00
|
|
|
const getQuizRule = `-- name: GetQuizRule :one
|
2024-05-17 18:50:51 +00:00
|
|
|
SELECT id, accountid, quizid, performerid, pipelineid, stepid, fieldsrule, deleted, createdat FROM rules WHERE QuizID = $1 AND Deleted = false
|
2024-04-23 11:48:15 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
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,
|
|
|
|
&i.Fieldsrule,
|
|
|
|
&i.Deleted,
|
|
|
|
&i.Createdat,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:33:15 +00:00
|
|
|
const getResultAnswers = `-- name: GetResultAnswers :many
|
2024-03-31 22:30:38 +00:00
|
|
|
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
|
2024-02-19 16:33:15 +00:00
|
|
|
`
|
|
|
|
|
2024-03-13 16:21:37 +00:00
|
|
|
type GetResultAnswersRow struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Content sql.NullString `db:"content" json:"content"`
|
|
|
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
|
|
|
QuestionID int64 `db:"question_id" json:"question_id"`
|
|
|
|
Fingerprint sql.NullString `db:"fingerprint" json:"fingerprint"`
|
|
|
|
Session sql.NullString `db:"session" json:"session"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
|
|
|
Result sql.NullBool `db:"result" json:"result"`
|
|
|
|
New sql.NullBool `db:"new" json:"new"`
|
|
|
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
2024-03-31 22:30:38 +00:00
|
|
|
DeviceType string `db:"device_type" json:"device_type"`
|
|
|
|
Device string `db:"device" json:"device"`
|
|
|
|
Os string `db:"os" json:"os"`
|
|
|
|
Browser string `db:"browser" json:"browser"`
|
|
|
|
Ip string `db:"ip" json:"ip"`
|
2024-03-13 16:21:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetResultAnswers(ctx context.Context, id int64) ([]GetResultAnswersRow, error) {
|
2024-02-19 16:33:15 +00:00
|
|
|
rows, err := q.db.QueryContext(ctx, getResultAnswers, id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
2024-03-13 16:21:37 +00:00
|
|
|
var items []GetResultAnswersRow
|
2024-02-19 16:33:15 +00:00
|
|
|
for rows.Next() {
|
2024-03-13 16:21:37 +00:00
|
|
|
var i GetResultAnswersRow
|
2024-02-19 16:33:15 +00:00
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Content,
|
|
|
|
&i.QuizID,
|
|
|
|
&i.QuestionID,
|
|
|
|
&i.Fingerprint,
|
|
|
|
&i.Session,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.Result,
|
|
|
|
&i.New,
|
|
|
|
&i.Deleted,
|
2024-03-31 22:30:38 +00:00
|
|
|
&i.DeviceType,
|
|
|
|
&i.Device,
|
|
|
|
&i.Os,
|
|
|
|
&i.Browser,
|
|
|
|
&i.Ip,
|
2024-02-19 16:33:15 +00:00
|
|
|
); 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
|
|
|
|
}
|
|
|
|
|
2024-04-18 10:16:03 +00:00
|
|
|
const getStepsWithPagination = `-- name: GetStepsWithPagination :many
|
2024-04-21 15:18:53 +00:00
|
|
|
SELECT s.id, s.amoid, s.pipelineid, s.accountid, s.name, s.color, s.deleted, s.createdat, COUNT(*) OVER() as total_count
|
2024-06-04 16:16:00 +00:00
|
|
|
FROM steps s JOIN (SELECT AmoID FROM users WHERE users.AccountID = $1 AND Deleted = false) u ON s.AccountID = u.AmoID
|
2024-05-13 12:31:39 +00:00
|
|
|
WHERE s.Deleted = false AND PipelineID = $4
|
2024-04-21 15:18:53 +00:00
|
|
|
ORDER BY s.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
2024-04-18 10:16:03 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type GetStepsWithPaginationParams struct {
|
2024-05-13 12:31:39 +00:00
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
Column2 interface{} `db:"column_2" json:"column_2"`
|
|
|
|
Limit int32 `db:"limit" json:"limit"`
|
|
|
|
Pipelineid int32 `db:"pipelineid" json:"pipelineid"`
|
2024-04-18 10:16:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type GetStepsWithPaginationRow struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Amoid int32 `db:"amoid" json:"amoid"`
|
|
|
|
Pipelineid int32 `db:"pipelineid" json:"pipelineid"`
|
|
|
|
Accountid int32 `db:"accountid" json:"accountid"`
|
|
|
|
Name string `db:"name" json:"name"`
|
|
|
|
Color string `db:"color" json:"color"`
|
|
|
|
Deleted bool `db:"deleted" json:"deleted"`
|
|
|
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
|
|
|
TotalCount int64 `db:"total_count" json:"total_count"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetStepsWithPagination(ctx context.Context, arg GetStepsWithPaginationParams) ([]GetStepsWithPaginationRow, error) {
|
2024-05-13 12:31:39 +00:00
|
|
|
rows, err := q.db.QueryContext(ctx, getStepsWithPagination,
|
|
|
|
arg.Accountid,
|
|
|
|
arg.Column2,
|
|
|
|
arg.Limit,
|
|
|
|
arg.Pipelineid,
|
|
|
|
)
|
2024-04-18 10:16:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetStepsWithPaginationRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetStepsWithPaginationRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Amoid,
|
|
|
|
&i.Pipelineid,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Name,
|
|
|
|
&i.Color,
|
|
|
|
&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 getTagsWithPagination = `-- name: GetTagsWithPagination :many
|
2024-04-21 15:18:53 +00:00
|
|
|
SELECT t.id, t.amoid, t.accountid, t.entity, t.name, t.color, t.deleted, t.createdat, COUNT(*) OVER() as total_count
|
2024-06-04 16:16:00 +00:00
|
|
|
FROM tags t JOIN (SELECT AmoID FROM users WHERE users.AccountID = $1 AND Deleted = false) u ON t.AccountID = u.AmoID
|
2024-04-21 15:18:53 +00:00
|
|
|
WHERE t.Deleted = false
|
|
|
|
ORDER BY t.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
2024-04-18 10:16:03 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type GetTagsWithPaginationParams struct {
|
2024-04-21 15:18:53 +00:00
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
Column2 interface{} `db:"column_2" json:"column_2"`
|
|
|
|
Limit int32 `db:"limit" json:"limit"`
|
2024-04-18 10:16:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type GetTagsWithPaginationRow struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Amoid int32 `db:"amoid" json:"amoid"`
|
|
|
|
Accountid int32 `db:"accountid" json:"accountid"`
|
|
|
|
Entity interface{} `db:"entity" json:"entity"`
|
|
|
|
Name string `db:"name" json:"name"`
|
|
|
|
Color string `db:"color" json:"color"`
|
|
|
|
Deleted bool `db:"deleted" json:"deleted"`
|
|
|
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
|
|
|
TotalCount int64 `db:"total_count" json:"total_count"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetTagsWithPagination(ctx context.Context, arg GetTagsWithPaginationParams) ([]GetTagsWithPaginationRow, error) {
|
2024-04-21 15:18:53 +00:00
|
|
|
rows, err := q.db.QueryContext(ctx, getTagsWithPagination, arg.Accountid, arg.Column2, arg.Limit)
|
2024-04-18 10:16:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetTagsWithPaginationRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetTagsWithPaginationRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Amoid,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Entity,
|
|
|
|
&i.Name,
|
|
|
|
&i.Color,
|
|
|
|
&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
|
|
|
|
}
|
|
|
|
|
2024-04-21 13:57:43 +00:00
|
|
|
const getTokenById = `-- name: GetTokenById :one
|
2024-04-21 13:52:25 +00:00
|
|
|
SELECT accountid, refreshtoken, accesstoken, authcode, expiration, createdat FROM tokens WHERE accountID = $1
|
|
|
|
`
|
|
|
|
|
2024-04-21 13:57:43 +00:00
|
|
|
func (q *Queries) GetTokenById(ctx context.Context, accountid string) (Token, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, getTokenById, accountid)
|
|
|
|
var i Token
|
|
|
|
err := row.Scan(
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Refreshtoken,
|
|
|
|
&i.Accesstoken,
|
|
|
|
&i.Authcode,
|
|
|
|
&i.Expiration,
|
|
|
|
&i.Createdat,
|
|
|
|
)
|
|
|
|
return i, err
|
2024-04-21 13:52:25 +00:00
|
|
|
}
|
|
|
|
|
2024-04-29 21:45:58 +00:00
|
|
|
const getUserFieldsByID = `-- name: GetUserFieldsByID :many
|
|
|
|
SELECT ID,AmoID,Code,AccountID,Name,Entity,Type
|
|
|
|
FROM fields
|
2024-05-07 17:47:49 +00:00
|
|
|
WHERE AccountID = $1 AND Deleted = false
|
2024-04-29 21:45:58 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-05-07 17:47:49 +00:00
|
|
|
const getUserPipelinesByID = `-- name: GetUserPipelinesByID :many
|
|
|
|
SELECT ID,AmoID,AccountID,Name,IsArchive
|
|
|
|
FROM pipelines
|
|
|
|
WHERE AccountID = $1 AND Deleted = false
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetUserPipelinesByIDRow struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Amoid int32 `db:"amoid" json:"amoid"`
|
|
|
|
Accountid int32 `db:"accountid" json:"accountid"`
|
|
|
|
Name string `db:"name" json:"name"`
|
|
|
|
Isarchive bool `db:"isarchive" json:"isarchive"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetUserPipelinesByID(ctx context.Context, accountid int32) ([]GetUserPipelinesByIDRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getUserPipelinesByID, accountid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetUserPipelinesByIDRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetUserPipelinesByIDRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Amoid,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Name,
|
|
|
|
&i.Isarchive,
|
|
|
|
); 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 getUserStepsByID = `-- name: GetUserStepsByID :many
|
|
|
|
SELECT ID,AmoID,PipelineID,AccountID,Name,Color
|
|
|
|
FROM steps
|
|
|
|
WHERE AccountID = $1 AND Deleted = false
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetUserStepsByIDRow struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Amoid int32 `db:"amoid" json:"amoid"`
|
|
|
|
Pipelineid int32 `db:"pipelineid" json:"pipelineid"`
|
|
|
|
Accountid int32 `db:"accountid" json:"accountid"`
|
|
|
|
Name string `db:"name" json:"name"`
|
|
|
|
Color string `db:"color" json:"color"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetUserStepsByID(ctx context.Context, accountid int32) ([]GetUserStepsByIDRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getUserStepsByID, accountid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetUserStepsByIDRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetUserStepsByIDRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Amoid,
|
|
|
|
&i.Pipelineid,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Name,
|
|
|
|
&i.Color,
|
|
|
|
); 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 getUserTagsByID = `-- name: GetUserTagsByID :many
|
|
|
|
SELECT ID,AmoID,AccountID,Name,Entity,Color
|
|
|
|
FROM tags
|
|
|
|
WHERE AccountID = $1 AND Deleted = false
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetUserTagsByIDRow struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Amoid int32 `db:"amoid" json:"amoid"`
|
|
|
|
Accountid int32 `db:"accountid" json:"accountid"`
|
|
|
|
Name string `db:"name" json:"name"`
|
|
|
|
Entity interface{} `db:"entity" json:"entity"`
|
|
|
|
Color string `db:"color" json:"color"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetUserTagsByID(ctx context.Context, accountid int32) ([]GetUserTagsByIDRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getUserTagsByID, accountid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetUserTagsByIDRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetUserTagsByIDRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Amoid,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Name,
|
|
|
|
&i.Entity,
|
|
|
|
&i.Color,
|
|
|
|
); 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 getUserUsersByID = `-- name: GetUserUsersByID :many
|
|
|
|
SELECT ID,AccountID,AmoID,Name,Email,Role,"Group",Subdomain,AmoUserID,Country
|
|
|
|
FROM users
|
|
|
|
WHERE AmoUserID = $1 AND Deleted = false
|
2024-02-19 16:33:15 +00:00
|
|
|
`
|
|
|
|
|
2024-05-07 17:47:49 +00:00
|
|
|
type GetUserUsersByIDRow struct {
|
2024-02-19 16:33:15 +00:00
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
2024-05-07 17:47:49 +00:00
|
|
|
Amoid int32 `db:"amoid" json:"amoid"`
|
|
|
|
Name string `db:"name" json:"name"`
|
|
|
|
Email string `db:"email" json:"email"`
|
|
|
|
Role int32 `db:"role" json:"role"`
|
|
|
|
Group int32 `db:"Group" json:"Group"`
|
|
|
|
Subdomain string `db:"subdomain" json:"subdomain"`
|
|
|
|
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
|
|
|
Country string `db:"country" json:"country"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetUserUsersByID(ctx context.Context, amouserid int32) ([]GetUserUsersByIDRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getUserUsersByID, amouserid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetUserUsersByIDRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetUserUsersByIDRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Amoid,
|
|
|
|
&i.Name,
|
|
|
|
&i.Email,
|
|
|
|
&i.Role,
|
|
|
|
&i.Group,
|
|
|
|
&i.Subdomain,
|
|
|
|
&i.Amouserid,
|
|
|
|
&i.Country,
|
|
|
|
); 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
|
2024-02-19 16:33:15 +00:00
|
|
|
}
|
|
|
|
|
2024-04-17 17:18:52 +00:00
|
|
|
const getUsersWithPagination = `-- name: GetUsersWithPagination :many
|
2024-04-22 08:33:25 +00:00
|
|
|
WITH user_data AS (
|
|
|
|
SELECT AmoID FROM users WHERE users.AccountID = $1 AND Deleted = false
|
|
|
|
)
|
2024-04-22 08:37:07 +00:00
|
|
|
SELECT u.id, u.accountid, u.amoid, u.name, u.email, u.role, u."Group", u.deleted, u.createdat, u.subdomain, u.amouserid, u.country, COUNT(*) OVER() as total_count
|
2024-04-22 08:33:25 +00:00
|
|
|
FROM users u
|
|
|
|
JOIN user_data a ON u.AmoUserID = a.AmoID
|
|
|
|
WHERE u.Deleted = false
|
|
|
|
ORDER BY u.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
2024-04-17 17:18:52 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type GetUsersWithPaginationParams struct {
|
2024-04-21 15:18:53 +00:00
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
2024-04-22 08:33:25 +00:00
|
|
|
Column2 interface{} `db:"column_2" json:"column_2"`
|
|
|
|
Limit int32 `db:"limit" json:"limit"`
|
2024-04-17 17:18:52 +00:00
|
|
|
}
|
|
|
|
|
2024-04-17 17:43:28 +00:00
|
|
|
type GetUsersWithPaginationRow struct {
|
2024-04-20 09:01:25 +00:00
|
|
|
ID int64 `db:"id" json:"id"`
|
2024-04-22 08:37:07 +00:00
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
Amoid int32 `db:"amoid" json:"amoid"`
|
2024-04-20 09:01:25 +00:00
|
|
|
Name string `db:"name" json:"name"`
|
|
|
|
Email string `db:"email" json:"email"`
|
|
|
|
Role int32 `db:"role" json:"role"`
|
|
|
|
Group int32 `db:"Group" json:"Group"`
|
2024-04-22 08:37:07 +00:00
|
|
|
Deleted bool `db:"deleted" json:"deleted"`
|
2024-04-20 09:01:25 +00:00
|
|
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
|
|
|
Subdomain string `db:"subdomain" json:"subdomain"`
|
2024-04-22 08:33:25 +00:00
|
|
|
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
2024-04-22 08:37:07 +00:00
|
|
|
Country string `db:"country" json:"country"`
|
2024-04-20 09:01:25 +00:00
|
|
|
TotalCount int64 `db:"total_count" json:"total_count"`
|
2024-04-17 17:43:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetUsersWithPagination(ctx context.Context, arg GetUsersWithPaginationParams) ([]GetUsersWithPaginationRow, error) {
|
2024-04-22 08:33:25 +00:00
|
|
|
rows, err := q.db.QueryContext(ctx, getUsersWithPagination, arg.Accountid, arg.Column2, arg.Limit)
|
2024-02-19 16:33:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
2024-04-17 17:43:28 +00:00
|
|
|
var items []GetUsersWithPaginationRow
|
2024-02-19 16:33:15 +00:00
|
|
|
for rows.Next() {
|
2024-04-17 17:43:28 +00:00
|
|
|
var i GetUsersWithPaginationRow
|
2024-02-19 16:33:15 +00:00
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Accountid,
|
2024-04-22 08:37:07 +00:00
|
|
|
&i.Amoid,
|
2024-02-19 16:33:15 +00:00
|
|
|
&i.Name,
|
2024-04-17 17:18:52 +00:00
|
|
|
&i.Email,
|
|
|
|
&i.Role,
|
|
|
|
&i.Group,
|
2024-04-22 08:37:07 +00:00
|
|
|
&i.Deleted,
|
2024-04-17 17:18:52 +00:00
|
|
|
&i.Createdat,
|
|
|
|
&i.Subdomain,
|
2024-04-22 08:33:25 +00:00
|
|
|
&i.Amouserid,
|
2024-04-22 08:37:07 +00:00
|
|
|
&i.Country,
|
2024-04-17 17:43:28 +00:00
|
|
|
&i.TotalCount,
|
2024-02-19 16:33:15 +00:00
|
|
|
); 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
|
|
|
|
}
|
|
|
|
|
2024-05-04 10:33:50 +00:00
|
|
|
const gettingAmoUsersTrueResults = `-- name: GettingAmoUsersTrueResults :many
|
2024-05-19 12:22:35 +00:00
|
|
|
SELECT a.quiz_id,a.id,a.result,a.question_id,a.content,a.session,
|
|
|
|
(SELECT a2.utm
|
|
|
|
FROM answer a2
|
|
|
|
WHERE a2.start = true AND a2.session = a.session
|
|
|
|
LIMIT 1) AS utm
|
|
|
|
,t.accesstoken,r.accountid,r.fieldsrule,r.performerid,r.stepid,r.pipelineid,(SELECT u.name FROM users u WHERE u.amoid = r.performerid) AS performer_name
|
2024-05-04 10:33:50 +00:00
|
|
|
FROM answer a
|
|
|
|
INNER JOIN quiz q ON a.quiz_id = q.id
|
|
|
|
LEFT JOIN amoCRMStatuses s ON a.id = s.AnswerID
|
|
|
|
INNER JOIN rules r ON q.id = r.QuizID
|
|
|
|
INNER JOIN tokens t ON q.accountid = t.AccountID
|
|
|
|
INNER JOIN users u ON q.accountid = u.accountid AND u.amoid = r.accountid
|
|
|
|
WHERE a.result = true
|
|
|
|
AND s.id IS NULL
|
2024-05-04 10:39:08 +00:00
|
|
|
AND a.deleted = false
|
2024-05-04 10:33:50 +00:00
|
|
|
AND r.deleted = false
|
2024-05-04 10:37:43 +00:00
|
|
|
AND q.deleted = false
|
2024-05-04 10:33:50 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type GettingAmoUsersTrueResultsRow struct {
|
2024-05-04 10:40:24 +00:00
|
|
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Result sql.NullBool `db:"result" json:"result"`
|
|
|
|
QuestionID int64 `db:"question_id" json:"question_id"`
|
|
|
|
Content sql.NullString `db:"content" json:"content"`
|
|
|
|
Session sql.NullString `db:"session" json:"session"`
|
2024-05-19 12:22:35 +00:00
|
|
|
Utm json.RawMessage `db:"utm" json:"utm"`
|
2024-05-04 10:40:24 +00:00
|
|
|
Accesstoken string `db:"accesstoken" json:"accesstoken"`
|
|
|
|
Accountid int32 `db:"accountid" json:"accountid"`
|
|
|
|
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
|
|
|
Performerid int32 `db:"performerid" json:"performerid"`
|
|
|
|
Stepid int32 `db:"stepid" json:"stepid"`
|
|
|
|
Pipelineid int32 `db:"pipelineid" json:"pipelineid"`
|
|
|
|
PerformerName string `db:"performer_name" json:"performer_name"`
|
2024-05-04 10:33:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GettingAmoUsersTrueResults(ctx context.Context) ([]GettingAmoUsersTrueResultsRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, gettingAmoUsersTrueResults)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GettingAmoUsersTrueResultsRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GettingAmoUsersTrueResultsRow
|
|
|
|
if err := rows.Scan(
|
2024-02-19 16:33:15 +00:00
|
|
|
&i.QuizID,
|
2024-05-04 10:39:08 +00:00
|
|
|
&i.ID,
|
|
|
|
&i.Result,
|
2024-02-19 16:33:15 +00:00
|
|
|
&i.QuestionID,
|
2024-05-04 10:39:08 +00:00
|
|
|
&i.Content,
|
2024-02-19 16:33:15 +00:00
|
|
|
&i.Session,
|
2024-05-19 12:22:35 +00:00
|
|
|
&i.Utm,
|
2024-05-04 10:33:50 +00:00
|
|
|
&i.Accesstoken,
|
|
|
|
&i.Accountid,
|
|
|
|
&i.Fieldsrule,
|
2024-05-04 10:39:08 +00:00
|
|
|
&i.Performerid,
|
|
|
|
&i.Stepid,
|
|
|
|
&i.Pipelineid,
|
2024-05-04 10:40:24 +00:00
|
|
|
&i.PerformerName,
|
2024-02-19 16:33:15 +00:00
|
|
|
); 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
|
|
|
|
}
|
|
|
|
|
2024-06-01 17:54:33 +00:00
|
|
|
const insertAnswers = `-- name: InsertAnswers :one
|
2024-02-19 16:33:15 +00:00
|
|
|
INSERT INTO answer(
|
|
|
|
content,
|
|
|
|
quiz_id,
|
|
|
|
question_id,
|
|
|
|
fingerprint,
|
|
|
|
session,
|
2024-03-13 16:21:37 +00:00
|
|
|
result,
|
2024-03-14 13:32:20 +00:00
|
|
|
email,
|
|
|
|
device_type,
|
|
|
|
device,
|
|
|
|
os,
|
|
|
|
browser,
|
2024-03-15 11:32:26 +00:00
|
|
|
ip,
|
2024-05-17 17:22:23 +00:00
|
|
|
start,
|
|
|
|
utm
|
|
|
|
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)
|
2024-06-01 17:54:33 +00:00
|
|
|
RETURNING id, content, quiz_id, question_id, fingerprint, session, created_at, result, new, deleted, email, device_type, device, os, browser, ip, start, utm
|
2024-02-19 16:33:15 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type InsertAnswersParams struct {
|
2024-05-17 17:53:00 +00:00
|
|
|
Content sql.NullString `db:"content" json:"content"`
|
|
|
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
|
|
|
QuestionID int64 `db:"question_id" json:"question_id"`
|
|
|
|
Fingerprint sql.NullString `db:"fingerprint" json:"fingerprint"`
|
|
|
|
Session sql.NullString `db:"session" json:"session"`
|
|
|
|
Result sql.NullBool `db:"result" json:"result"`
|
|
|
|
Email string `db:"email" json:"email"`
|
|
|
|
DeviceType string `db:"device_type" json:"device_type"`
|
|
|
|
Device string `db:"device" json:"device"`
|
|
|
|
Os string `db:"os" json:"os"`
|
|
|
|
Browser string `db:"browser" json:"browser"`
|
|
|
|
Ip string `db:"ip" json:"ip"`
|
|
|
|
Start bool `db:"start" json:"start"`
|
|
|
|
Utm json.RawMessage `db:"utm" json:"utm"`
|
2024-02-19 16:33:15 +00:00
|
|
|
}
|
|
|
|
|
2024-06-01 17:54:33 +00:00
|
|
|
func (q *Queries) InsertAnswers(ctx context.Context, arg InsertAnswersParams) (Answer, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, insertAnswers,
|
2024-02-19 16:33:15 +00:00
|
|
|
arg.Content,
|
|
|
|
arg.QuizID,
|
|
|
|
arg.QuestionID,
|
|
|
|
arg.Fingerprint,
|
|
|
|
arg.Session,
|
|
|
|
arg.Result,
|
2024-03-13 16:21:37 +00:00
|
|
|
arg.Email,
|
2024-03-14 13:32:20 +00:00
|
|
|
arg.DeviceType,
|
|
|
|
arg.Device,
|
|
|
|
arg.Os,
|
|
|
|
arg.Browser,
|
|
|
|
arg.Ip,
|
2024-03-15 11:32:26 +00:00
|
|
|
arg.Start,
|
2024-05-17 17:22:23 +00:00
|
|
|
arg.Utm,
|
2024-02-19 16:33:15 +00:00
|
|
|
)
|
2024-06-01 17:54:33 +00:00
|
|
|
var i Answer
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Content,
|
|
|
|
&i.QuizID,
|
|
|
|
&i.QuestionID,
|
|
|
|
&i.Fingerprint,
|
|
|
|
&i.Session,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.Result,
|
|
|
|
&i.New,
|
|
|
|
&i.Deleted,
|
|
|
|
&i.Email,
|
|
|
|
&i.DeviceType,
|
|
|
|
&i.Device,
|
|
|
|
&i.Os,
|
|
|
|
&i.Browser,
|
|
|
|
&i.Ip,
|
|
|
|
&i.Start,
|
|
|
|
&i.Utm,
|
|
|
|
)
|
|
|
|
return i, err
|
2024-02-19 16:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const insertPrivilege = `-- name: InsertPrivilege :exec
|
|
|
|
INSERT INTO privileges (privilegeID, account_id, privilege_name, amount, created_at) VALUES ($1, $2, $3, $4, $5)
|
|
|
|
`
|
|
|
|
|
|
|
|
type InsertPrivilegeParams struct {
|
|
|
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
|
|
|
AccountID uuid.NullUUID `db:"account_id" json:"account_id"`
|
|
|
|
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
|
|
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) InsertPrivilege(ctx context.Context, arg InsertPrivilegeParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, insertPrivilege,
|
|
|
|
arg.Privilegeid,
|
|
|
|
arg.AccountID,
|
|
|
|
arg.PrivilegeName,
|
|
|
|
arg.Amount,
|
|
|
|
arg.CreatedAt,
|
|
|
|
)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const insertQuestion = `-- name: InsertQuestion :one
|
|
|
|
INSERT INTO question (
|
|
|
|
quiz_id,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
questiontype,
|
|
|
|
required,
|
|
|
|
page,
|
|
|
|
content,
|
|
|
|
parent_ids,
|
|
|
|
updated_at
|
|
|
|
)
|
|
|
|
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)
|
|
|
|
RETURNING id, created_at, updated_at
|
|
|
|
`
|
|
|
|
|
|
|
|
type InsertQuestionParams struct {
|
|
|
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
|
|
|
Title string `db:"title" json:"title"`
|
|
|
|
Description sql.NullString `db:"description" json:"description"`
|
|
|
|
Questiontype interface{} `db:"questiontype" json:"questiontype"`
|
|
|
|
Required sql.NullBool `db:"required" json:"required"`
|
|
|
|
Page sql.NullInt16 `db:"page" json:"page"`
|
|
|
|
Content sql.NullString `db:"content" json:"content"`
|
|
|
|
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
|
|
|
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type InsertQuestionRow struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
|
|
|
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) InsertQuestion(ctx context.Context, arg InsertQuestionParams) (InsertQuestionRow, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, insertQuestion,
|
|
|
|
arg.QuizID,
|
|
|
|
arg.Title,
|
|
|
|
arg.Description,
|
|
|
|
arg.Questiontype,
|
|
|
|
arg.Required,
|
|
|
|
arg.Page,
|
|
|
|
arg.Content,
|
|
|
|
pq.Array(arg.ParentIds),
|
|
|
|
arg.UpdatedAt,
|
|
|
|
)
|
|
|
|
var i InsertQuestionRow
|
|
|
|
err := row.Scan(&i.ID, &i.CreatedAt, &i.UpdatedAt)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const insertQuiz = `-- name: InsertQuiz :one
|
|
|
|
INSERT INTO quiz (accountid,
|
|
|
|
fingerprinting,
|
|
|
|
repeatable,
|
|
|
|
note_prevented,
|
|
|
|
mail_notifications,
|
|
|
|
unique_answers,
|
|
|
|
super,
|
|
|
|
group_id,
|
|
|
|
name,
|
|
|
|
description,
|
|
|
|
config,
|
|
|
|
status,
|
|
|
|
limit_answers,
|
|
|
|
due_to,
|
|
|
|
time_of_passing,
|
|
|
|
pausable,
|
|
|
|
parent_ids,
|
|
|
|
questions_count,
|
|
|
|
qid
|
|
|
|
)
|
|
|
|
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19)
|
|
|
|
RETURNING id, created_at, updated_at, qid
|
|
|
|
`
|
|
|
|
|
|
|
|
type InsertQuizParams struct {
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
Fingerprinting sql.NullBool `db:"fingerprinting" json:"fingerprinting"`
|
|
|
|
Repeatable sql.NullBool `db:"repeatable" json:"repeatable"`
|
|
|
|
NotePrevented sql.NullBool `db:"note_prevented" json:"note_prevented"`
|
|
|
|
MailNotifications sql.NullBool `db:"mail_notifications" json:"mail_notifications"`
|
|
|
|
UniqueAnswers sql.NullBool `db:"unique_answers" json:"unique_answers"`
|
|
|
|
Super sql.NullBool `db:"super" json:"super"`
|
|
|
|
GroupID sql.NullInt64 `db:"group_id" json:"group_id"`
|
|
|
|
Name sql.NullString `db:"name" json:"name"`
|
|
|
|
Description sql.NullString `db:"description" json:"description"`
|
|
|
|
Config sql.NullString `db:"config" json:"config"`
|
|
|
|
Status interface{} `db:"status" json:"status"`
|
|
|
|
LimitAnswers sql.NullInt32 `db:"limit_answers" json:"limit_answers"`
|
|
|
|
DueTo sql.NullInt32 `db:"due_to" json:"due_to"`
|
|
|
|
TimeOfPassing sql.NullInt32 `db:"time_of_passing" json:"time_of_passing"`
|
|
|
|
Pausable sql.NullBool `db:"pausable" json:"pausable"`
|
|
|
|
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
|
|
|
QuestionsCount sql.NullInt32 `db:"questions_count" json:"questions_count"`
|
|
|
|
Qid uuid.NullUUID `db:"qid" json:"qid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type InsertQuizRow struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
|
|
|
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
|
|
|
Qid uuid.NullUUID `db:"qid" json:"qid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) InsertQuiz(ctx context.Context, arg InsertQuizParams) (InsertQuizRow, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, insertQuiz,
|
|
|
|
arg.Accountid,
|
|
|
|
arg.Fingerprinting,
|
|
|
|
arg.Repeatable,
|
|
|
|
arg.NotePrevented,
|
|
|
|
arg.MailNotifications,
|
|
|
|
arg.UniqueAnswers,
|
|
|
|
arg.Super,
|
|
|
|
arg.GroupID,
|
|
|
|
arg.Name,
|
|
|
|
arg.Description,
|
|
|
|
arg.Config,
|
|
|
|
arg.Status,
|
|
|
|
arg.LimitAnswers,
|
|
|
|
arg.DueTo,
|
|
|
|
arg.TimeOfPassing,
|
|
|
|
arg.Pausable,
|
|
|
|
pq.Array(arg.ParentIds),
|
|
|
|
arg.QuestionsCount,
|
|
|
|
arg.Qid,
|
|
|
|
)
|
|
|
|
var i InsertQuizRow
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.UpdatedAt,
|
|
|
|
&i.Qid,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const moveToHistory = `-- name: MoveToHistory :one
|
|
|
|
INSERT INTO question(
|
|
|
|
quiz_id, title, description, questiontype, required,
|
|
|
|
page, content, version, parent_ids, deleted
|
|
|
|
)
|
|
|
|
SELECT quiz_id, title, description, questiontype, required,
|
|
|
|
page, content, version, parent_ids, true as deleted
|
|
|
|
FROM question WHERE question.id=$1
|
|
|
|
RETURNING question.id, quiz_id, parent_ids
|
|
|
|
`
|
|
|
|
|
|
|
|
type MoveToHistoryRow struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
|
|
|
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) MoveToHistory(ctx context.Context, id int64) (MoveToHistoryRow, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, moveToHistory, id)
|
|
|
|
var i MoveToHistoryRow
|
|
|
|
err := row.Scan(&i.ID, &i.QuizID, pq.Array(&i.ParentIds))
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const moveToHistoryQuiz = `-- name: MoveToHistoryQuiz :one
|
|
|
|
INSERT INTO quiz(deleted,
|
|
|
|
accountid, archived,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,name,description,config,
|
|
|
|
status,limit_answers,due_to,time_of_passing,pausable,version,version_comment,parent_ids,questions_count,answers_count,average_time_passing, super, group_id
|
|
|
|
)
|
|
|
|
SELECT true as deleted, accountid, archived,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,name,description,config,
|
|
|
|
status,limit_answers,due_to,time_of_passing,pausable,version,version_comment,parent_ids,questions_count,answers_count,average_time_passing, super, group_id
|
|
|
|
FROM quiz WHERE quiz.id=$1 AND quiz.accountid=$2
|
|
|
|
RETURNING quiz.id, qid, parent_ids
|
|
|
|
`
|
|
|
|
|
|
|
|
type MoveToHistoryQuizParams struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type MoveToHistoryQuizRow struct {
|
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
Qid uuid.NullUUID `db:"qid" json:"qid"`
|
|
|
|
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) MoveToHistoryQuiz(ctx context.Context, arg MoveToHistoryQuizParams) (MoveToHistoryQuizRow, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, moveToHistoryQuiz, arg.ID, arg.Accountid)
|
|
|
|
var i MoveToHistoryQuizRow
|
|
|
|
err := row.Scan(&i.ID, &i.Qid, pq.Array(&i.ParentIds))
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
2024-03-17 14:55:20 +00:00
|
|
|
const questionsStatistics = `-- name: QuestionsStatistics :many
|
|
|
|
WITH Funnel AS (
|
|
|
|
SELECT
|
2024-03-17 15:25:46 +00:00
|
|
|
COUNT(DISTINCT a.session) FILTER (WHERE a.start = FALSE) AS count_start_false,
|
|
|
|
COUNT(DISTINCT a.session) FILTER (WHERE a.start = TRUE) AS count_start_true,
|
|
|
|
COUNT(DISTINCT CASE WHEN a.result = FALSE AND qid_true_result IS NOT NULL THEN a.session END) AS count_f_result_with_t_question,
|
|
|
|
COUNT(DISTINCT a.session) FILTER (WHERE a.result = TRUE) AS count_t_result
|
2024-03-17 14:55:20 +00:00
|
|
|
FROM
|
|
|
|
answer a
|
|
|
|
LEFT JOIN (
|
|
|
|
SELECT DISTINCT a.session, q.id AS qid_true_result
|
|
|
|
FROM answer a
|
|
|
|
JOIN question q ON a.question_id = q.id
|
|
|
|
WHERE a.result = TRUE
|
|
|
|
) AS q ON a.session = q.session
|
|
|
|
WHERE
|
|
|
|
a.quiz_id = $1
|
|
|
|
AND a.created_at >= TO_TIMESTAMP($2)
|
|
|
|
AND a.created_at <= TO_TIMESTAMP($3)
|
|
|
|
),
|
|
|
|
Results AS (
|
2024-03-17 19:21:12 +00:00
|
|
|
SELECT
|
2024-04-07 10:59:53 +00:00
|
|
|
COALESCE(q.title, '') AS question_title,
|
2024-03-17 19:21:12 +00:00
|
|
|
COUNT(*) AS total_answers,
|
2024-03-17 19:25:41 +00:00
|
|
|
CAST(COUNT(*) * 100.0 / NULLIF(SUM(COUNT(*)) FILTER (WHERE a.result = TRUE) OVER (PARTITION BY a.quiz_id), 0) AS FLOAT8) AS percentage
|
2024-03-17 19:21:12 +00:00
|
|
|
FROM
|
|
|
|
question q
|
|
|
|
JOIN answer a ON q.id = a.question_id
|
|
|
|
WHERE
|
|
|
|
a.quiz_id = $1
|
|
|
|
AND a.created_at >= TO_TIMESTAMP($2)
|
|
|
|
AND a.created_at <= TO_TIMESTAMP($3)
|
2024-03-17 19:28:28 +00:00
|
|
|
AND a.result = TRUE
|
2024-03-17 19:21:12 +00:00
|
|
|
GROUP BY
|
2024-03-17 19:23:30 +00:00
|
|
|
q.title, a.quiz_id, a.result
|
2024-03-17 19:21:12 +00:00
|
|
|
HAVING
|
|
|
|
COUNT(*) >= 1
|
|
|
|
),
|
2024-04-05 13:27:04 +00:00
|
|
|
LastContent AS (
|
|
|
|
SELECT
|
|
|
|
a.question_id,
|
|
|
|
a.content AS last_answer_content
|
|
|
|
FROM
|
|
|
|
answer a
|
|
|
|
JOIN (
|
|
|
|
SELECT
|
|
|
|
session,
|
|
|
|
question_id,
|
|
|
|
MAX(created_at) AS last_created_at
|
|
|
|
FROM
|
|
|
|
answer
|
|
|
|
WHERE
|
|
|
|
quiz_id = $1
|
2024-04-07 15:32:36 +00:00
|
|
|
AND start != true
|
2024-04-05 13:27:04 +00:00
|
|
|
AND created_at >= TO_TIMESTAMP($2)
|
|
|
|
AND created_at <= TO_TIMESTAMP($3)
|
|
|
|
GROUP BY
|
|
|
|
question_id, session
|
|
|
|
) AS last_created_at_one_session ON a.session = last_created_at_one_session.session AND a.question_id = last_created_at_one_session.question_id AND a.created_at = last_created_at_one_session.last_created_at
|
|
|
|
),
|
2024-03-17 14:55:20 +00:00
|
|
|
Questions AS (
|
2024-03-17 19:10:11 +00:00
|
|
|
SELECT
|
|
|
|
q.title AS question_title,
|
2024-04-08 18:28:39 +00:00
|
|
|
q.page AS question_page,
|
2024-04-05 13:27:04 +00:00
|
|
|
lc.last_answer_content AS answer_content,
|
2024-03-17 19:10:11 +00:00
|
|
|
CAST(
|
|
|
|
COUNT(CASE WHEN a.result = FALSE THEN 1 END) * 100.0 / NULLIF(SUM(COUNT(CASE WHEN a.result = FALSE THEN 1 END)) OVER (PARTITION BY q.id), 0) AS FLOAT8
|
|
|
|
) AS percentage
|
|
|
|
FROM
|
|
|
|
question q
|
2024-04-05 13:27:04 +00:00
|
|
|
JOIN LastContent lc ON q.id = lc.question_id
|
2024-03-17 19:10:11 +00:00
|
|
|
JOIN answer a ON q.id = a.question_id
|
|
|
|
WHERE
|
|
|
|
a.quiz_id = $1
|
2024-04-07 15:32:36 +00:00
|
|
|
AND a.start != true
|
2024-03-17 19:10:11 +00:00
|
|
|
AND a.created_at >= TO_TIMESTAMP($2)
|
|
|
|
AND a.created_at <= TO_TIMESTAMP($3)
|
|
|
|
GROUP BY
|
2024-04-05 13:27:04 +00:00
|
|
|
q.id, q.title, lc.last_answer_content
|
2024-03-17 19:10:11 +00:00
|
|
|
HAVING
|
|
|
|
COUNT(*) >= 1
|
2024-03-17 18:10:10 +00:00
|
|
|
)
|
2024-03-17 14:55:20 +00:00
|
|
|
SELECT
|
|
|
|
Funnel.count_start_false,
|
|
|
|
Funnel.count_start_true,
|
|
|
|
Funnel.count_f_result_with_t_question,
|
|
|
|
Funnel.count_t_result,
|
2024-04-07 10:59:53 +00:00
|
|
|
COALESCE(Results.question_title, '') AS results_title,
|
|
|
|
COALESCE(Results.percentage, 0) AS results_percentage,
|
|
|
|
COALESCE(Questions.question_title, '') AS questions_title,
|
2024-04-08 18:28:39 +00:00
|
|
|
COALESCE(Questions.question_page, 0) AS questions_page,
|
2024-04-07 10:59:53 +00:00
|
|
|
COALESCE(Questions.answer_content, '') AS answer_content,
|
|
|
|
COALESCE(Questions.percentage, 0) AS questions_percentage
|
2024-03-17 14:55:20 +00:00
|
|
|
FROM
|
2024-04-07 10:59:53 +00:00
|
|
|
Funnel
|
|
|
|
LEFT JOIN Results ON true
|
|
|
|
LEFT JOIN Questions ON Questions.percentage >= 1
|
2024-03-17 14:55:20 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type QuestionsStatisticsParams struct {
|
|
|
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
|
|
|
ToTimestamp float64 `db:"to_timestamp" json:"to_timestamp"`
|
|
|
|
ToTimestamp_2 float64 `db:"to_timestamp_2" json:"to_timestamp_2"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type QuestionsStatisticsRow struct {
|
2024-04-07 10:59:53 +00:00
|
|
|
CountStartFalse int64 `db:"count_start_false" json:"count_start_false"`
|
|
|
|
CountStartTrue int64 `db:"count_start_true" json:"count_start_true"`
|
|
|
|
CountFResultWithTQuestion int64 `db:"count_f_result_with_t_question" json:"count_f_result_with_t_question"`
|
|
|
|
CountTResult int64 `db:"count_t_result" json:"count_t_result"`
|
|
|
|
ResultsTitle string `db:"results_title" json:"results_title"`
|
|
|
|
ResultsPercentage float64 `db:"results_percentage" json:"results_percentage"`
|
|
|
|
QuestionsTitle string `db:"questions_title" json:"questions_title"`
|
|
|
|
QuestionsPage int16 `db:"questions_page" json:"questions_page"`
|
|
|
|
AnswerContent string `db:"answer_content" json:"answer_content"`
|
|
|
|
QuestionsPercentage float64 `db:"questions_percentage" json:"questions_percentage"`
|
2024-03-17 14:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) QuestionsStatistics(ctx context.Context, arg QuestionsStatisticsParams) ([]QuestionsStatisticsRow, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, questionsStatistics, arg.QuizID, arg.ToTimestamp, arg.ToTimestamp_2)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []QuestionsStatisticsRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i QuestionsStatisticsRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.CountStartFalse,
|
|
|
|
&i.CountStartTrue,
|
|
|
|
&i.CountFResultWithTQuestion,
|
|
|
|
&i.CountTResult,
|
2024-03-17 14:58:18 +00:00
|
|
|
&i.ResultsTitle,
|
2024-03-17 14:55:20 +00:00
|
|
|
&i.ResultsPercentage,
|
2024-03-17 14:58:18 +00:00
|
|
|
&i.QuestionsTitle,
|
2024-04-08 18:28:39 +00:00
|
|
|
&i.QuestionsPage,
|
2024-03-17 14:58:18 +00:00
|
|
|
&i.AnswerContent,
|
2024-03-17 14:55:20 +00:00
|
|
|
&i.QuestionsPercentage,
|
|
|
|
); 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
|
|
|
|
}
|
|
|
|
|
2024-03-19 16:13:03 +00:00
|
|
|
const quizCopyQid = `-- name: QuizCopyQid :one
|
|
|
|
INSERT INTO quiz (
|
|
|
|
accountid, archived, fingerprinting, repeatable, note_prevented, mail_notifications, unique_answers, name, description, config,
|
|
|
|
status, limit_answers, due_to, time_of_passing, pausable, version, version_comment, parent_ids, questions_count, answers_count, average_time_passing, super, group_id
|
|
|
|
)
|
|
|
|
SELECT
|
2024-03-28 22:23:08 +00:00
|
|
|
$2, archived, fingerprinting, repeatable, note_prevented, mail_notifications, unique_answers, name, description, config,
|
2024-03-19 16:13:03 +00:00
|
|
|
status, limit_answers, due_to, time_of_passing, pausable, version, version_comment, parent_ids, questions_count, answers_count, average_time_passing, super, group_id
|
|
|
|
FROM
|
2024-03-28 22:23:08 +00:00
|
|
|
quiz as q
|
2024-03-19 16:13:03 +00:00
|
|
|
WHERE
|
2024-03-28 22:23:08 +00:00
|
|
|
q.qid = $1
|
2024-03-29 08:37:16 +00:00
|
|
|
RETURNING (select id from quiz where qid = $1),id, qid
|
2024-03-19 16:13:03 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type QuizCopyQidParams struct {
|
|
|
|
Qid uuid.NullUUID `db:"qid" json:"qid"`
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type QuizCopyQidRow struct {
|
2024-03-28 23:51:52 +00:00
|
|
|
ID int64 `db:"id" json:"id"`
|
|
|
|
ID_2 int64 `db:"id_2" json:"id_2"`
|
|
|
|
Qid uuid.NullUUID `db:"qid" json:"qid"`
|
2024-03-19 16:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) QuizCopyQid(ctx context.Context, arg QuizCopyQidParams) (QuizCopyQidRow, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, quizCopyQid, arg.Qid, arg.Accountid)
|
|
|
|
var i QuizCopyQidRow
|
2024-03-28 23:51:52 +00:00
|
|
|
err := row.Scan(&i.ID, &i.ID_2, &i.Qid)
|
2024-03-19 16:13:03 +00:00
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
2024-06-04 15:53:06 +00:00
|
|
|
const setQuizSettings = `-- name: SetQuizSettings :one
|
2024-05-17 18:46:36 +00:00
|
|
|
INSERT INTO rules (AccountID, QuizID, PerformerID, PipelineID, StepID, FieldsRule)
|
2024-04-23 11:48:15 +00:00
|
|
|
SELECT u.AmoID AS AccountID,$1 AS QuizID,$2 AS PerformerID,$3 AS PipelineID,
|
2024-06-04 15:32:14 +00:00
|
|
|
$4 AS StepID,$5 AS FieldsRule FROM users u WHERE u.AccountID = $6 AND u.Deleted = false
|
2024-06-04 15:53:06 +00:00
|
|
|
RETURNING id
|
2024-04-23 11:48:15 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type SetQuizSettingsParams struct {
|
|
|
|
Quizid int32 `db:"quizid" json:"quizid"`
|
|
|
|
Performerid int32 `db:"performerid" json:"performerid"`
|
|
|
|
Pipelineid int32 `db:"pipelineid" json:"pipelineid"`
|
|
|
|
Stepid int32 `db:"stepid" json:"stepid"`
|
|
|
|
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
}
|
|
|
|
|
2024-06-04 15:53:06 +00:00
|
|
|
func (q *Queries) SetQuizSettings(ctx context.Context, arg SetQuizSettingsParams) (int64, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, setQuizSettings,
|
2024-04-23 11:48:15 +00:00
|
|
|
arg.Quizid,
|
|
|
|
arg.Performerid,
|
|
|
|
arg.Pipelineid,
|
|
|
|
arg.Stepid,
|
|
|
|
arg.Fieldsrule,
|
|
|
|
arg.Accountid,
|
|
|
|
)
|
2024-06-04 15:53:06 +00:00
|
|
|
var id int64
|
|
|
|
err := row.Scan(&id)
|
|
|
|
return id, err
|
2024-04-23 11:48:15 +00:00
|
|
|
}
|
|
|
|
|
2024-05-06 17:36:24 +00:00
|
|
|
const settingDealAmoStatus = `-- name: SettingDealAmoStatus :exec
|
2024-05-06 09:57:14 +00:00
|
|
|
INSERT INTO amoCRMStatuses (AccountID, DealID, AnswerID, Status)
|
|
|
|
SELECT u.AmoID, $1, $2, $3
|
|
|
|
FROM tokens AS t
|
|
|
|
JOIN users AS u ON t.AccountID = u.AccountID
|
|
|
|
WHERE t.AccessToken = $4
|
|
|
|
`
|
|
|
|
|
2024-05-06 17:36:24 +00:00
|
|
|
type SettingDealAmoStatusParams struct {
|
2024-05-06 09:57:14 +00:00
|
|
|
Dealid int32 `db:"dealid" json:"dealid"`
|
|
|
|
Answerid int64 `db:"answerid" json:"answerid"`
|
|
|
|
Status string `db:"status" json:"status"`
|
|
|
|
Accesstoken string `db:"accesstoken" json:"accesstoken"`
|
|
|
|
}
|
|
|
|
|
2024-05-06 17:36:24 +00:00
|
|
|
func (q *Queries) SettingDealAmoStatus(ctx context.Context, arg SettingDealAmoStatusParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, settingDealAmoStatus,
|
2024-05-06 09:57:14 +00:00
|
|
|
arg.Dealid,
|
|
|
|
arg.Answerid,
|
|
|
|
arg.Status,
|
|
|
|
arg.Accesstoken,
|
|
|
|
)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-04-17 17:18:52 +00:00
|
|
|
const softDeleteAccount = `-- name: SoftDeleteAccount :exec
|
2024-05-03 08:20:31 +00:00
|
|
|
WITH userd AS (
|
|
|
|
SELECT AmoUserID FROM users WHERE users.AccountID = $1
|
|
|
|
),
|
|
|
|
tokend AS (
|
2024-06-04 13:55:20 +00:00
|
|
|
UPDATE users SET Deleted = true WHERE AmoUserID IN (SELECT AmoUserID FROM userd)
|
2024-05-03 08:20:31 +00:00
|
|
|
)
|
2024-06-04 13:55:20 +00:00
|
|
|
DELETE FROM tokens WHERE tokens.AccountID = $1
|
2024-04-17 17:18:52 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) SoftDeleteAccount(ctx context.Context, accountid string) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, softDeleteAccount, accountid)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:33:15 +00:00
|
|
|
const softDeleteResultByID = `-- name: SoftDeleteResultByID :exec
|
|
|
|
UPDATE answer SET deleted = TRUE WHERE id = $1 AND deleted = FALSE
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) SoftDeleteResultByID(ctx context.Context, id int64) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, softDeleteResultByID, id)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-05-13 12:36:12 +00:00
|
|
|
const templateCopy = `-- name: TemplateCopy :one
|
2024-05-13 11:05:04 +00:00
|
|
|
WITH copied_quiz AS (
|
|
|
|
INSERT INTO quiz (accountid, name,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,super,group_id, description, config, status,limit_answers,due_to,time_of_passing,pausable,version,version_comment, parent_ids)
|
2024-05-13 12:30:37 +00:00
|
|
|
SELECT $1 AS accountid,name,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,super,group_id, description, config, 'stop' AS status,limit_answers,due_to,time_of_passing,pausable,version,version_comment, parent_ids
|
2024-05-13 11:05:04 +00:00
|
|
|
FROM quiz
|
2024-05-20 14:55:24 +00:00
|
|
|
WHERE qid = $2 and status = 'template'
|
2024-05-13 11:05:04 +00:00
|
|
|
RETURNING id
|
|
|
|
)
|
|
|
|
INSERT INTO question (quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids)
|
|
|
|
SELECT cq.id AS quiz_id, q.title, q.description, q.questiontype, q.required, q.deleted, q.page, q.content, q.version, q.parent_ids
|
|
|
|
FROM question q
|
|
|
|
JOIN quiz old ON q.quiz_id = old.id
|
|
|
|
JOIN copied_quiz cq ON old.qid = $2
|
2024-05-13 12:36:12 +00:00
|
|
|
RETURNING quiz_id
|
2024-05-13 11:05:04 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type TemplateCopyParams struct {
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
Qid uuid.NullUUID `db:"qid" json:"qid"`
|
|
|
|
}
|
|
|
|
|
2024-05-13 12:36:12 +00:00
|
|
|
func (q *Queries) TemplateCopy(ctx context.Context, arg TemplateCopyParams) (int64, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, templateCopy, arg.Accountid, arg.Qid)
|
|
|
|
var quiz_id int64
|
|
|
|
err := row.Scan(&quiz_id)
|
|
|
|
return quiz_id, err
|
2024-05-13 11:05:04 +00:00
|
|
|
}
|
|
|
|
|
2024-05-02 09:35:03 +00:00
|
|
|
const updateFieldRules = `-- name: UpdateFieldRules :exec
|
|
|
|
UPDATE rules SET FieldsRule = $1
|
|
|
|
WHERE AccountID = (SELECT AmoID FROM users WHERE users.AccountID = $2) AND QuizID = $3 AND Deleted = false
|
|
|
|
`
|
|
|
|
|
|
|
|
type UpdateFieldRulesParams struct {
|
|
|
|
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
|
|
|
Quizid int32 `db:"quizid" json:"quizid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) UpdateFieldRules(ctx context.Context, arg UpdateFieldRulesParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, updateFieldRules, arg.Fieldsrule, arg.Accountid, arg.Quizid)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-04-18 20:05:49 +00:00
|
|
|
const updateFields = `-- name: UpdateFields :exec
|
|
|
|
UPDATE fields AS f
|
2024-05-03 07:09:06 +00:00
|
|
|
SET name = (update_data ->> 'Name')::varchar(512),
|
2024-04-18 20:05:49 +00:00
|
|
|
code = (update_data ->> 'Code')::varchar(255),
|
2024-05-03 15:00:30 +00:00
|
|
|
type = (update_data ->> 'Type')::fieldtype
|
2024-04-18 20:05:49 +00:00
|
|
|
FROM json_array_elements($1::json) AS update_data
|
|
|
|
WHERE f.amoID = (update_data ->> 'AmoID')::INT
|
|
|
|
AND f.accountID = (update_data ->> 'AccountID')::INT
|
|
|
|
AND f.Entity = (update_data ->> 'Entity')::entitytype
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) UpdateFields(ctx context.Context, dollar_1 json.RawMessage) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, updateFields, dollar_1)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const updatePipelines = `-- name: UpdatePipelines :exec
|
|
|
|
UPDATE pipelines AS p
|
2024-05-03 07:09:06 +00:00
|
|
|
SET name = (update_data ->> 'Name')::varchar(512),
|
2024-05-03 15:00:30 +00:00
|
|
|
isArchive = CASE WHEN (update_data ->> 'IsArchive') = 'true' THEN TRUE ELSE FALSE END
|
2024-04-18 20:05:49 +00:00
|
|
|
FROM json_array_elements($1::json) AS update_data
|
|
|
|
WHERE p.amoID = (update_data ->> 'AmoID')::INT
|
|
|
|
AND p.accountID = (update_data ->> 'AccountID')::INT
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) UpdatePipelines(ctx context.Context, dollar_1 json.RawMessage) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, updatePipelines, dollar_1)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:33:15 +00:00
|
|
|
const updatePrivilege = `-- name: UpdatePrivilege :exec
|
|
|
|
UPDATE privileges SET amount = $1, created_at = $2 WHERE account_id = $3 AND privilegeID = $4
|
|
|
|
`
|
|
|
|
|
|
|
|
type UpdatePrivilegeParams struct {
|
|
|
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
|
|
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
|
|
|
AccountID uuid.NullUUID `db:"account_id" json:"account_id"`
|
|
|
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) UpdatePrivilege(ctx context.Context, arg UpdatePrivilegeParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, updatePrivilege,
|
|
|
|
arg.Amount,
|
|
|
|
arg.CreatedAt,
|
|
|
|
arg.AccountID,
|
|
|
|
arg.Privilegeid,
|
|
|
|
)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const updatePrivilegeAmount = `-- name: UpdatePrivilegeAmount :exec
|
|
|
|
UPDATE privileges SET amount = $1 WHERE id = $2
|
|
|
|
`
|
|
|
|
|
|
|
|
type UpdatePrivilegeAmountParams struct {
|
|
|
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
|
|
|
ID int32 `db:"id" json:"id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) UpdatePrivilegeAmount(ctx context.Context, arg UpdatePrivilegeAmountParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, updatePrivilegeAmount, arg.Amount, arg.ID)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-04-18 20:05:49 +00:00
|
|
|
const updateSteps = `-- name: UpdateSteps :exec
|
|
|
|
UPDATE steps AS s
|
2024-05-03 07:09:06 +00:00
|
|
|
SET name = (update_data ->> 'Name')::varchar(512),
|
2024-05-03 15:00:30 +00:00
|
|
|
color = (update_data ->> 'Color')::varchar(50)
|
2024-04-18 20:05:49 +00:00
|
|
|
FROM json_array_elements($1::json) AS update_data
|
|
|
|
WHERE s.amoID = (update_data ->> 'AmoID')::INT
|
|
|
|
AND s.accountID = (update_data ->> 'AccountID')::INT
|
|
|
|
AND s.pipelineID = (update_data ->> 'PipelineID')::INT
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) UpdateSteps(ctx context.Context, dollar_1 json.RawMessage) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, updateSteps, dollar_1)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const updateTags = `-- name: UpdateTags :exec
|
|
|
|
UPDATE tags AS t
|
2024-05-03 07:09:06 +00:00
|
|
|
SET name = (update_data ->> 'Name')::varchar(512),
|
2024-05-03 15:00:30 +00:00
|
|
|
color = (update_data ->> 'Color')::varchar(50)
|
2024-04-18 20:05:49 +00:00
|
|
|
FROM json_array_elements($1::json) AS update_data
|
|
|
|
WHERE t.amoID = (update_data ->> 'AmoID')::INT
|
|
|
|
AND t.accountID = (update_data ->> 'AccountID')::INT
|
|
|
|
AND t.Entity = (update_data ->> 'Entity')::entitytype
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) UpdateTags(ctx context.Context, dollar_1 json.RawMessage) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, updateTags, dollar_1)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-04-20 09:01:25 +00:00
|
|
|
const updateUsers = `-- name: UpdateUsers :exec
|
2024-05-03 15:00:30 +00:00
|
|
|
UPDATE users AS u
|
|
|
|
SET Name = (update_data ->> 'Name')::varchar(512),
|
|
|
|
Email = (update_data ->> 'Email')::varchar(50),
|
|
|
|
Role = (update_data ->> 'Role')::INT,
|
|
|
|
"Group" = (update_data ->> 'Group')::INT,
|
|
|
|
AmoUserID= (update_data ->> 'AmoUserID')::INT
|
|
|
|
FROM json_array_elements($1::json) AS update_data
|
|
|
|
WHERE u.AmoID = (update_data ->> 'AmocrmID')::INT
|
2024-04-20 09:01:25 +00:00
|
|
|
`
|
|
|
|
|
2024-05-03 15:00:30 +00:00
|
|
|
func (q *Queries) UpdateUsers(ctx context.Context, dollar_1 json.RawMessage) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, updateUsers, dollar_1)
|
2024-04-20 09:01:25 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-05-06 17:36:24 +00:00
|
|
|
const updatingDealAmoStatus = `-- name: UpdatingDealAmoStatus :exec
|
|
|
|
UPDATE amoCRMStatuses SET Status = $1
|
2024-05-06 20:07:10 +00:00
|
|
|
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)
|
2024-05-06 17:36:24 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
type UpdatingDealAmoStatusParams struct {
|
|
|
|
Status string `db:"status" json:"status"`
|
2024-05-06 17:45:19 +00:00
|
|
|
Dealid int32 `db:"dealid" json:"dealid"`
|
2024-05-06 18:40:34 +00:00
|
|
|
Accesstoken string `db:"accesstoken" json:"accesstoken"`
|
2024-05-06 17:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) UpdatingDealAmoStatus(ctx context.Context, arg UpdatingDealAmoStatusParams) error {
|
2024-05-06 18:40:34 +00:00
|
|
|
_, err := q.db.ExecContext(ctx, updatingDealAmoStatus, arg.Status, arg.Dealid, arg.Accesstoken)
|
2024-05-06 17:36:24 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-04-17 17:18:52 +00:00
|
|
|
const webhookDelete = `-- name: WebhookDelete :exec
|
2024-04-23 15:04:31 +00:00
|
|
|
WITH userd AS (
|
|
|
|
UPDATE users SET Deleted = true WHERE AmoUserID = $1 RETURNING AccountID
|
|
|
|
)
|
2024-05-03 08:20:31 +00:00
|
|
|
DELETE FROM tokens WHERE AccountID IN (SELECT AccountID FROM userd)
|
2024-04-17 17:18:52 +00:00
|
|
|
`
|
|
|
|
|
2024-04-23 15:04:31 +00:00
|
|
|
func (q *Queries) WebhookDelete(ctx context.Context, amouserid int32) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, webhookDelete, amouserid)
|
2024-04-17 17:18:52 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const webhookUpdate = `-- name: WebhookUpdate :exec
|
2024-05-06 11:06:55 +00:00
|
|
|
UPDATE tokens SET AccessToken = $1,RefreshToken = $2,Expiration = to_timestamp(($3)::bigint) AT TIME ZONE 'UTC' + INTERVAL '3 hours',CreatedAt = to_timestamp(($4)::bigint) AT TIME ZONE 'UTC' + INTERVAL '3 hours'
|
2024-05-06 11:00:28 +00:00
|
|
|
WHERE accountID = $5
|
2024-04-17 17:18:52 +00:00
|
|
|
`
|
|
|
|
|
2024-05-06 11:00:28 +00:00
|
|
|
type WebhookUpdateParams struct {
|
2024-05-06 11:06:55 +00:00
|
|
|
Accesstoken string `db:"accesstoken" json:"accesstoken"`
|
|
|
|
Refreshtoken string `db:"refreshtoken" json:"refreshtoken"`
|
|
|
|
Column3 int64 `db:"column_3" json:"column_3"`
|
|
|
|
Column4 int64 `db:"column_4" json:"column_4"`
|
|
|
|
Accountid string `db:"accountid" json:"accountid"`
|
2024-05-06 11:00:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) WebhookUpdate(ctx context.Context, arg WebhookUpdateParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, webhookUpdate,
|
|
|
|
arg.Accesstoken,
|
|
|
|
arg.Refreshtoken,
|
2024-05-06 11:06:55 +00:00
|
|
|
arg.Column3,
|
|
|
|
arg.Column4,
|
2024-05-06 11:00:28 +00:00
|
|
|
arg.Accountid,
|
|
|
|
)
|
2024-04-17 17:18:52 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:33:15 +00:00
|
|
|
const workerStatProcess = `-- name: WorkerStatProcess :exec
|
|
|
|
WITH answer_aggregates AS (
|
|
|
|
SELECT
|
|
|
|
quiz_id,
|
|
|
|
COUNT(DISTINCT session) AS unique_true_answers_count
|
|
|
|
FROM
|
|
|
|
answer
|
|
|
|
WHERE
|
|
|
|
result = TRUE
|
|
|
|
GROUP BY
|
|
|
|
quiz_id
|
|
|
|
),
|
|
|
|
question_aggregates AS (
|
|
|
|
SELECT
|
|
|
|
q.id AS quiz_id,
|
|
|
|
COUNT(qs.id) AS total_questions
|
|
|
|
FROM
|
|
|
|
quiz q
|
|
|
|
INNER JOIN
|
|
|
|
question qs ON q.id = qs.quiz_id
|
|
|
|
WHERE
|
|
|
|
q.deleted = false
|
|
|
|
AND q.archived = false
|
|
|
|
AND qs.deleted = false
|
|
|
|
GROUP BY
|
|
|
|
q.id
|
|
|
|
),
|
|
|
|
session_times_aggregates AS (
|
|
|
|
SELECT
|
|
|
|
quiz_id, COUNT(session) as sess,
|
|
|
|
AVG(extract(epoch FROM session_time)) AS average_session_time
|
|
|
|
FROM (
|
|
|
|
SELECT
|
|
|
|
quiz_id,
|
|
|
|
session,
|
|
|
|
(MAX(created_at) - MIN(created_at)) AS session_time
|
|
|
|
FROM
|
|
|
|
answer
|
|
|
|
GROUP BY
|
|
|
|
quiz_id,
|
|
|
|
session
|
|
|
|
) AS all_sessions
|
|
|
|
GROUP BY
|
|
|
|
quiz_id
|
|
|
|
)
|
|
|
|
UPDATE quiz q
|
|
|
|
SET
|
|
|
|
questions_count = COALESCE(qa.total_questions, 0),
|
|
|
|
answers_count = COALESCE(aa.unique_true_answers_count, 0),
|
|
|
|
average_time_passing = COALESCE(sta.average_session_time, 0),
|
|
|
|
sessions_count = COALESCE(sta.sess,0)
|
|
|
|
FROM
|
|
|
|
(SELECT id, qid, accountid, deleted, archived, fingerprinting, repeatable, note_prevented, mail_notifications, unique_answers, super, group_id, name, description, config, status, limit_answers, due_to, time_of_passing, pausable, version, version_comment, parent_ids, created_at, updated_at, questions_count, answers_count, average_time_passing, sessions_count FROM quiz WHERE deleted = FALSE AND archived = FALSE) q_sub
|
|
|
|
LEFT JOIN answer_aggregates aa ON q_sub.id = aa.quiz_id
|
|
|
|
LEFT JOIN question_aggregates qa ON q_sub.id = qa.quiz_id
|
|
|
|
LEFT JOIN session_times_aggregates sta ON q_sub.id = sta.quiz_id
|
|
|
|
WHERE
|
|
|
|
q.id = q_sub.id
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) WorkerStatProcess(ctx context.Context) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, workerStatProcess)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const workerTimeoutProcess = `-- name: WorkerTimeoutProcess :exec
|
|
|
|
UPDATE quiz SET status = 'timeout' WHERE deleted = false AND due_to <> 0 AND due_to < EXTRACT(epoch FROM CURRENT_TIMESTAMP)
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) WorkerTimeoutProcess(ctx context.Context) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, workerTimeoutProcess)
|
|
|
|
return err
|
|
|
|
}
|