update sqlc gen
This commit is contained in:
parent
c2b5e87d2f
commit
92b755fde5
@ -705,7 +705,7 @@ SELECT * FROM tokens WHERE Expiration <= TO_TIMESTAMP(EXTRACT(EPOCH FROM NOW())
|
|||||||
|
|
||||||
-- name: WebhookDelete :exec
|
-- name: WebhookDelete :exec
|
||||||
WITH companyDel AS (
|
WITH companyDel AS (
|
||||||
UPDATE accountsAmo SET Deleted = true WHERE AmoID = $1 RETURNING AccountID
|
UPDATE accountsAmo SET Deleted = true WHERE accountsAmo.AmoID = $1 RETURNING AccountID
|
||||||
),
|
),
|
||||||
userDel AS (
|
userDel AS (
|
||||||
UPDATE usersAmo SET Deleted = true WHERE AmoID = $1
|
UPDATE usersAmo SET Deleted = true WHERE AmoID = $1
|
||||||
@ -726,7 +726,7 @@ DELETE FROM tokens WHERE tokens.AccountID = $1;
|
|||||||
SELECT * FROM accountsAmo WHERE AccountID = $1 AND Deleted = false;
|
SELECT * FROM accountsAmo WHERE AccountID = $1 AND Deleted = false;
|
||||||
|
|
||||||
-- name: GetAllCompanyUsers :many
|
-- name: GetAllCompanyUsers :many
|
||||||
SELECT * FROM usersamo WHERE amoid = $2 AND deleted = false;
|
SELECT * FROM usersamo WHERE amoid = $1 AND deleted = false;
|
||||||
|
|
||||||
-- name: GetUsersWithPagination :many
|
-- name: GetUsersWithPagination :many
|
||||||
WITH user_data AS (
|
WITH user_data AS (
|
||||||
@ -1041,4 +1041,4 @@ WHERE AccountID = $1 AND Deleted = false;
|
|||||||
-- name: DecrementManual :one
|
-- name: DecrementManual :one
|
||||||
UPDATE privileges p SET amount = amount - 1 FROM account a
|
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
|
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;;
|
RETURNING p.id, p.privilegeID, p.account_id, p.privilege_name, p.amount, p.created_at;
|
||||||
|
@ -20,6 +20,18 @@ type Account struct {
|
|||||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Accountsamo struct {
|
||||||
|
ID int64 `db:"id" json:"id"`
|
||||||
|
Accountid string `db:"accountid" json:"accountid"`
|
||||||
|
Amoid int32 `db:"amoid" json:"amoid"`
|
||||||
|
Name string `db:"name" json:"name"`
|
||||||
|
Deleted bool `db:"deleted" json:"deleted"`
|
||||||
|
Createdat time.Time `db:"createdat" json:"createdat"`
|
||||||
|
Subdomain string `db:"subdomain" json:"subdomain"`
|
||||||
|
Country string `db:"country" json:"country"`
|
||||||
|
Driveurl sql.NullString `db:"driveurl" json:"driveurl"`
|
||||||
|
}
|
||||||
|
|
||||||
type Amocrmstatus struct {
|
type Amocrmstatus struct {
|
||||||
ID int64 `db:"id" json:"id"`
|
ID int64 `db:"id" json:"id"`
|
||||||
Accountid int32 `db:"accountid" json:"accountid"`
|
Accountid int32 `db:"accountid" json:"accountid"`
|
||||||
@ -173,18 +185,14 @@ type Token struct {
|
|||||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type Usersamo struct {
|
||||||
ID int64 `db:"id" json:"id"`
|
ID int64 `db:"id" json:"id"`
|
||||||
Accountid string `db:"accountid" json:"accountid"`
|
|
||||||
Amoid int32 `db:"amoid" json:"amoid"`
|
Amoid int32 `db:"amoid" json:"amoid"`
|
||||||
|
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
||||||
Name string `db:"name" json:"name"`
|
Name string `db:"name" json:"name"`
|
||||||
Email string `db:"email" json:"email"`
|
Email string `db:"email" json:"email"`
|
||||||
Role int32 `db:"role" json:"role"`
|
Role int32 `db:"role" json:"role"`
|
||||||
Group int32 `db:"Group" json:"Group"`
|
Group int32 `db:"Group" json:"Group"`
|
||||||
Deleted bool `db:"deleted" json:"deleted"`
|
Deleted bool `db:"deleted" json:"deleted"`
|
||||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
Createdat time.Time `db:"createdat" json:"createdat"`
|
||||||
Subdomain string `db:"subdomain" json:"subdomain"`
|
|
||||||
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
|
||||||
Country string `db:"country" json:"country"`
|
|
||||||
Driveurl string `db:"driveurl" json:"driveurl"`
|
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,36 @@ func (q *Queries) AccountPagination(ctx context.Context, arg AccountPaginationPa
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const addAmoAccountUser = `-- name: AddAmoAccountUser :exec
|
||||||
|
INSERT INTO usersAmo (AmoID, AmoUserID, Name, Email, Role, "Group", Deleted, CreatedAt)
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||||
|
`
|
||||||
|
|
||||||
|
type AddAmoAccountUserParams struct {
|
||||||
|
Amoid int32 `db:"amoid" json:"amoid"`
|
||||||
|
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
||||||
|
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 time.Time `db:"createdat" json:"createdat"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) AddAmoAccountUser(ctx context.Context, arg AddAmoAccountUserParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, addAmoAccountUser,
|
||||||
|
arg.Amoid,
|
||||||
|
arg.Amouserid,
|
||||||
|
arg.Name,
|
||||||
|
arg.Email,
|
||||||
|
arg.Role,
|
||||||
|
arg.Group,
|
||||||
|
arg.Deleted,
|
||||||
|
arg.Createdat,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const allServiceStatistics = `-- name: AllServiceStatistics :one
|
const allServiceStatistics = `-- name: AllServiceStatistics :one
|
||||||
WITH Registrations AS (
|
WITH Registrations AS (
|
||||||
SELECT COUNT(*) AS registration_count
|
SELECT COUNT(*) AS registration_count
|
||||||
@ -117,7 +147,7 @@ func (q *Queries) ArchiveQuiz(ctx context.Context, arg ArchiveQuizParams) error
|
|||||||
const changeQuizSettings = `-- name: ChangeQuizSettings :one
|
const changeQuizSettings = `-- name: ChangeQuizSettings :one
|
||||||
UPDATE rules
|
UPDATE rules
|
||||||
SET PerformerID = $1,PipelineID = $2,StepID = $3,FieldsRule = $4, TagsToAdd=$5
|
SET PerformerID = $1,PipelineID = $2,StepID = $3,FieldsRule = $4, TagsToAdd=$5
|
||||||
WHERE AccountID = (SELECT AmoID FROM users WHERE users.AccountID = $6 AND users.Deleted = false) AND QuizID = $7 AND Deleted = false
|
WHERE AccountID = (SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $6 AND accountsAmo.Deleted = false) AND QuizID = $7 AND Deleted = false
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -200,9 +230,7 @@ func (q *Queries) CheckExpired(ctx context.Context) ([]Token, error) {
|
|||||||
|
|
||||||
const checkFields = `-- name: CheckFields :many
|
const checkFields = `-- name: CheckFields :many
|
||||||
WITH user_data AS (
|
WITH user_data AS (
|
||||||
SELECT AmoID
|
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false
|
||||||
FROM users
|
|
||||||
WHERE users.AccountID = $1
|
|
||||||
), new_fields AS (
|
), new_fields AS (
|
||||||
SELECT (field->>'AmoID')::INT AS amoID,
|
SELECT (field->>'AmoID')::INT AS amoID,
|
||||||
COALESCE(field->>'Code', '')::varchar(255) AS code,
|
COALESCE(field->>'Code', '')::varchar(255) AS code,
|
||||||
@ -282,29 +310,6 @@ func (q *Queries) CheckFields(ctx context.Context, arg CheckFieldsParams) ([]Che
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
const checkPipelines = `-- name: CheckPipelines :many
|
const checkPipelines = `-- name: CheckPipelines :many
|
||||||
WITH new_pipelines AS (
|
WITH new_pipelines AS (
|
||||||
SELECT (pipeline->>'AmoID')::INT AS amoID,
|
SELECT (pipeline->>'AmoID')::INT AS amoID,
|
||||||
@ -487,9 +492,7 @@ func (q *Queries) CheckSteps(ctx context.Context, dollar_1 json.RawMessage) ([]C
|
|||||||
|
|
||||||
const checkTags = `-- name: CheckTags :many
|
const checkTags = `-- name: CheckTags :many
|
||||||
WITH user_data AS (
|
WITH user_data AS (
|
||||||
SELECT AmoID
|
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false
|
||||||
FROM users
|
|
||||||
WHERE users.AccountID = $1
|
|
||||||
), new_tags AS (
|
), new_tags AS (
|
||||||
SELECT (tag->>'AmoID')::INT AS amoID,
|
SELECT (tag->>'AmoID')::INT AS amoID,
|
||||||
(tag->>'Entity')::entitytype AS Entity,
|
(tag->>'Entity')::entitytype AS Entity,
|
||||||
@ -562,79 +565,6 @@ func (q *Queries) CheckTags(ctx context.Context, arg CheckTagsParams) ([]CheckTa
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
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, driveurl
|
|
||||||
)
|
|
||||||
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, driveurl
|
|
||||||
FROM inserted_users ins
|
|
||||||
WHERE ins.amoID = nu.amoID
|
|
||||||
)
|
|
||||||
`
|
|
||||||
|
|
||||||
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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
const copyQuestion = `-- name: CopyQuestion :one
|
const copyQuestion = `-- name: CopyQuestion :one
|
||||||
INSERT INTO question(
|
INSERT INTO question(
|
||||||
quiz_id, title, description, questiontype, required,
|
quiz_id, title, description, questiontype, required,
|
||||||
@ -780,23 +710,17 @@ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (A
|
|||||||
|
|
||||||
const createAmoAccount = `-- name: CreateAmoAccount :exec
|
const createAmoAccount = `-- name: CreateAmoAccount :exec
|
||||||
|
|
||||||
INSERT INTO users (AccountID, AmoID, Name, Email, Role, "Group", Deleted, CreatedAt, Subdomain, AmoUserID, Country,DriveURL)
|
INSERT INTO accountsAmo (AccountID, AmoID,Name, Subdomain, Country,DriveURL)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
`
|
`
|
||||||
|
|
||||||
type CreateAmoAccountParams struct {
|
type CreateAmoAccountParams struct {
|
||||||
Accountid string `db:"accountid" json:"accountid"`
|
Accountid string `db:"accountid" json:"accountid"`
|
||||||
Amoid int32 `db:"amoid" json:"amoid"`
|
Amoid int32 `db:"amoid" json:"amoid"`
|
||||||
Name string `db:"name" json:"name"`
|
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"`
|
Subdomain string `db:"subdomain" json:"subdomain"`
|
||||||
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
|
||||||
Country string `db:"country" json:"country"`
|
Country string `db:"country" json:"country"`
|
||||||
Driveurl string `db:"driveurl" json:"driveurl"`
|
Driveurl sql.NullString `db:"driveurl" json:"driveurl"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// amo methods:
|
// amo methods:
|
||||||
@ -805,13 +729,7 @@ func (q *Queries) CreateAmoAccount(ctx context.Context, arg CreateAmoAccountPara
|
|||||||
arg.Accountid,
|
arg.Accountid,
|
||||||
arg.Amoid,
|
arg.Amoid,
|
||||||
arg.Name,
|
arg.Name,
|
||||||
arg.Email,
|
|
||||||
arg.Role,
|
|
||||||
arg.Group,
|
|
||||||
arg.Deleted,
|
|
||||||
arg.Createdat,
|
|
||||||
arg.Subdomain,
|
arg.Subdomain,
|
||||||
arg.Amouserid,
|
|
||||||
arg.Country,
|
arg.Country,
|
||||||
arg.Driveurl,
|
arg.Driveurl,
|
||||||
)
|
)
|
||||||
@ -1004,7 +922,7 @@ func (q *Queries) DeleteTags(ctx context.Context, dollar_1 []int64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const deleteUsers = `-- name: DeleteUsers :exec
|
const deleteUsers = `-- name: DeleteUsers :exec
|
||||||
UPDATE users SET Deleted = true WHERE ID = ANY($1::bigint[])
|
UPDATE usersAmo SET Deleted = true WHERE ID = ANY($1::bigint[])
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) DeleteUsers(ctx context.Context, dollar_1 []int64) error {
|
func (q *Queries) DeleteUsers(ctx context.Context, dollar_1 []int64) error {
|
||||||
@ -1459,6 +1377,43 @@ func (q *Queries) GetAllAnswersByQuizID(ctx context.Context, session sql.NullStr
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getAllCompanyUsers = `-- name: GetAllCompanyUsers :many
|
||||||
|
SELECT id, amoid, amouserid, name, email, role, "Group", deleted, createdat FROM usersamo WHERE amoid = $1 AND deleted = false
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetAllCompanyUsers(ctx context.Context, amoid int32) ([]Usersamo, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, getAllCompanyUsers, amoid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []Usersamo
|
||||||
|
for rows.Next() {
|
||||||
|
var i Usersamo
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Amoid,
|
||||||
|
&i.Amouserid,
|
||||||
|
&i.Name,
|
||||||
|
&i.Email,
|
||||||
|
&i.Role,
|
||||||
|
&i.Group,
|
||||||
|
&i.Deleted,
|
||||||
|
&i.Createdat,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
const getAllTokens = `-- name: GetAllTokens :many
|
const getAllTokens = `-- name: GetAllTokens :many
|
||||||
SELECT accountid, refreshtoken, accesstoken, authcode, expiration, createdat FROM tokens
|
SELECT accountid, refreshtoken, accesstoken, authcode, expiration, createdat FROM tokens
|
||||||
`
|
`
|
||||||
@ -1493,25 +1448,21 @@ func (q *Queries) GetAllTokens(ctx context.Context) ([]Token, error) {
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const getCurrentAccount = `-- name: GetCurrentAccount :one
|
const getCurrentCompany = `-- name: GetCurrentCompany :one
|
||||||
SELECT id, accountid, amoid, name, email, role, "Group", deleted, createdat, subdomain, amouserid, country, driveurl FROM users WHERE AccountID = $1 AND Deleted = false
|
SELECT id, accountid, amoid, name, deleted, createdat, subdomain, country, driveurl FROM accountsAmo WHERE AccountID = $1 AND Deleted = false
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetCurrentAccount(ctx context.Context, accountid string) (User, error) {
|
func (q *Queries) GetCurrentCompany(ctx context.Context, accountid string) (Accountsamo, error) {
|
||||||
row := q.db.QueryRowContext(ctx, getCurrentAccount, accountid)
|
row := q.db.QueryRowContext(ctx, getCurrentCompany, accountid)
|
||||||
var i User
|
var i Accountsamo
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Accountid,
|
&i.Accountid,
|
||||||
&i.Amoid,
|
&i.Amoid,
|
||||||
&i.Name,
|
&i.Name,
|
||||||
&i.Email,
|
|
||||||
&i.Role,
|
|
||||||
&i.Group,
|
|
||||||
&i.Deleted,
|
&i.Deleted,
|
||||||
&i.Createdat,
|
&i.Createdat,
|
||||||
&i.Subdomain,
|
&i.Subdomain,
|
||||||
&i.Amouserid,
|
|
||||||
&i.Country,
|
&i.Country,
|
||||||
&i.Driveurl,
|
&i.Driveurl,
|
||||||
)
|
)
|
||||||
@ -1634,8 +1585,11 @@ func (q *Queries) GetFieldByAmoID(ctx context.Context, amoid int32) (Field, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getFieldsWithPagination = `-- name: GetFieldsWithPagination :many
|
const getFieldsWithPagination = `-- name: GetFieldsWithPagination :many
|
||||||
|
WITH user_data AS (
|
||||||
|
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false
|
||||||
|
)
|
||||||
SELECT f.id, f.amoid, f.code, f.accountid, f.name, f.entity, f.type, f.deleted, f.createdat, COUNT(*) OVER() as total_count
|
SELECT f.id, f.amoid, f.code, f.accountid, f.name, f.entity, f.type, f.deleted, f.createdat, COUNT(*) OVER() as total_count
|
||||||
FROM fields f JOIN (SELECT AmoID FROM users WHERE users.AccountID = $1 AND Deleted = false) u ON f.AccountID = u.AmoID
|
FROM fields f JOIN user_data u ON f.AccountID = u.AmoID
|
||||||
WHERE f.Deleted = false
|
WHERE f.Deleted = false
|
||||||
ORDER BY f.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
ORDER BY f.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
||||||
`
|
`
|
||||||
@ -1750,8 +1704,11 @@ func (q *Queries) GetListStartQuiz(ctx context.Context, accountid string) ([]int
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getPipelinesWithPagination = `-- name: GetPipelinesWithPagination :many
|
const getPipelinesWithPagination = `-- name: GetPipelinesWithPagination :many
|
||||||
|
WITH user_data AS (
|
||||||
|
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false
|
||||||
|
)
|
||||||
SELECT p.id, p.amoid, p.accountid, p.name, p.isarchive, p.deleted, p.createdat, COUNT(*) OVER() as total_count
|
SELECT p.id, p.amoid, p.accountid, p.name, p.isarchive, p.deleted, p.createdat, COUNT(*) OVER() as total_count
|
||||||
FROM pipelines p JOIN (SELECT AmoID FROM users WHERE users.AccountID = $1 AND Deleted = false) u ON p.AccountID = u.AmoID
|
FROM pipelines p JOIN user_data u ON p.AccountID = u.AmoID
|
||||||
WHERE p.Deleted = false
|
WHERE p.Deleted = false
|
||||||
ORDER BY p.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
ORDER BY p.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
||||||
`
|
`
|
||||||
@ -2368,8 +2325,11 @@ func (q *Queries) GetResultAnswers(ctx context.Context, id int64) ([]GetResultAn
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getStepsWithPagination = `-- name: GetStepsWithPagination :many
|
const getStepsWithPagination = `-- name: GetStepsWithPagination :many
|
||||||
|
WITH user_data AS (
|
||||||
|
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false
|
||||||
|
)
|
||||||
SELECT s.id, s.amoid, s.pipelineid, s.accountid, s.name, s.color, s.deleted, s.createdat, COUNT(*) OVER() as total_count
|
SELECT s.id, s.amoid, s.pipelineid, s.accountid, s.name, s.color, s.deleted, s.createdat, COUNT(*) OVER() as total_count
|
||||||
FROM steps s JOIN (SELECT AmoID FROM users WHERE users.AccountID = $1 AND Deleted = false) u ON s.AccountID = u.AmoID
|
FROM steps s JOIN user_data u ON s.AccountID = u.AmoID
|
||||||
WHERE s.Deleted = false AND PipelineID = $4
|
WHERE s.Deleted = false AND PipelineID = $4
|
||||||
ORDER BY s.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
ORDER BY s.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
||||||
`
|
`
|
||||||
@ -2432,8 +2392,11 @@ func (q *Queries) GetStepsWithPagination(ctx context.Context, arg GetStepsWithPa
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getTagsWithPagination = `-- name: GetTagsWithPagination :many
|
const getTagsWithPagination = `-- name: GetTagsWithPagination :many
|
||||||
|
WITH user_data AS (
|
||||||
|
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false
|
||||||
|
)
|
||||||
SELECT t.id, t.amoid, t.accountid, t.entity, t.name, t.color, t.deleted, t.createdat, COUNT(*) OVER() as total_count
|
SELECT t.id, t.amoid, t.accountid, t.entity, t.name, t.color, t.deleted, t.createdat, COUNT(*) OVER() as total_count
|
||||||
FROM tags t JOIN (SELECT AmoID FROM users WHERE users.AccountID = $1 AND Deleted = false) u ON t.AccountID = u.AmoID
|
FROM tags t JOIN user_data u ON t.AccountID = u.AmoID
|
||||||
WHERE t.Deleted = false
|
WHERE t.Deleted = false
|
||||||
ORDER BY t.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
ORDER BY t.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
||||||
`
|
`
|
||||||
@ -2688,44 +2651,28 @@ func (q *Queries) GetUserTagsByID(ctx context.Context, accountid int32) ([]GetUs
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getUserUsersByID = `-- name: GetUserUsersByID :many
|
const getUserUsersByID = `-- name: GetUserUsersByID :many
|
||||||
SELECT ID,AccountID,AmoID,Name,Email,Role,"Group",Subdomain,AmoUserID,Country
|
SELECT id, amoid, amouserid, name, email, role, "Group", deleted, createdat FROM usersAmo WHERE amoid = $1 AND Deleted = false
|
||||||
FROM users
|
|
||||||
WHERE AmoUserID = $1 AND Deleted = false
|
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetUserUsersByIDRow struct {
|
func (q *Queries) GetUserUsersByID(ctx context.Context, amoid int32) ([]Usersamo, error) {
|
||||||
ID int64 `db:"id" json:"id"`
|
rows, err := q.db.QueryContext(ctx, getUserUsersByID, amoid)
|
||||||
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"`
|
|
||||||
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
var items []GetUserUsersByIDRow
|
var items []Usersamo
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i GetUserUsersByIDRow
|
var i Usersamo
|
||||||
if err := rows.Scan(
|
if err := rows.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Accountid,
|
|
||||||
&i.Amoid,
|
&i.Amoid,
|
||||||
|
&i.Amouserid,
|
||||||
&i.Name,
|
&i.Name,
|
||||||
&i.Email,
|
&i.Email,
|
||||||
&i.Role,
|
&i.Role,
|
||||||
&i.Group,
|
&i.Group,
|
||||||
&i.Subdomain,
|
&i.Deleted,
|
||||||
&i.Amouserid,
|
&i.Createdat,
|
||||||
&i.Country,
|
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -2742,11 +2689,11 @@ func (q *Queries) GetUserUsersByID(ctx context.Context, amouserid int32) ([]GetU
|
|||||||
|
|
||||||
const getUsersWithPagination = `-- name: GetUsersWithPagination :many
|
const getUsersWithPagination = `-- name: GetUsersWithPagination :many
|
||||||
WITH user_data AS (
|
WITH user_data AS (
|
||||||
SELECT AmoID FROM users WHERE users.AccountID = $1 AND Deleted = false
|
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false
|
||||||
)
|
)
|
||||||
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, u.driveurl, COUNT(*) OVER() as total_count
|
SELECT u.id, u.amoid, u.amouserid, u.name, u.email, u.role, u."Group", u.deleted, u.createdat, COUNT(*) OVER() as total_count
|
||||||
FROM users u
|
FROM usersAmo u
|
||||||
JOIN user_data a ON u.AmoUserID = a.AmoID
|
JOIN user_data a ON u.AmoID = a.AmoID
|
||||||
WHERE u.Deleted = false
|
WHERE u.Deleted = false
|
||||||
ORDER BY u.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
ORDER BY u.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
||||||
`
|
`
|
||||||
@ -2759,18 +2706,14 @@ type GetUsersWithPaginationParams struct {
|
|||||||
|
|
||||||
type GetUsersWithPaginationRow struct {
|
type GetUsersWithPaginationRow struct {
|
||||||
ID int64 `db:"id" json:"id"`
|
ID int64 `db:"id" json:"id"`
|
||||||
Accountid string `db:"accountid" json:"accountid"`
|
|
||||||
Amoid int32 `db:"amoid" json:"amoid"`
|
Amoid int32 `db:"amoid" json:"amoid"`
|
||||||
|
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
||||||
Name string `db:"name" json:"name"`
|
Name string `db:"name" json:"name"`
|
||||||
Email string `db:"email" json:"email"`
|
Email string `db:"email" json:"email"`
|
||||||
Role int32 `db:"role" json:"role"`
|
Role int32 `db:"role" json:"role"`
|
||||||
Group int32 `db:"Group" json:"Group"`
|
Group int32 `db:"Group" json:"Group"`
|
||||||
Deleted bool `db:"deleted" json:"deleted"`
|
Deleted bool `db:"deleted" json:"deleted"`
|
||||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
Createdat time.Time `db:"createdat" json:"createdat"`
|
||||||
Subdomain string `db:"subdomain" json:"subdomain"`
|
|
||||||
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
|
||||||
Country string `db:"country" json:"country"`
|
|
||||||
Driveurl string `db:"driveurl" json:"driveurl"`
|
|
||||||
TotalCount int64 `db:"total_count" json:"total_count"`
|
TotalCount int64 `db:"total_count" json:"total_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2785,18 +2728,14 @@ func (q *Queries) GetUsersWithPagination(ctx context.Context, arg GetUsersWithPa
|
|||||||
var i GetUsersWithPaginationRow
|
var i GetUsersWithPaginationRow
|
||||||
if err := rows.Scan(
|
if err := rows.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Accountid,
|
|
||||||
&i.Amoid,
|
&i.Amoid,
|
||||||
|
&i.Amouserid,
|
||||||
&i.Name,
|
&i.Name,
|
||||||
&i.Email,
|
&i.Email,
|
||||||
&i.Role,
|
&i.Role,
|
||||||
&i.Group,
|
&i.Group,
|
||||||
&i.Deleted,
|
&i.Deleted,
|
||||||
&i.Createdat,
|
&i.Createdat,
|
||||||
&i.Subdomain,
|
|
||||||
&i.Amouserid,
|
|
||||||
&i.Country,
|
|
||||||
&i.Driveurl,
|
|
||||||
&i.TotalCount,
|
&i.TotalCount,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -2818,13 +2757,13 @@ SELECT a.quiz_id,a.id,a.result,a.question_id,a.content,a.session,
|
|||||||
FROM answer a2
|
FROM answer a2
|
||||||
WHERE a2.start = true AND a2.session = a.session
|
WHERE a2.start = true AND a2.session = a.session
|
||||||
LIMIT 1) AS utm
|
LIMIT 1) AS utm
|
||||||
,t.accesstoken,r.accountid,r.fieldsrule,r.tagstoadd,r.performerid,r.stepid,r.pipelineid,(SELECT u.name FROM users u WHERE u.amoid = r.performerid) AS performer_name,u.subdomain,u.accountid,u.driveurl
|
,t.accesstoken,r.accountid,r.fieldsrule,r.tagstoadd,r.performerid,r.stepid,r.pipelineid,(SELECT u.name FROM usersAmo u WHERE u.AmoUserID = r.performerid) AS performer_name,u.subdomain,u.accountid,u.driveurl
|
||||||
FROM answer a
|
FROM answer a
|
||||||
INNER JOIN quiz q ON a.quiz_id = q.id
|
INNER JOIN quiz q ON a.quiz_id = q.id
|
||||||
LEFT JOIN amoCRMStatuses s ON a.id = s.AnswerID
|
LEFT JOIN amoCRMStatuses s ON a.id = s.AnswerID
|
||||||
INNER JOIN rules r ON q.id = r.QuizID
|
INNER JOIN rules r ON q.id = r.QuizID
|
||||||
INNER JOIN tokens t ON q.accountid = t.AccountID
|
INNER JOIN tokens t ON q.accountid = t.AccountID
|
||||||
INNER JOIN users u ON q.accountid = u.accountid AND u.amoid = r.accountid
|
INNER JOIN accountsAmo u ON q.accountid = u.accountid AND u.amoid = r.accountid
|
||||||
WHERE a.result = true
|
WHERE a.result = true
|
||||||
AND s.id IS NULL
|
AND s.id IS NULL
|
||||||
AND a.deleted = false
|
AND a.deleted = false
|
||||||
@ -2851,7 +2790,7 @@ type GettingAmoUsersTrueResultsRow struct {
|
|||||||
PerformerName string `db:"performer_name" json:"performer_name"`
|
PerformerName string `db:"performer_name" json:"performer_name"`
|
||||||
Subdomain string `db:"subdomain" json:"subdomain"`
|
Subdomain string `db:"subdomain" json:"subdomain"`
|
||||||
Accountid_2 string `db:"accountid_2" json:"accountid_2"`
|
Accountid_2 string `db:"accountid_2" json:"accountid_2"`
|
||||||
Driveurl string `db:"driveurl" json:"driveurl"`
|
Driveurl sql.NullString `db:"driveurl" json:"driveurl"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GettingAmoUsersTrueResults(ctx context.Context) ([]GettingAmoUsersTrueResultsRow, error) {
|
func (q *Queries) GettingAmoUsersTrueResults(ctx context.Context) ([]GettingAmoUsersTrueResultsRow, error) {
|
||||||
@ -3375,7 +3314,7 @@ func (q *Queries) QuizCopyQid(ctx context.Context, arg QuizCopyQidParams) (QuizC
|
|||||||
const setQuizSettings = `-- name: SetQuizSettings :one
|
const setQuizSettings = `-- name: SetQuizSettings :one
|
||||||
INSERT INTO rules (AccountID, QuizID, PerformerID, PipelineID, StepID, FieldsRule,TagsToAdd)
|
INSERT INTO rules (AccountID, QuizID, PerformerID, PipelineID, StepID, FieldsRule,TagsToAdd)
|
||||||
SELECT u.AmoID AS AccountID,$1 AS QuizID,$2 AS PerformerID,$3 AS PipelineID,
|
SELECT u.AmoID AS AccountID,$1 AS QuizID,$2 AS PerformerID,$3 AS PipelineID,
|
||||||
$4 AS StepID,$5 AS FieldsRule,$6 AS TagsToAdd FROM users u WHERE u.AccountID = $7 AND u.Deleted = false
|
$4 AS StepID,$5 AS FieldsRule,$6 AS TagsToAdd FROM accountsamo u WHERE u.AccountID = $7 AND u.Deleted = false
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -3408,7 +3347,7 @@ const settingDealAmoStatus = `-- name: SettingDealAmoStatus :exec
|
|||||||
INSERT INTO amoCRMStatuses (AccountID, DealID, AnswerID, Status)
|
INSERT INTO amoCRMStatuses (AccountID, DealID, AnswerID, Status)
|
||||||
SELECT u.AmoID, $1, $2, $3
|
SELECT u.AmoID, $1, $2, $3
|
||||||
FROM tokens AS t
|
FROM tokens AS t
|
||||||
JOIN users AS u ON t.AccountID = u.AccountID
|
JOIN accountsAmo AS u ON t.AccountID = u.AccountID
|
||||||
WHERE t.AccessToken = $4 AND u.Deleted = false
|
WHERE t.AccessToken = $4 AND u.Deleted = false
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -3430,11 +3369,12 @@ func (q *Queries) SettingDealAmoStatus(ctx context.Context, arg SettingDealAmoSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
const softDeleteAccount = `-- name: SoftDeleteAccount :exec
|
const softDeleteAccount = `-- name: SoftDeleteAccount :exec
|
||||||
WITH userd AS (
|
WITH amoCompany AS (
|
||||||
SELECT AmoUserID FROM users WHERE users.AccountID = $1
|
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1
|
||||||
),
|
),usersDel AS (
|
||||||
tokend AS (
|
UPDATE usersAmo SET Deleted = true WHERE AmoID = (SELECT AmoID FROM amoCompany)
|
||||||
UPDATE users SET Deleted = true WHERE AmoUserID IN (SELECT AmoUserID FROM userd)
|
),
|
||||||
|
companyDel AS ( UPDATE accountsAmo SET Deleted = true WHERE AmoID = (SELECT AmoID FROM amoCompany)
|
||||||
)
|
)
|
||||||
DELETE FROM tokens WHERE tokens.AccountID = $1
|
DELETE FROM tokens WHERE tokens.AccountID = $1
|
||||||
`
|
`
|
||||||
@ -3481,9 +3421,35 @@ func (q *Queries) TemplateCopy(ctx context.Context, arg TemplateCopyParams) (int
|
|||||||
return quiz_id, err
|
return quiz_id, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updateAmoAccountUser = `-- name: UpdateAmoAccountUser :exec
|
||||||
|
UPDATE usersAmo SET Name = $3, Email = $4, Role = $5, "Group" = $6
|
||||||
|
WHERE AmoID = $1 AND AmoUserID = $2 AND deleted = false
|
||||||
|
`
|
||||||
|
|
||||||
|
type UpdateAmoAccountUserParams struct {
|
||||||
|
Amoid int32 `db:"amoid" json:"amoid"`
|
||||||
|
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
||||||
|
Name string `db:"name" json:"name"`
|
||||||
|
Email string `db:"email" json:"email"`
|
||||||
|
Role int32 `db:"role" json:"role"`
|
||||||
|
Group int32 `db:"Group" json:"Group"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) UpdateAmoAccountUser(ctx context.Context, arg UpdateAmoAccountUserParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, updateAmoAccountUser,
|
||||||
|
arg.Amoid,
|
||||||
|
arg.Amouserid,
|
||||||
|
arg.Name,
|
||||||
|
arg.Email,
|
||||||
|
arg.Role,
|
||||||
|
arg.Group,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const updateFieldRules = `-- name: UpdateFieldRules :exec
|
const updateFieldRules = `-- name: UpdateFieldRules :exec
|
||||||
UPDATE rules SET FieldsRule = $1
|
UPDATE rules SET FieldsRule = $1
|
||||||
WHERE AccountID = (SELECT AmoID FROM users WHERE users.AccountID = $2 AND users.Deleted = false) AND QuizID = $3 AND Deleted = false
|
WHERE AccountID = (SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $2 AND accountsAmo.Deleted = false) AND QuizID = $3 AND Deleted = false
|
||||||
`
|
`
|
||||||
|
|
||||||
type UpdateFieldRulesParams struct {
|
type UpdateFieldRulesParams struct {
|
||||||
@ -3592,25 +3558,9 @@ func (q *Queries) UpdateTags(ctx context.Context, dollar_1 json.RawMessage) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateUsers = `-- name: UpdateUsers :exec
|
|
||||||
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
|
|
||||||
`
|
|
||||||
|
|
||||||
func (q *Queries) UpdateUsers(ctx context.Context, dollar_1 json.RawMessage) error {
|
|
||||||
_, err := q.db.ExecContext(ctx, updateUsers, dollar_1)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatingDealAmoStatus = `-- name: UpdatingDealAmoStatus :exec
|
const updatingDealAmoStatus = `-- name: UpdatingDealAmoStatus :exec
|
||||||
UPDATE amoCRMStatuses SET Status = $1
|
UPDATE amoCRMStatuses SET Status = $1
|
||||||
WHERE DealID = $2 AND AccountID = (SELECT u.AmoID FROM tokens AS t JOIN users AS u ON t.AccountID = u.AccountID WHERE t.AccessToken = $3 AND u.Deleted = false)
|
WHERE DealID = $2 AND AccountID = (SELECT u.AmoID FROM tokens AS t JOIN accountsAmo AS u ON t.AccountID = u.AccountID WHERE t.AccessToken = $3 AND u.Deleted = false)
|
||||||
`
|
`
|
||||||
|
|
||||||
type UpdatingDealAmoStatusParams struct {
|
type UpdatingDealAmoStatusParams struct {
|
||||||
@ -3625,14 +3575,17 @@ func (q *Queries) UpdatingDealAmoStatus(ctx context.Context, arg UpdatingDealAmo
|
|||||||
}
|
}
|
||||||
|
|
||||||
const webhookDelete = `-- name: WebhookDelete :exec
|
const webhookDelete = `-- name: WebhookDelete :exec
|
||||||
WITH userd AS (
|
WITH companyDel AS (
|
||||||
UPDATE users SET Deleted = true WHERE AmoUserID = $1 RETURNING AccountID
|
UPDATE accountsAmo SET Deleted = true WHERE accountsAmo.AmoID = $1 RETURNING AccountID
|
||||||
|
),
|
||||||
|
userDel AS (
|
||||||
|
UPDATE usersAmo SET Deleted = true WHERE AmoID = $1
|
||||||
)
|
)
|
||||||
DELETE FROM tokens WHERE AccountID IN (SELECT AccountID FROM userd)
|
DELETE FROM tokens WHERE AccountID IN (SELECT AccountID FROM companyDel)
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) WebhookDelete(ctx context.Context, amouserid int32) error {
|
func (q *Queries) WebhookDelete(ctx context.Context, amoid int32) error {
|
||||||
_, err := q.db.ExecContext(ctx, webhookDelete, amouserid)
|
_, err := q.db.ExecContext(ctx, webhookDelete, amoid)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user