0

im using javascript to update a an object but I have to specify the property each time:

 const user = await prisma.user.update({
    where: { id: theid },
    data: { email: statvalue },
  })

so I want to be able to update any property, in this example only 'email' can be changed.

How would I use a string to generically replace where it says 'email' and put in a variable so i can use this short code snippet to update any property of the object?

EDIT- I can access the actual variables in an object this way, as in the suggested answers. But I cant do what I said above. Which is getting the property itself generically and inserting it the above code instead of email.

Keith
  • 57
  • 4

1 Answers1

0

You should be able to accomplish this like this:

const propertyToUpdate = "email";

const user = await prisma.user.update(
{
    where: 
    { 
        id: theid,
    },
    data: 
    { 
        [ propertyToUpdate ]: statvalue,
    },
});
duckdotexe
  • 61
  • 3