Chris Bitoy
12/06/2021, 5:35 PM→ 42 const creatives = await prisma.creative.create({
data: {
brandLogo: 'www.test2.png',
brandName: 'This is a Unique one',
projectName: 'ProjectName is also unique',
headerImage: 'www.imageheader.png',
projectCreative: [
'<http://anothertest2.com|anothertest2.com>',
'<http://anothertest3.com|anothertest3.com>',
'<http://anothertest4.com|anothertest4.com>',
'<http://anothertest5.com|anothertest5.com>'
]
~~~~~~~~~~~~~~~~~~~~~
}
})
Argument projectCreative: Got invalid value
[
'<http://anothertest2.com|anothertest2.com>',
'<http://anothertest3.com|anothertest3.com>',
'<http://anothertest4.com|anothertest4.com>',
'<http://anothertest5.com|anothertest5.com>'
]
on prisma.createOneCreative. Provided List<String>, expected ProjectCreativeCreateNestedManyWithoutCreativeInput:
type ProjectCreativeCreateNestedManyWithoutCreativeInput {
create?: ProjectCreativeCreateWithoutCreativeInput | List<ProjectCreativeCreateWithoutCreativeInput> | ProjectCreativeUncheckedCreateWithoutCreativeInput | List<ProjectCreativeUncheckedCreateWithoutCreativeInput>
connectOrCreate?: ProjectCreativeCreateOrConnectWithoutCreativeInput | List<ProjectCreativeCreateOrConnectWithoutCreativeInput>
createMany?: ProjectCreativeCreateManyCreativeInputEnvelope
connect?: ProjectCreativeWhereUniqueInput | List<ProjectCreativeWhereUniqueInput>
}
But I defined my models to accept an array of strings:
model Creative {
id Int @id @default(autoincrement())
owner_id String @default(cuid())
campaign_id String @default(cuid())
parent_c_id String @default(cuid())
brandLogo String
brandName String @unique
projectName String @unique
headerImage String
projectCreative ProjectCreative[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model ProjectCreative {
id Int @id @default(autoincrement())
creative Creative? @relation(fields: [creativeId], references: [id])
creativeId Int?
cloudinary_url0 String
cloudinary_url1 String
cloudinary_url2 String
cloudinary_url3 String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
via my POST route:
<http://router.post|router.post>("/creatives", async (req, res) => {
try {
const { brandLogo, brandName, projectName, headerImage, projectCreative } =
req.body;
const creatives = await prisma.creative.create({
data: { brandLogo, brandName, projectName, headerImage, projectCreative },
});
res.status(201).json({ success: true, data: creatives, error: "" });
} catch (error) {
console.log(error);
res.status(500).json({ data: {}, error: error, status: 500 });
}
});
With this test data:
{
"brandLogo": "www.test2.png",
"brandName": "This is a Unique one",
"projectName": "ProjectName is also unique",
"headerImage": "www.imageheader.png",
"projectCreative": [
"<http://anothertest2.com|anothertest2.com>",
"<http://anothertest3.com|anothertest3.com>",
"<http://anothertest4.com|anothertest4.com>",
"<http://anothertest5.com|anothertest5.com>"
]
}
Can you help me figure it out?