update account and users amo repo methods
This commit is contained in:
parent
405cd05c98
commit
391f9df624
@ -963,8 +963,8 @@ UPDATE usersAmo SET Name = $3, Email = $4, Role = $5, "Group" = $6
|
|||||||
WHERE AmoID = $1 AND AmoUserID = $2 AND deleted = false;
|
WHERE AmoID = $1 AND AmoUserID = $2 AND deleted = false;
|
||||||
|
|
||||||
-- name: AddAmoAccountUser :exec
|
-- name: AddAmoAccountUser :exec
|
||||||
INSERT INTO usersAmo (AmoID, AmoUserID, Name, Email, Role, "Group", Deleted, CreatedAt)
|
INSERT INTO usersAmo (AmoID, AmoUserID, Name, Email, Role, "Group")
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8);
|
VALUES ($1, $2, $3, $4, $5, $6);
|
||||||
|
|
||||||
-- name: GettingAmoUsersTrueResults :many
|
-- name: GettingAmoUsersTrueResults :many
|
||||||
SELECT a.quiz_id,a.id,a.result,a.question_id,a.content,a.session,
|
SELECT a.quiz_id,a.id,a.result,a.question_id,a.content,a.session,
|
||||||
|
|||||||
@ -88,7 +88,7 @@ func (r *AmoRepository) GetCurrentAccount(ctx context.Context, accountID string)
|
|||||||
CreatedAt: row.Createdat,
|
CreatedAt: row.Createdat,
|
||||||
Subdomain: row.Subdomain,
|
Subdomain: row.Subdomain,
|
||||||
Country: row.Country,
|
Country: row.Country,
|
||||||
DriveURL: row.Driveurl.String,
|
DriveURL: row.Driveurl,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &user, nil
|
return &user, nil
|
||||||
@ -101,7 +101,7 @@ func (r *AmoRepository) CreateAccount(ctx context.Context, accountID string, use
|
|||||||
Name: userInfo.Name,
|
Name: userInfo.Name,
|
||||||
Subdomain: userInfo.Subdomain,
|
Subdomain: userInfo.Subdomain,
|
||||||
Country: userInfo.Country,
|
Country: userInfo.Country,
|
||||||
Driveurl: sql.NullString{String: userInfo.DriveURL, Valid: true},
|
Driveurl: userInfo.DriveURL,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -111,15 +111,17 @@ func (r *AmoRepository) CreateAccount(ctx context.Context, accountID string, use
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *AmoRepository) CheckMainUser(ctx context.Context, user model.User) error {
|
// todo возможно стоит обновлять еще и компанию пока не знаю
|
||||||
err := r.queries.CheckMainUser(ctx, sqlcgen.CheckMainUserParams{
|
|
||||||
|
func (r *AmoRepository) AddAmoAccountUser(ctx context.Context, user model.AmoAccountUser) error {
|
||||||
|
err := r.queries.AddAmoAccountUser(ctx, sqlcgen.AddAmoAccountUserParams{
|
||||||
|
Amoid: user.AmoID,
|
||||||
|
Amouserid: user.AmoUserID,
|
||||||
Name: user.Name,
|
Name: user.Name,
|
||||||
Group: user.Group,
|
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
Role: user.Role,
|
Role: user.Role,
|
||||||
Amoid: user.AmoID,
|
Group: user.Group,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -127,39 +129,18 @@ func (r *AmoRepository) CheckMainUser(ctx context.Context, user model.User) erro
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *AmoRepository) CheckAndUpdateUsers(ctx context.Context, users []model.User) error {
|
func (r *AmoRepository) UpdateAmoAccountUser(ctx context.Context, user model.AmoAccountUser) error {
|
||||||
dollar1, err := json.Marshal(users)
|
err := r.queries.UpdateAmoAccountUser(ctx, sqlcgen.UpdateAmoAccountUserParams{
|
||||||
|
Amoid: user.AmoID,
|
||||||
|
Amouserid: user.AmoUserID,
|
||||||
|
Name: user.Name,
|
||||||
|
Email: user.Email,
|
||||||
|
Role: user.Role,
|
||||||
|
Group: user.Group,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
rows, err := r.queries.CheckUsers(ctx, dollar1)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if rows != nil {
|
|
||||||
var toUpdate []model.User
|
|
||||||
for _, row := range rows {
|
|
||||||
to := model.User{
|
|
||||||
AmoID: row.Amoid,
|
|
||||||
Name: row.Name,
|
|
||||||
Group: row.Group,
|
|
||||||
Role: row.Role,
|
|
||||||
Email: row.Email,
|
|
||||||
Amouserid: row.Amouserid,
|
|
||||||
}
|
|
||||||
toUpdate = append(toUpdate, to)
|
|
||||||
}
|
|
||||||
dollar1, err := json.Marshal(toUpdate)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = r.queries.UpdateUsers(ctx, dollar1)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -185,27 +166,25 @@ func (r *AmoRepository) DeleteUsers(ctx context.Context, ids []int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *AmoRepository) GetUserUsersByID(ctx context.Context, amoUserID int32) ([]model.User, error) {
|
func (r *AmoRepository) GetUserUsersByID(ctx context.Context, amoUserID int32) ([]model.AmoAccountUser, error) {
|
||||||
rows, err := r.queries.GetUserUsersByID(ctx, amoUserID)
|
rows, err := r.queries.GetUserUsersByID(ctx, amoUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var users []model.User
|
var users []model.AmoAccountUser
|
||||||
for _, row := range rows {
|
for _, row := range rows {
|
||||||
user := model.User{
|
user := model.AmoAccountUser{
|
||||||
ID: row.ID,
|
ID: row.ID,
|
||||||
Accountid: row.Accountid,
|
|
||||||
AmoID: row.Amoid,
|
AmoID: row.Amoid,
|
||||||
|
AmoUserID: row.Amouserid,
|
||||||
Name: row.Name,
|
Name: row.Name,
|
||||||
Email: row.Email,
|
Email: row.Email,
|
||||||
Group: row.Group,
|
Group: row.Group,
|
||||||
Role: row.Role,
|
Role: row.Role,
|
||||||
Subdomain: row.Subdomain,
|
Deleted: row.Deleted,
|
||||||
Amouserid: row.Amouserid,
|
CreatedAt: row.Createdat,
|
||||||
Country: row.Country,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
users = append(users, user)
|
users = append(users, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user