Shmuel
01/06/2022, 3:46 PM.create(
or do you have the back-end build it up?
Say for example you want to create a user with posts do you send back- in the body- an object that's prisma specific looking like this...
{
data: {
email: '<mailto:emma@prisma.io|emma@prisma.io>',
posts: {
create: [
{
title: 'My first post',
categories: {
connectOrCreate: [
{
create: { name: 'Introductions' },
where: {
name: 'Introductions',
},
},
],
},
},
{
title: 'How to make cookies',
categories: {
connectOrCreate: [
{
create: { name: 'Social' },
where: {
name: 'Social',
},
},
],
},
},
],
},
},
}
And just dump the prebuilt object into...
const { id } = await prisma.user.create({
data: req.body,
});
Or do you send back something less prisma specific like this...
data: {
email: '<mailto:emma@prisma.io|emma@prisma.io>',
posts:
[
{
title: 'My first post',
categories: [
{
name: 'Introductions',
},
],
},
{
title: 'How to make cookies',
categories:
[
{
name: 'Social',
},
],
},
],
},
And then build it up before passing it to the prisma.user.create
method?Richard Kaufman-López
01/06/2022, 4:10 PMawait prisma.user.create({
data: req.body,
});
That is very dangerous. You always want to validate all data that will go into the DB.Shmuel
01/06/2022, 4:32 PMRichard Kaufman-López
01/06/2022, 4:35 PMawait prisma.user.create({
data: req.body,
});
where req.body
has req.body.roles = ["admin"]
, for exampleRichard Kaufman-López
01/06/2022, 4:36 PMShmuel
01/06/2022, 5:01 PM