Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating entity with unique item and fail #346

Open
luis199230 opened this issue Jun 7, 2023 · 0 comments
Open

Updating entity with unique item and fail #346

luis199230 opened this issue Jun 7, 2023 · 0 comments

Comments

@luis199230
Copy link

luis199230 commented Jun 7, 2023

I have this entity UserEntity:

import {
  Attribute,
  AutoGenerateAttribute,
  Entity,
  INDEX_TYPE,
  AUTO_GENERATE_ATTRIBUTE_STRATEGY,
} from "@typedorm/common";

@Entity({
  name: "users",
  primaryKey: {
    partitionKey: "USER#{{id}}",
    sortKey: "USER#{{id}}",
  },
  indexes: {
    GSI1: {
      partitionKey: "USER#{{email}}",
      sortKey: "USER#PHONE#{{phone}}#EMAIL#{{email}}",
      type: INDEX_TYPE.GSI,
    },
    GSI2: {
      partitionKey: "USER#{{phone}}",
      sortKey: "USER#EMAIL#{{email}}#PHONE#{{phone}}",
      type: INDEX_TYPE.GSI,
    },
    LSI1: {
      sortKey: "USER#UPDATED_AT#{{updatedAt}}",
      type: INDEX_TYPE.LSI,
    },
  },
})
export class UserEntity {
  @AutoGenerateAttribute({
    strategy: AUTO_GENERATE_ATTRIBUTE_STRATEGY.UUID4,
  })
  id: string;

  @Attribute()
  name: string;

  @Attribute()
  lastName: string;

  @Attribute({
    unique: true,
  })
  email: string;

  @Attribute({
    unique: true,
  })
  phone: string;

  @Attribute()
  externalKey: string;

  @Attribute()
  paymentGatewayKey?: string;

  @Attribute()
  cards?: string[];

  @AutoGenerateAttribute({
    strategy: AUTO_GENERATE_ATTRIBUTE_STRATEGY.EPOCH_DATE,
  })
  createdAt: number;

  @AutoGenerateAttribute({
    strategy: AUTO_GENERATE_ATTRIBUTE_STRATEGY.EPOCH_DATE,
    autoUpdate: true,
  })
  updatedAt: number;
}

I tried to update using this query:

getEntityManager().update(UserEntity, { id }, {
      name: 'John',
      lastName: 'Doe',
      email: 'john@doe.com'
      phone: '123456789',
    })

But I got this message:

{
    "errorType": "TypeError",
    "errorMessage": "Cannot read properties of undefined (reading 'map')",
    "code": "TypeError",
    "message": "Cannot read properties of undefined (reading 'map')",
    "time": "2023-06-07T03:35:14.889Z",
    "stack": [
        "TypeError: Cannot read properties of undefined (reading 'map')",
        "    at Response.<anonymous> (/var/task/node_modules/@typedorm/document-client/cjs/src/classes/document-client-v2.js:97:57)",
        "    at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:367:18)",
        "    at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:106:20)",
        "    at Request.emit (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:78:10)",
        "    at Request.emit (/var/task/node_modules/aws-sdk/lib/request.js:686:14)",
        "    at Request.transition (/var/task/node_modules/aws-sdk/lib/request.js:22:10)",
        "    at AcceptorStateMachine.runTo (/var/task/node_modules/aws-sdk/lib/state_machine.js:14:12)",
        "    at /var/task/node_modules/aws-sdk/lib/state_machine.js:26:10",
        "    at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:38:9)",
        "    at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:688:12)"
    ]
}  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant