added Item and Cart Models

This commit is contained in:
Kfir Dayan 2023-06-08 14:55:04 +03:00
parent a671f5fefc
commit bd481bb1b1
2 changed files with 18 additions and 33 deletions

View file

@ -15,4 +15,22 @@ model User {
password String password String
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @updatedAt 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])
} }

View file

@ -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();
});