Inconsistent query result: Field topics is required to return data, got `null` instead.
All data exists in the db but this still happens.
where: {id},
include: {
author: true,
topics: {
include: {
subTopics: {include: {media: true}},
Steps: {include: {media: true}},
media: true,
where: {id},
include: {
author: true,
topics: {
include: {
subTopics: {include: {media: true}},
Steps: {include: {media: true}},
media: true,
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 Topic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
subTopics SubTopic @relation(fields: [subTopicsId], references: [id])
subTopicsId String[] @db.ObjectId
Steps Step @relation(fields: [StepsId], references: [id])
StepsId String[] @db.ObjectId
media Media @relation(fields: [mediaId], references: [id])
mediaId String @db.ObjectId
course Course[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model SubTopic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
description String
media Media @relation(fields: [mediaId], references: [id])
mediaId String @db.ObjectId
Topic Topic[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Step {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
media Media @relation(fields: [mediaId], references: [id])
mediaId String @db.ObjectId
Topic Topic[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Media {
id String @id @default(auto()) @map("_id") @db.ObjectId
fileName String
type String
link String
Step Step[]
SubTopic SubTopic[]
Topic Topic[]
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
}
model Topic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
subTopics SubTopic @relation(fields: [subTopicsId], references: [id])
subTopicsId String[] @db.ObjectId
Steps Step @relation(fields: [StepsId], references: [id])
StepsId String[] @db.ObjectId
media Media @relation(fields: [mediaId], references: [id])
mediaId String @db.ObjectId
course Course[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model SubTopic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
description String
media Media @relation(fields: [mediaId], references: [id])
mediaId String @db.ObjectId
Topic Topic[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Step {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
media Media @relation(fields: [mediaId], references: [id])
mediaId String @db.ObjectId
Topic Topic[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Media {
id String @id @default(auto()) @map("_id") @db.ObjectId
fileName String
type String
link String
Step Step[]
SubTopic SubTopic[]
Topic Topic[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
11 Replies
Could you provide more of your code and the full error message?
Sure, I'm using nextjs api and this is my code for the get request
And this is the first part of the schema
This is the error message
export const GET = async (req: Request) => {
try {
await connectToDatabase();
const allTopics = await prisma.topic.findMany({
include: { media: true, subTopics: { include: { media: true } } },
});
return NextResponse.json({ allTopics }, { status: 200 });
} catch (error) {
//error handling
console.log(error);
return NextResponse.json(
{ message: `Server Error ${error}` },
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
};
export const GET = async (req: Request) => {
try {
await connectToDatabase();
const allTopics = await prisma.topic.findMany({
include: { media: true, subTopics: { include: { media: true } } },
});
return NextResponse.json({ allTopics }, { status: 200 });
} catch (error) {
//error handling
console.log(error);
return NextResponse.json(
{ message: `Server Error ${error}` },
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
};
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
// base schema structure
// model modelName {
// elements
// relationships
// references
// date/time
// }
enum Role {
LEARNER
ADMIN
SUPERADMIN
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
password String @unique
fullName String @unique
userName String @unique
role Role @default(LEARNER)
subscription String?
businessName String?
industryType String?
businessType String?
employeeNo String?
employeeNoss String?
teams Team[]
Course Course[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Team {
id String @id @default(auto()) @map("_id") @db.ObjectId
members User @relation(fields: [membersId], references: [id])
membersId String[] @db.ObjectId
libraries Course @relation(fields: [librariesId], references: [id])
librariesId String[] @db.ObjectId
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
// base schema structure
// model modelName {
// elements
// relationships
// references
// date/time
// }
enum Role {
LEARNER
ADMIN
SUPERADMIN
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
password String @unique
fullName String @unique
userName String @unique
role Role @default(LEARNER)
subscription String?
businessName String?
industryType String?
businessType String?
employeeNo String?
employeeNoss String?
teams Team[]
Course Course[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Team {
id String @id @default(auto()) @map("_id") @db.ObjectId
members User @relation(fields: [membersId], references: [id])
membersId String[] @db.ObjectId
libraries Course @relation(fields: [librariesId], references: [id])
librariesId String[] @db.ObjectId
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
Inconsistent query result: Field subTopics is required to return data, got `null` instead.
at In.handleRequestError (D:\Codes\Devanta\devanta-fe\node_modules\@prisma\client\runtime\library.js:122:7044)
at In.handleAndLogRequestError (D:\Codes\Devanta\devanta-fe\node_modules\@prisma\client\runtime\library.js:122:6188)
at In.request (D:\Codes\Devanta\devanta-fe\node_modules\@prisma\client\runtime\library.js:122:5896)
at async l (D:\Codes\Devanta\devanta-fe\node_modules\@prisma\client\runtime\library.js:127:11167)
at async GET (webpack-internal:///(rsc)/./app/api/topic/route.ts:37:27)
at async D:\Codes\Devanta\devanta-fe\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:53191
at async e_.execute (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:44492)
Inconsistent query result: Field subTopics is required to return data, got `null` instead.
at In.handleRequestError (D:\Codes\Devanta\devanta-fe\node_modules\@prisma\client\runtime\library.js:122:7044)
at In.handleAndLogRequestError (D:\Codes\Devanta\devanta-fe\node_modules\@prisma\client\runtime\library.js:122:6188)
at In.request (D:\Codes\Devanta\devanta-fe\node_modules\@prisma\client\runtime\library.js:122:5896)
at async l (D:\Codes\Devanta\devanta-fe\node_modules\@prisma\client\runtime\library.js:127:11167)
at async GET (webpack-internal:///(rsc)/./app/api/topic/route.ts:37:27)
at async D:\Codes\Devanta\devanta-fe\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:53191
at async e_.execute (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:44492)
at async e_.handle (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:54445)
at async doRender (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\base-server.js:1377:42)
at async cacheEntry.responseCache.get.routeKind (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\base-server.js:1599:28)
at async DevServer.renderToResponseWithComponentsImpl (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\base-server.js:1507:28)
at async DevServer.renderPageComponent (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\base-server.js:1924:24)
at async DevServer.renderToResponseImpl (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\base-server.js:1962:32)
at async DevServer.pipeImpl (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\base-server.js:920:25)
at async NextNodeServer.handleCatchallRenderRequest (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\next-server.js:272:17)
at async DevServer.handleRequestImpl (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\base-server.js:816:17) at async D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\dev\next-dev-server.js:339:20
at async Span.traceAsyncFn (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\trace\trace.js:154:20)
at async DevServer.handleRequest (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\dev\next-dev-server.js:336:24)
at async invokeRender (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\lib\router-server.js:174:21)
at async handleRequest (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\lib\router-server.js:353:24)
at async requestHandlerImpl (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\lib\router-server.js:377:13)
at async Server.requestListener (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\lib\start-server.js:141:13) {
clientVersion: '5.13.0'
}
at async e_.handle (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:54445)
at async doRender (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\base-server.js:1377:42)
at async cacheEntry.responseCache.get.routeKind (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\base-server.js:1599:28)
at async DevServer.renderToResponseWithComponentsImpl (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\base-server.js:1507:28)
at async DevServer.renderPageComponent (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\base-server.js:1924:24)
at async DevServer.renderToResponseImpl (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\base-server.js:1962:32)
at async DevServer.pipeImpl (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\base-server.js:920:25)
at async NextNodeServer.handleCatchallRenderRequest (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\next-server.js:272:17)
at async DevServer.handleRequestImpl (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\base-server.js:816:17) at async D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\dev\next-dev-server.js:339:20
at async Span.traceAsyncFn (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\trace\trace.js:154:20)
at async DevServer.handleRequest (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\dev\next-dev-server.js:336:24)
at async invokeRender (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\lib\router-server.js:174:21)
at async handleRequest (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\lib\router-server.js:353:24)
at async requestHandlerImpl (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\lib\router-server.js:377:13)
at async Server.requestListener (D:\Codes\Devanta\devanta-fe\node_modules\next\dist\server\lib\start-server.js:141:13) {
clientVersion: '5.13.0'
}
Could you also post what your “Topic” model looks like?
Your Course model says a course only has a single Topic, you forgot a
[]
there, but you defined it as an array
Isnt it what is causing the error?model Topic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
subTopics SubTopic @relation(fields: [subTopicsId], references: [id])
subTopicsId String[] @db.ObjectId
Steps Step @relation(fields: [StepsId], references: [id])
StepsId String[] @db.ObjectId
media Media @relation(fields: [mediaId], references: [id])
mediaId String @db.ObjectId
course Course[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Topic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
subTopics SubTopic @relation(fields: [subTopicsId], references: [id])
subTopicsId String[] @db.ObjectId
Steps Step @relation(fields: [StepsId], references: [id])
StepsId String[] @db.ObjectId
media Media @relation(fields: [mediaId], references: [id])
mediaId String @db.ObjectId
course Course[]
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
}
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 see that one topic can have many subtopics. Can a subtopic only have one "parent" topic? or many?
One parent
Badly need help
And this is the result I want
I thought that prisma can do that for me with
I even modified my schema to this so that the only problem I should be worried about is the array of Topics
But still it gives me this error
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
@Jon Harrell please help
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();
}
};
[
{
"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
},
"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"
}
]
}
]
const allCourse = await prisma.course.findMany({
include: { author: true, topics: true },
});
const allCourse = await prisma.course.findMany({
include: { author: true, topics: true },
});
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[]
}
I'm not 100% certain, but I'm fairly sure that your schema is backwards. I see
When I would expect to see
Does that make sense?
model Topic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
subTopics SubTopic @relation(fields: [subTopicsId], references: [id])
subTopicsId String[] @db.ObjectId
.
.
.
}
model Topic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
subTopics SubTopic @relation(fields: [subTopicsId], references: [id])
subTopicsId String[] @db.ObjectId
.
.
.
}
model Topic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
subTopics SubTopic[]
.
.
.
}
model SubTopic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
parentTopic Topic @relation(fields: [parentTopicId], references: [id])
parentTopicId String @db.ObjectId
.
.
.
}
model Topic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
subTopics SubTopic[]
.
.
.
}
model SubTopic {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
parentTopic Topic @relation(fields: [parentTopicId], references: [id])
parentTopicId String @db.ObjectId
.
.
.
}
So I should create a topic first then a subtopic?
But why does authorId/author is working?
The only difference is that Topic is an array
Sorry, there's a lot of different questions here.
I'm trying to resolve the original error you posted: "Inconsistent query result: Field subTopics is required to return data, got
null
instead."
The way to resolve that is to change your schema to what I suggested above. That is to say, have subTopics
be an array of SubTopic
on Topic
and then have parentTopic
and parentTopicId
on SubTopic
to complete the relation.
Are you still having trouble with that part?I see I get it now, I should build the schema from top to bottom I was doing it the other way around
Now this works now
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
}
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();
}
};