added method GetAllYclientsUserToken

This commit is contained in:
pasha1coil 2025-10-06 17:18:56 +03:00
parent a2baabf928
commit 43096217dc
3 changed files with 56 additions and 1 deletions

@ -1553,4 +1553,7 @@ update YclientsTokens set Expiration=$1, Active = $2 where AccountID = $3 RETURN
select * from YclientsTokens where AccountID = $1 and Expiration=false and Active = true; select * from YclientsTokens where AccountID = $1 and Expiration=false and Active = true;
-- name: CreateYclientsAccount :one -- name: CreateYclientsAccount :one
insert into YclientsAccounts (AccountID,SalonID,Title,Country,ShortDecription) values ($1,$2,$3,$4,$5) RETURNING *; insert into YclientsAccounts (AccountID,SalonID,Title,Country,ShortDecription) values ($1,$2,$3,$4,$5) RETURNING *;
-- name: GetAllYclientsUserToken :many
select * from YclientsTokens where Expiration=false and Active = true;

@ -2164,6 +2164,40 @@ func (q *Queries) GetAllTokens(ctx context.Context) ([]Token, error) {
return items, nil return items, nil
} }
const getAllYclientsUserToken = `-- name: GetAllYclientsUserToken :many
select accountid, salonid, accesstoken, active, expiration, createdat from YclientsTokens where Expiration=false and Active = true
`
func (q *Queries) GetAllYclientsUserToken(ctx context.Context) ([]Yclientstoken, error) {
rows, err := q.db.QueryContext(ctx, getAllYclientsUserToken)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Yclientstoken
for rows.Next() {
var i Yclientstoken
if err := rows.Scan(
&i.Accountid,
&i.Salonid,
&i.Accesstoken,
&i.Active,
&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
}
const getBitrixFieldByID = `-- name: GetBitrixFieldByID :one const getBitrixFieldByID = `-- name: GetBitrixFieldByID :one
SELECT id, bitrixid, accountid, entityid, fieldname, editfromlabel, fieldtype, deleted, createdat FROM BitrixFields WHERE BitrixID = $1 AND Deleted = false SELECT id, bitrixid, accountid, entityid, fieldname, editfromlabel, fieldtype, deleted, createdat FROM BitrixFields WHERE BitrixID = $1 AND Deleted = false
` `

@ -95,6 +95,24 @@ func (r *YclientsRepository) GetYclientsUserToken(ctx context.Context, accountID
}, err }, err
} }
func (r *YclientsRepository) GetAllYclientsUserToken(ctx context.Context) ([]model.YclientsToken, error) {
rows, err := r.queries.GetAllYclientsUserToken(ctx)
if err != nil {
return nil, err
}
var tokens []model.YclientsToken
for _, row := range rows {
tokens = append(tokens, model.YclientsToken{
AccountID: row.Accountid,
SalonID: row.Salonid,
AccessToken: row.Accesstoken,
Active: row.Active,
Expiration: row.Expiration,
})
}
return tokens, nil
}
// users // users
func (r *YclientsRepository) GetCurrentAccount(ctx context.Context, accountID string) (*model.YclientsAccount, error) { func (r *YclientsRepository) GetCurrentAccount(ctx context.Context, accountID string) (*model.YclientsAccount, error) {
row, err := r.queries.GetCurrentYclientsCompany(ctx, accountID) row, err := r.queries.GetCurrentYclientsCompany(ctx, accountID)