Redis-om EntityId: how to return the result of a search

90 views Asked by At

I use redis-om with nodejs, typescript and graphql

I save a record in redis with this code

let vote = await voteRepository.save({
      voterID,
      date,
      certified
    });

the type of 'vote' is 'Entity' but I want to send back to the client an object of type Vote:

type Vote {
  voterID: String!
  date: String!
  certified: Boolean!
}

For now I must recreate another variable like this:

async addVote({ voterID, date, certified }: Vote): Promise<Vote> {
  let vote = voteRepository.save...  // type Entity
  let voteReturned: Vote = {
    voterID,
    date,
    certified
  }
  // return vote --> Error: Type 'Entity' is missing the following properties from type 'Vote'
  return voteReturned // OK: type Vote
}

How can I extract or convert the variable 'vote' to the type Vote ?

Same question for returning an array after a search.

0

There are 0 answers