Reputation: 1
I'm developing an API using Nestjs and Prisma, the problem occurs when I try to insert information in the Database (Postgres), I get this error, saying that it cannot read the "organ" property which is the table in which I intend to insert the information.
The error is occurring in the repository in the create method: `
import { Organ } from '@prisma/client';
import { CreateOrganDto } from '../../../../../modules/organs/dto/create-organ.dto';
import { IOrganRepository } from '../../../../../modules/organs/repositories/IOrganRepository';
import { PrismaService } from '../../../../../shared/infra/db/prisma.service';
export class OrganRepository implements IOrganRepository {
constructor(private prisma: PrismaService) {}
async create({ name }: CreateOrganDto): Promise<Organ> {
const organ = await this.prisma.organ.create({
data: {
name
},
});
return organ;
}
async findByName(name: string): Promise<Organ | null> {
const organ = await this.prisma.organ.findUnique({
where: {
name,
},
});
return organ;
}
}
a const organ dev
this.prisma.organ.create method is returning an Organ, never type when it should just return Organ
Upvotes: 0
Views: 1993
Reputation: 31
So this fix is to make the class injectable by annotating it with @Injectable(), put it at the top of the class
Upvotes: 0
Reputation: 7618
It looks like the PrismaClient is not in sync with Prisma Schema.
You would need to invoke npx prisma generate
in order to regenerate the PrismaClient - Reference.
Also, I would recommend checking that all models defined in schema file has been created in the database, you can either use npx prisma migrate dev
or npx prisma db push
to create the corresponding tables - Reference.
Upvotes: 0