censmart
censmart
PPrisma
Created by censmart on 2/2/2025 in #help-and-questions
Prisma extented Request type
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 }
5 replies
PPrisma
Created by censmart on 2/2/2025 in #help-and-questions
Prisma extented Request type
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); } };
5 replies
PPrisma
Created by censmart on 1/27/2025 in #help-and-questions
Modeling data
I do get that undefined on the id, which i want to connect to
8 replies
PPrisma
Created by censmart on 1/27/2025 in #help-and-questions
Modeling data
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 } } } })
8 replies
PPrisma
Created by censmart on 12/11/2024 in #help-and-questions
types from @prisma/client
Yes it did
6 replies