createOrUpdateAccount creates or updates an account based on the provided name. It returns the account ID and an error if any occurred.
(accountName string, rawDataParams string)
| 267 | // createOrUpdateAccount creates or updates an account based on the provided name. |
| 268 | // It returns the account ID and an error if any occurred. |
| 269 | func (s *Service) createOrUpdateAccount(accountName string, rawDataParams string) (string, errors.Error) { |
| 270 | if accountName == "" { |
| 271 | return "", nil // Return empty ID if name is empty, no error needed here. |
| 272 | } |
| 273 | now := time.Now() |
| 274 | accountId := fmt.Sprintf("csv:CsvAccount:0:%s", accountName) |
| 275 | account := &crossdomain.Account{ |
| 276 | DomainEntity: domainlayer.DomainEntity{ |
| 277 | Id: accountId, |
| 278 | NoPKModel: common.NoPKModel{ |
| 279 | RawDataOrigin: common.RawDataOrigin{ |
| 280 | RawDataParams: rawDataParams, |
| 281 | }, |
| 282 | }, |
| 283 | }, |
| 284 | FullName: accountName, |
| 285 | UserName: accountName, |
| 286 | CreatedDate: &now, // FIXME: will update created_date if already exists. to debug, using created_at instead |
| 287 | } |
| 288 | err := s.dal.CreateOrUpdate(account) |
| 289 | if err != nil { |
| 290 | return "", errors.Default.Wrap(err, fmt.Sprintf("failed to create or update account for %s", accountName)) |
| 291 | } |
| 292 | return accountId, nil |
| 293 | } |
| 294 | |
| 295 | // getStringField extracts a string field from a record map. |
| 296 | // If required is true, it returns an error if the field is missing, nil, empty, or not a string. |
no test coverage detected