generated from theodorusclarence/ts-nextjs-tailwind-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add RandomFact types and schema
- Loading branch information
1 parent
b07fa9a
commit 610fedf
Showing
7 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
import { | ||
falseRandomFactsQuery, | ||
trueRandomFactsQuery, | ||
} from '@/queries/random-facts'; | ||
|
||
import { sanityClient } from '../../../sanity/lib/client'; | ||
|
||
import { RandomFact } from '@/types/RandomFact'; | ||
|
||
const randomFactsApi = async (req: NextApiRequest, res: NextApiResponse) => { | ||
const trueFacts: RandomFact[] = await sanityClient.fetch( | ||
trueRandomFactsQuery | ||
); | ||
|
||
const falseFacts: RandomFact[] = await sanityClient.fetch( | ||
falseRandomFactsQuery | ||
); | ||
|
||
res.status(200).json({ | ||
true: trueFacts, | ||
false: falseFacts, | ||
}); | ||
}; | ||
|
||
export default randomFactsApi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { groq } from 'next-sanity'; | ||
|
||
export const trueRandomFactsQuery = groq` | ||
*[_type == "randomFact" && isFactTrue == true] { | ||
_id, | ||
name, | ||
description | ||
}`; | ||
|
||
export const falseRandomFactsQuery = groq` | ||
*[_type == "randomFact" && isFactTrue == false] { | ||
_id, | ||
name, | ||
description, | ||
explanation | ||
}`; | ||
|
||
export const randomFactsQuery = groq` | ||
*[_type == "randomFact"] { | ||
_id, | ||
name, | ||
description, | ||
isFactTrue | ||
}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { defineField, defineType } from 'sanity'; | ||
|
||
export default defineType({ | ||
name: 'randomFact', | ||
title: 'Random Fact', | ||
type: 'document', | ||
fields: [ | ||
defineField({ | ||
name: 'name', | ||
title: 'Name', | ||
type: 'string', | ||
}), | ||
defineField({ | ||
name: 'headline', | ||
title: 'Headline', | ||
type: 'string', | ||
description: 'What will appear as MC option in the quiz', | ||
}), | ||
defineField({ | ||
name: 'description', | ||
title: 'Description', | ||
type: 'array', | ||
of: [{ type: 'block' }], | ||
}), | ||
defineField({ | ||
name: 'isFactTrue', | ||
title: 'Is fact true?', | ||
type: 'boolean', | ||
initialValue: true, | ||
}), | ||
defineField({ | ||
name: 'explanation', | ||
title: 'Explanation', | ||
type: 'array', | ||
of: [{ type: 'block' }], | ||
}), | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface RandomFact { | ||
_id: string; | ||
name: string; | ||
description: string; | ||
trueFact: boolean; | ||
explanation: string; | ||
} |