Prisma extented Request type
8 try {
→ 19 const newTour = await db.tour.create({
data: {
name: "the new forest hikers",
price: 299,
rating: 4.8,
belongsTo: {
connect: {
id: undefined,
? email?: String,
? AND?: UserWhereInput | UserWhereInput[],
? OR?: UserWhereInput[],
? NOT?: UserWhereInput | UserWhereInput[],
? name?: StringFilter | String,
? password?: StringFilter | String,
? photo?: StringNullableFilter | String | Null,
? createdAt?: DateTimeFilter | DateTime,
? updatedAt?: DateTimeFilter | DateTime,
? tours?: TourListRelationFilter
}
}
}
})
I get undefined on the id field, i don't know why
3 Replies
Well met, adventurer! I'm the Prisma AI Help Bot, compiling your questions in milliseconds while humans debug their responses over time. Who’s on your team?
Hey 👋
Can you please share the query and the schema file?
declare global {
namespace Express {
interface Request {
user?: User;
}
}
}
export const createTour: RequestHandler = async (req, res) => {
const { name, price, rating } = req.body as Tour;
try {
const newTour = await db.tour.create({
data: {
name: lowercaseString(name),
price,
rating,
belongsTo: {
connect: {
id: req.user?.id,
},
},
},
});
res.status(201).json({
message: 'success',
data: newTour,
});
} catch (error) {
console.log(error);
}
};
enum TourType {
EASY
MEDIUM
HARD
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String
email String @unique
password String
photo String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
tours Tour[]
}
model Tour {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String @unique
price Float
rating Float
type TourType @default(EASY)
userId String @db.ObjectId
belongsTo User @relation(fields: [userId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}