UpdateUsers to update multiple users, with parameters of user IDs slice If ids set to nil / empty all the users will be updated
(ctx context.Context, data map[string]interface{}, ids []string)
| 145 | // UpdateUsers to update multiple users, with parameters of user IDs slice |
| 146 | // If ids set to nil / empty all the users will be updated |
| 147 | func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{}, ids []string) error { |
| 148 | // set updated_at time for all users |
| 149 | data["updated_at"] = time.Now().Unix() |
| 150 | updateFields, params := GetSetFields(data) |
| 151 | if len(ids) > 0 { |
| 152 | for _, id := range ids { |
| 153 | params["id"] = id |
| 154 | userQuery := fmt.Sprintf("UPDATE %s.%s SET %s WHERE _id = $id", p.scopeName, schemas.Collections.User, updateFields) |
| 155 | |
| 156 | _, err := p.db.Query(userQuery, &gocb.QueryOptions{ |
| 157 | ScanConsistency: gocb.QueryScanConsistencyRequestPlus, |
| 158 | Context: ctx, |
| 159 | NamedParameters: params, |
| 160 | }) |
| 161 | if err != nil { |
| 162 | return err |
| 163 | } |
| 164 | } |
| 165 | } else { |
| 166 | userQuery := fmt.Sprintf("UPDATE %s.%s SET %s WHERE _id IS NOT NULL", p.scopeName, schemas.Collections.User, updateFields) |
| 167 | _, err := p.db.Query(userQuery, &gocb.QueryOptions{ |
| 168 | ScanConsistency: gocb.QueryScanConsistencyRequestPlus, |
| 169 | Context: ctx, |
| 170 | NamedParameters: params, |
| 171 | }) |
| 172 | if err != nil { |
| 173 | return err |
| 174 | } |
| 175 | } |
| 176 | return nil |
| 177 | } |
| 178 | |
| 179 | // GetUserByPhoneNumber to get user information from database using phone number |
| 180 | func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*schemas.User, error) { |
nothing calls this directly
no test coverage detected