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;
|
||||
|
||||
-- name: AddAmoAccountUser :exec
|
||||
INSERT INTO usersAmo (AmoID, AmoUserID, Name, Email, Role, "Group", Deleted, CreatedAt)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8);
|
||||
INSERT INTO usersAmo (AmoID, AmoUserID, Name, Email, Role, "Group")
|
||||
VALUES ($1, $2, $3, $4, $5, $6);
|
||||
|
||||
-- name: GettingAmoUsersTrueResults :many
|
||||
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,
|
||||
Subdomain: row.Subdomain,
|
||||
Country: row.Country,
|
||||
DriveURL: row.Driveurl.String,
|
||||
DriveURL: row.Driveurl,
|
||||
}
|
||||
|
||||
return &user, nil
|
||||
@ -101,7 +101,7 @@ func (r *AmoRepository) CreateAccount(ctx context.Context, accountID string, use
|
||||
Name: userInfo.Name,
|
||||
Subdomain: userInfo.Subdomain,
|
||||
Country: userInfo.Country,
|
||||
Driveurl: sql.NullString{String: userInfo.DriveURL, Valid: true},
|
||||
Driveurl: userInfo.DriveURL,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@ -111,15 +111,17 @@ func (r *AmoRepository) CreateAccount(ctx context.Context, accountID string, use
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *AmoRepository) CheckMainUser(ctx context.Context, user model.User) error {
|
||||
err := r.queries.CheckMainUser(ctx, sqlcgen.CheckMainUserParams{
|
||||
Name: user.Name,
|
||||
Group: user.Group,
|
||||
Email: user.Email,
|
||||
Role: user.Role,
|
||||
Amoid: user.AmoID,
|
||||
})
|
||||
// todo возможно стоит обновлять еще и компанию пока не знаю
|
||||
|
||||
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,
|
||||
Email: user.Email,
|
||||
Role: user.Role,
|
||||
Group: user.Group,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -127,39 +129,18 @@ func (r *AmoRepository) CheckMainUser(ctx context.Context, user model.User) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *AmoRepository) CheckAndUpdateUsers(ctx context.Context, users []model.User) error {
|
||||
dollar1, err := json.Marshal(users)
|
||||
func (r *AmoRepository) UpdateAmoAccountUser(ctx context.Context, user model.AmoAccountUser) error {
|
||||
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 {
|
||||
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
|
||||
}
|
||||
@ -185,27 +166,25 @@ func (r *AmoRepository) DeleteUsers(ctx context.Context, ids []int64) error {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var users []model.User
|
||||
var users []model.AmoAccountUser
|
||||
for _, row := range rows {
|
||||
user := model.User{
|
||||
user := model.AmoAccountUser{
|
||||
ID: row.ID,
|
||||
Accountid: row.Accountid,
|
||||
AmoID: row.Amoid,
|
||||
AmoUserID: row.Amouserid,
|
||||
Name: row.Name,
|
||||
Email: row.Email,
|
||||
Group: row.Group,
|
||||
Role: row.Role,
|
||||
Subdomain: row.Subdomain,
|
||||
Amouserid: row.Amouserid,
|
||||
Country: row.Country,
|
||||
Deleted: row.Deleted,
|
||||
CreatedAt: row.Createdat,
|
||||
}
|
||||
|
||||
users = append(users, user)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user