我在Next中有一个运行Prisma查询的简单API端点。当我尝试通过Vercel部署到生产时,我收到以下错误(在localhost上工作正常):
Type error: Type '{ activated: true; }' is not assignable to type 'UserWhereInput'.
Object literal may only specify known properties, and 'activated' does not exist in type 'UserWhereInput'.
activated
清楚地存在于我的架构中。如何告诉Typescript?下面是我的代码
// ../api/alert.ts
import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "../../lib/prisma";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.method === "POST") {
try {
const { authorization } = req.headers;
if (authorization === `Bearer ${process.env.API_SECRET_KEY}`) {
//make sure the service that is calling this API endpoint is authorized
//get all users that are activated
const activeUsers = prisma.user.findMany({
where: { activated: true },
});
// do other stuff
res.status(200).json({ success: true });
} else {
res.status(401).json({ success: false });
}
} catch (err) {
res.status(500).json({ statusCode: 500 });
}
} else {
res.setHeader("Allow", "POST");
res.status(405).end("Method Not Allowed");
}
}
架构.prisma
...
model User {
id String @id @default(cuid())
phone String
createdAt DateTime @default(now())
activated Boolean @default(false)
Message Message[]
}
/资源库/棱镜.ts
import { PrismaClient } from "@prisma/client";
let prisma: PrismaClient;
if (process.env.NODE_ENV === "production") {
prisma = new PrismaClient();
} else {
let globalWithPrisma = global as typeof globalThis & {
prisma: PrismaClient;
};
if (!globalWithPrisma.prisma) {
globalWithPrisma.prisma = new PrismaClient();
}
prisma = globalWithPrisma.prisma;
}
export default prisma;
1条答案
按热度按时间yftpprvb1#
我必须将
prisma generate
添加到package.json
,如下所示: