Natsuha
Natsuha
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
Now this works now
export const GET = async (req: Request) => {
try {
const allTopic: Topic[] = await prisma.topic.findMany({
include: { course: { include: { team: true, author: true } } },
});
//logic here

return NextResponse.json({ allTopic }, { status: 200 });
} catch (error) {
//error handling
console.log(error);
return NextResponse.json({ message: "Server Error" }, { status: 500 });
} finally {
await prisma.$disconnect();
}
};
export const GET = async (req: Request) => {
try {
const allTopic: Topic[] = await prisma.topic.findMany({
include: { course: { include: { team: true, author: true } } },
});
//logic here

return NextResponse.json({ allTopic }, { status: 200 });
} catch (error) {
//error handling
console.log(error);
return NextResponse.json({ message: "Server Error" }, { status: 500 });
} finally {
await prisma.$disconnect();
}
};
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
password String @unique
fullName String @unique
userName String @unique
businessDetails BusinessDetails?
role Role

team Team @relation(fields: [teamId], references: [id])
teamId String @db.ObjectId

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

Course Course[]
}

model Team {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Course Course[]
User User[]
}

model Course {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String

team Team @relation(fields: [teamId], references: [id])
teamId String @db.ObjectId
author User @relation(fields: [authorId], references: [id])
authorId String @db.ObjectId

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Topic Topic[]
}

model Topic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String

course Course @relation(fields: [courseId], references: [id])
courseId String @db.ObjectId

subTopics SubTopic[]
steps Step[]
media Media

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

type SubTopic {
title String
description String
media Media
}

type Media {
name String
type String
link String
}

type Step {
title String
media Media
}

type BusinessDetails {
subscription String
name String
industryType String
businessType String
employeeNo String
position String
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
password String @unique
fullName String @unique
userName String @unique
businessDetails BusinessDetails?
role Role

team Team @relation(fields: [teamId], references: [id])
teamId String @db.ObjectId

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

Course Course[]
}

model Team {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Course Course[]
User User[]
}

model Course {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String

team Team @relation(fields: [teamId], references: [id])
teamId String @db.ObjectId
author User @relation(fields: [authorId], references: [id])
authorId String @db.ObjectId

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Topic Topic[]
}

model Topic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String

course Course @relation(fields: [courseId], references: [id])
courseId String @db.ObjectId

subTopics SubTopic[]
steps Step[]
media Media

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

type SubTopic {
title String
description String
media Media
}

type Media {
name String
type String
link String
}

type Step {
title String
media Media
}

type BusinessDetails {
subscription String
name String
industryType String
businessType String
employeeNo String
position String
}
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
I see I get it now, I should build the schema from top to bottom I was doing it the other way around
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
The only difference is that Topic is an array
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
But why does authorId/author is working?
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
So I should create a topic first then a subtopic?
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
@Jon Harrell please help
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
Moving forward I can go with this but this still leaves a bad taste in my mouth and almost half the reason that I went with prisma is so that I can avoid this boilerplate of a code
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
But still it gives me this error
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
model Course {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String

topics Topic? @relation(fields: [topicsId], references: [id])
topicsId String[] @db.ObjectId
author User @relation(fields: [authorId], references: [id])
authorId String @db.ObjectId

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

Team Team[]
}

model Topic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String

subTopics SubTopic[]
steps Step[]
media Media

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

Course Course[]
}
model Course {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String

topics Topic? @relation(fields: [topicsId], references: [id])
topicsId String[] @db.ObjectId
author User @relation(fields: [authorId], references: [id])
authorId String @db.ObjectId

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

Team Team[]
}

model Topic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String

subTopics SubTopic[]
steps Step[]
media Media

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

Course Course[]
}
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
I even modified my schema to this so that the only problem I should be worried about is the array of Topics
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
I thought that prisma can do that for me with
const allCourse = await prisma.course.findMany({
include: { author: true, topics: true },
});
const allCourse = await prisma.course.findMany({
include: { author: true, topics: true },
});
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
And this is the result I want
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
"topics": [
{
"subTopics": [
{
"title": "The coffee SubTopic 1",
"description": "Here we have 1 coffee",
"media": {
"name": "",
"type": "",
"link": ""
}
},
{
"title": "The coffee SubTopic 2",
"description": "Here we have 2 coffee",
"media": {
"name": "",
"type": "",
"link": ""
}
}
],
"steps": [
{
"title": "Step 1",
"media": {
"name": "",
"type": "",
"link": ""
}
},
{
"title": "Step 2",
"media": {
"name": "",
"type": "",
"link": ""
}
}
],
"media": {
"name": "",
"type": "",
"link": ""
},
"id": "663e263b94556ca00bd2f298",
"title": "The coffee title",
"createdAt": "2024-05-10T13:50:50.862Z",
"updatedAt": "2024-05-10T13:50:50.862Z"
}
]
}
]
"topics": [
{
"subTopics": [
{
"title": "The coffee SubTopic 1",
"description": "Here we have 1 coffee",
"media": {
"name": "",
"type": "",
"link": ""
}
},
{
"title": "The coffee SubTopic 2",
"description": "Here we have 2 coffee",
"media": {
"name": "",
"type": "",
"link": ""
}
}
],
"steps": [
{
"title": "Step 1",
"media": {
"name": "",
"type": "",
"link": ""
}
},
{
"title": "Step 2",
"media": {
"name": "",
"type": "",
"link": ""
}
}
],
"media": {
"name": "",
"type": "",
"link": ""
},
"id": "663e263b94556ca00bd2f298",
"title": "The coffee title",
"createdAt": "2024-05-10T13:50:50.862Z",
"updatedAt": "2024-05-10T13:50:50.862Z"
}
]
}
]
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
[
{
"id": "663e265f94556ca00bd2f29c",
"title": "The coffee course title",
"topicsId": [
"663e263b94556ca00bd2f298"
],
"authorId": "663e261a94556ca00bd2f294",
"createdAt": "2024-05-10T13:51:27.076Z",
"updatedAt": "2024-05-10T13:51:27.076Z",
"author": {
"id": "663e261a94556ca00bd2f294",
"email": "[email protected]",
"password": "",
"fullName": "Gregory Errl Babela",
"userName": "greg",
"role": "ADMIN",
"createdAt": "2024-05-10T13:50:17.987Z",
"updatedAt": "2024-05-10T13:50:17.987Z",
"businessDetails": null
},
[
{
"id": "663e265f94556ca00bd2f29c",
"title": "The coffee course title",
"topicsId": [
"663e263b94556ca00bd2f298"
],
"authorId": "663e261a94556ca00bd2f294",
"createdAt": "2024-05-10T13:51:27.076Z",
"updatedAt": "2024-05-10T13:51:27.076Z",
"author": {
"id": "663e261a94556ca00bd2f294",
"email": "[email protected]",
"password": "",
"fullName": "Gregory Errl Babela",
"userName": "greg",
"role": "ADMIN",
"createdAt": "2024-05-10T13:50:17.987Z",
"updatedAt": "2024-05-10T13:50:17.987Z",
"businessDetails": null
},
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
export const GET = async () => {
try {
await prisma.$connect();
const allCourse = await prisma.course.findMany({
include: { author: true },
});

let parsedAllCourse: any = allCourse;

parsedAllCourse = Promise.all(
await parsedAllCourse.map(async (course: any, index: any) => {
if (course && course.author) {
course.author.password = "";
}
const topics = await prisma.topic.findMany({
where: { id: { in: course?.topicsId } },
});
course.topics = topics;
return course;
})
);

return NextResponse.json(await parsedAllCourse, { status: 200 });
} catch (error) {
//error handling
console.log(error);
return NextResponse.json({ message: "Server Error" }, { status: 500 });
} finally {
await prisma.$disconnect();
}
};
export const GET = async () => {
try {
await prisma.$connect();
const allCourse = await prisma.course.findMany({
include: { author: true },
});

let parsedAllCourse: any = allCourse;

parsedAllCourse = Promise.all(
await parsedAllCourse.map(async (course: any, index: any) => {
if (course && course.author) {
course.author.password = "";
}
const topics = await prisma.topic.findMany({
where: { id: { in: course?.topicsId } },
});
course.topics = topics;
return course;
})
);

return NextResponse.json(await parsedAllCourse, { status: 200 });
} catch (error) {
//error handling
console.log(error);
return NextResponse.json({ message: "Server Error" }, { status: 500 });
} finally {
await prisma.$disconnect();
}
};
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
Badly need help
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
One parent
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
Only mediaid and authorid is supposed to be only 1 entry
34 replies
PPrisma
Created by GregoryErrl on 5/3/2024 in #help-and-questions
Inconsistent query result: Field topics is required to return data, got `null` instead.
model Course {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String

topics Topic @relation(fields: [topicsId], references: [id])
topicsId String[] @db.ObjectId
author User @relation(fields: [authorId], references: [id])
authorId String @db.ObjectId

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Course {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String

topics Topic @relation(fields: [topicsId], references: [id])
topicsId String[] @db.ObjectId
author User @relation(fields: [authorId], references: [id])
authorId String @db.ObjectId

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
I defined the array on the String[] on topicsid
34 replies