kwicherbelliaken / bad-reviews-make-good-movies

0 stars 0 forks source link

[FEATURE]: figure out a better way to handle writing and reading Movie from DB. #68

Open slackermorris opened 9 months ago

slackermorris commented 9 months ago

The issue arises when trying to resolve the id. It can't be conditionally sent when trying to accommodate for read and write paths.

  constructor(
    username: string,
    watchlistId: string,
    movieDetails: MovieDetails,
    id?: string
  ) {
    super();
    this.id = id ?? nanoid();
    this.username = username;
    this.watchlistId = watchlistId;
    this.movieDetails = movieDetails;
  }

This all relates to this fromItem call:

    static fromItem(item?: DynamoDB.DocumentClient.AttributeMap): Movie {
    if (!item) throw new Error("No item!");
    if (item.username == null) throw new Error("No username!");
    if (item.watchlistId == null) throw new Error("No watchlistId!");
    if (item.movieDetails == null) throw new Error("No movieDetails!");

    return new Movie(
      item.username,
      item.watchlistId,
      item.movieDetails,
      item.id
    );
  }