2024-04-09 15:52:37 +00:00
|
|
|
package repository
|
|
|
|
|
|
|
|
import (
|
|
|
|
"amocrm/internal/models"
|
2024-04-10 08:54:18 +00:00
|
|
|
amo2 "amocrm/internal/models/amo"
|
|
|
|
"amocrm/internal/tools"
|
2024-04-09 15:52:37 +00:00
|
|
|
"context"
|
2024-04-10 08:54:18 +00:00
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
2024-04-09 15:52:37 +00:00
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (r *Repository) UpdateListUsers(ctx context.Context) error {
|
|
|
|
//TODO:IMPLEMENT ME
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Repository) GettingUserFromCash(ctx context.Context) (*models.UserListResp, error) {
|
|
|
|
//TODO:IMPLEMENT ME
|
|
|
|
|
|
|
|
return &models.UserListResp{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Repository) SoftDeleteAccount(ctx context.Context) error {
|
|
|
|
//TODO:IMPLEMENT ME
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Repository) GetCurrentAccount(ctx context.Context) (*models.GetCurrentAccountResp, error) {
|
|
|
|
//TODO:IMPLEMENT ME
|
|
|
|
|
|
|
|
return &models.GetCurrentAccountResp{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Repository) CreateAccount(ctx context.Context, accountID string) error {
|
|
|
|
userData := models.User{}
|
|
|
|
userData.ObjID = primitive.NewObjectID()
|
|
|
|
userData.Accountid = accountID
|
|
|
|
_, err := r.mdbUser.InsertOne(ctx, userData)
|
|
|
|
if err != nil {
|
|
|
|
r.logger.Error("error createAccount in mongodb")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2024-04-10 08:54:18 +00:00
|
|
|
|
|
|
|
func (r *Repository) UpdateAccount(ctx context.Context, accountID string, userInfo *amo2.AmocrmUserInformation) error {
|
|
|
|
filter := bson.M{"Accountid": accountID}
|
|
|
|
// todo надо как то получить роль и почту
|
|
|
|
update := bson.M{
|
|
|
|
"$set": bson.M{
|
|
|
|
"Name": userInfo.Name,
|
|
|
|
"ID": userInfo.ID,
|
|
|
|
"Amoid": userInfo.CurrentUserID,
|
|
|
|
"Group": tools.ConvertUserGroups(userInfo),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := r.mdbUser.UpdateOne(ctx, filter, update)
|
|
|
|
if err != nil {
|
|
|
|
r.logger.Error("error updateAccount in mongodb")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|