Merge branch 'quizManual' into 'main'
Quiz manual See merge request backend/quiz/common!23
This commit is contained in:
commit
61ea5f2e25
@ -1058,3 +1058,8 @@ SELECT * FROM fields WHERE AmoID = $1 AND Deleted = false;
|
|||||||
SELECT ID,AmoID,Code,AccountID,Name,Entity,Type
|
SELECT ID,AmoID,Code,AccountID,Name,Entity,Type
|
||||||
FROM fields
|
FROM fields
|
||||||
WHERE AccountID = $1 AND Deleted = false;
|
WHERE AccountID = $1 AND Deleted = false;
|
||||||
|
|
||||||
|
-- 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;;
|
||||||
|
@ -832,6 +832,31 @@ func (q *Queries) CreateWebHook(ctx context.Context, arg CreateWebHookParams) er
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
const deleteAccountById = `-- name: DeleteAccountById :exec
|
const deleteAccountById = `-- name: DeleteAccountById :exec
|
||||||
DELETE FROM account WHERE id = $1
|
DELETE FROM account WHERE id = $1
|
||||||
`
|
`
|
||||||
|
@ -191,6 +191,14 @@ var (
|
|||||||
Type: "day",
|
Type: "day",
|
||||||
Value: "день",
|
Value: "день",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
PrivilegeID: "quizManual",
|
||||||
|
Name: "Заказать quiz",
|
||||||
|
ServiceKey: skey,
|
||||||
|
Description: "Закажите квиз и мы сделаем его в течении трех дней",
|
||||||
|
Type: "count",
|
||||||
|
Value: "шт",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
5
pj_errors/pg_error.go
Normal file
5
pj_errors/pg_error.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package pj_errors
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var ErrNotFound = errors.New("not found")
|
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal/sqlcgen"
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal/sqlcgen"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||||
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -344,3 +345,19 @@ func (r *AccountRepository) GetQidOwner(ctx context.Context, qId string) (string
|
|||||||
|
|
||||||
return userID, nil
|
return userID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *AccountRepository) ManualDone(ctx context.Context, userID string) error {
|
||||||
|
_, err := r.queries.DecrementManual(ctx, sqlcgen.DecrementManualParams{
|
||||||
|
UserID: sql.NullString{String: userID, Valid: true},
|
||||||
|
Privilegeid: sql.NullString{String: "quizManual", Valid: true},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if err == sql.ErrNoRows {
|
||||||
|
return pj_errors.ErrNotFound
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user