added Item and Cart Models
This commit is contained in:
parent
a671f5fefc
commit
bd481bb1b1
2 changed files with 18 additions and 33 deletions
|
@ -16,3 +16,21 @@ model User {
|
|||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model Item {
|
||||
id String @id @default(cuid()) @map("_id")
|
||||
name String
|
||||
price Float
|
||||
quantity Int @default(0)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model Cart {
|
||||
id String @id @default(cuid()) @map("_id")
|
||||
userId String
|
||||
itemId String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
@@unique([userId, itemId])
|
||||
}
|
33
src/index.ts
33
src/index.ts
|
@ -10,36 +10,3 @@ const prisma = new PrismaClient({
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
async function createUser(firstName, lastName, email, password) {
|
||||
console.log('Creating user...')
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
firstName,
|
||||
lastName,
|
||||
email,
|
||||
password,
|
||||
},
|
||||
});
|
||||
console.log(`Created user with id: ${user.id}`)
|
||||
console.log('User created!');
|
||||
return user;
|
||||
}
|
||||
|
||||
createUser('John', 'Doe', 'john@example.com', 'password')
|
||||
.then((user) => {
|
||||
console.log('User created:', user);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error creating user:', error);
|
||||
})
|
||||
.finally(() => {
|
||||
prisma.$disconnect();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue