Encountering an "error: not assignable to type" message while attempting to modify a field in Prisma

As a newcomer to Prisma, I am facing an issue while trying to update a field based on a foreign key. The error message I receive is:

Type '{ authorId: number; }' is not assignable to type 'PatientWhereUniqueInput'. 

Here is my schema for reference:

  id Int @id @default(autoincrement())
  name String?
  password String
  email String @unique
  patient Patient[]
}

model Patient {
  id Int @id @default(autoincrement())
  firstName String
  lastName String
  email String @unique
  password String
  contact String
  address String
  dob String
  image String?
  author User @relation(fields: [authorId], references: [id])
  authorId Int
  specialAttention Boolean @default(false)
}

In order to update the patient data, I am utilizing the following method, with userId representing the currently logged in user's Id retrieved from the middleware:

  const updatedPatient = await prisma.patient.update({
    where: {
      authorId: userId,
    },
    data: body,
  });
  return updatedPatient;
};

Answer №1

In order to update data, you must use the unique fields id and email.

type PatientWhereUniqueInput {
  id?: Int
  email?: String
}

This means your query should follow this structure:

const updatedPatient = await prisma.patient.update({
    where: {
      email: userEmail,
    },
    data: body,
  });
  return updatedPatient;
};

If you need to update multiple fields, you can use updateMany like this:

const updatedPatient = await prisma.patient.updateMany({
  where: {
    authorId: 1 ,
  },
  data: {
    firstName: 'William'
  },
});

For further information on a similar topic, check out this discussion here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Preventing Redundancy in Angular 2: Tips for Avoiding Duplicate Methods

Is there a way I can streamline my if/else statement to avoid code repetition in my header component? Take a look at the example below: export class HeaderMainComponent { logoAlt = 'We Craft beautiful websites'; // Logo alt and title texts @Vie ...

Angular 2's JSON tube is malfunctioning

Each time I attempt to utilize the JSON pipe to pass my data, an error message appears in the console: Unhandled Promise rejection: Template parse errors: The pipe 'json' could not be found (... Can someone help me understand what mistake I am ...

Tips for extracting data from an Angular object using the *ngFor directive

https://i.stack.imgur.com/ai7g1.png The JSON structure displayed in the image above is what I am working with. My goal is to extract the value associated with the key name. This is the approach I have taken so far: <span *ngFor="let outlet of pr ...

Automatic type inference is activated while employing intricate "isEmpty" verification

I have created a customized function similar to Ramda's isEmpty, tailored to meet my specific requirements: /** * Checks if a value is empty. * Returns true for null, undefined, empty strings, empty Sets, empty Maps, and objects without properties. ...

Connecting an Angular application to a URL hosted on localhost

I am currently working on an Angular project where one of the links needs to redirect to a different website. During development, this link points to a localhost URL like localhost:4210. However, due to security reasons in Angular, using such URLs is cons ...

React-table fails to show newly updated data

I am facing an issue with my react-table where real-time notifications received from an event-source are not being reflected in the table after data refresh. https://i.stack.imgur.com/q4vLL.png The first screenshot shows the initial data retrieval from th ...

Alias in webpack for Typescript modules

I'm facing an issue where I need to assign an alias for 'Hammer' in my code. I've already included the necessary paths in my tsconfig file as shown below: { "compilerOptions": { "declaration": true, "noImplicitAny": false , ...

Creating a type in TypeScript with keys as values taken from another type

There is an object const navigatorNames: NavigatorNamesType = { homeNavigation: 'HomeNavigation', authNavigation: 'AuthNavigation' } with the type defined as type NavigatorNamesType = { homeNavigation: 'HomeNavigation ...

Restrict the parameter type using a type predicate

How can I effectively narrow types based on the value of a single field in TypeScript? It seems that using type predicates may not be working as expected to narrow down the types of other parameters within a type. Is there a way to ensure correct type na ...

The selectedIndex attribute is failing to function properly for the mat-tab-nav-bar tabs in Angular Material

I've implemented the tab navigation code as shown below: <nav mat-tab-nav-bar [selectedIndex]="0"> <a mat-tab-link *ngFor="let link of navLinks; let i = index;" [routerLink]="link.path" routerLinkActive #rla="rou ...

Associate union with interface attributes

Can a union type be transformed into an interface in Typescript? My Desired Outcome If we have a union type A: type A = 'one' | 'two' | 'three'; I want to convert it to interface B: interface B { one: boolean; two ...

How do I utilize the file handler to execute the flush method within the Deno log module using Typescript?

I'm having trouble accessing the fileHandler object from my logger in order to flush the buffer to the file. This is the program I am working with: import * as log from "https://deno.land/<a href="/cdn-cgi/l/email-protection" class="__cf_emai ...

Describe the TypeScript type for an object with constant keys

My query resembles the one found in this Typescript interface definition question, but has a slight variation. I am beginning with an object where the keys are constants: const KEYS = { KEY1: 'hello', KEY2: 'world' } as const; How ...

Typescript method fails to compile due to an indexing error

Imagine you're trying to implement this method in Typescript: setResult(guId: string,fieldname: string, data:Array<UsedTsoClusterKey>) { let octdctruns: OctDctRun[] = [...this.octDctRuns]; const index = octdctruns.findIndex((o) => o.guid ...

How can one correctly cast or convert an array of objects to the interface that extends the objects' parent interface in Typescript?

Question: How can I optimize the usage of method sendItemIdsOverBroadcastChannel to reduce message size? interface IItemId { id: number; classId: number; } interface IItem extends IItemId { longString: string; anotherLongString: string } inte ...

Can TypeScript provide a way to declare that a file adheres to a particular type or interface?

Experimenting with different TypeScript styles has been quite enjoyable, especially the import * as User from './user' syntax inspired by node. I've been wondering if there is a way to specify a default type as well. Suppose I have an interf ...

Conditional Types - Finding the perfect match for a nullable type

I am attempting to find a nullable type in a conditional type: interface Unwrapped { dummyProp: string; } interface UnwrappedArray<T extends Unwrapped> extends Array<T> { } interface Wrapped<T extends Unwrapped> { unwrapped: T; } type T ...

Struggling to overcome the TS2322 error when assigning generic values

I am currently working on developing higher-order React components that will include default values for components labeled as "named". Here is a basic implementation example: type SomeProps = { a: string } type Variants = 'variantA' | 'var ...

Error in Typescript: Cannot assign type 'number' to type 'never'

I encountered an issue related to 'Type 'number' is not assignable to type 'never'.' 'Type 'number' is not assignable to type 'never'.' 'Type 'string' is not assignable t ...

Creating global variables in NodeJS allows you to access and modify data

Currently, this construct is being utilized to create a global LOG: declare global { let LOG: Logger; } // eslint-disable-next-line @typescript-eslint/no-namespace declare namespace globalThis { let LOG: Logger; } globalThis.LOG = new Logger(); It f ...