feat(courses): Add lessons
This commit is contained in:
committed by
Benedikt Rötsch
parent
6c7ab31305
commit
e2ceb39e83
@@ -1,9 +1,11 @@
|
||||
const { createClient } = require('contentful')
|
||||
|
||||
let client = null
|
||||
let previewClient = null
|
||||
|
||||
exports.initClient = () => {
|
||||
client = createClient({space: process.env.CF_SPACE, accessToken: process.env.CF_ACCESS_TOKEN})
|
||||
exports.initClient = (config = {space: process.env.CF_SPACE, accessToken: process.env.CF_ACCESS_TOKEN}) => {
|
||||
client = createClient(config)
|
||||
previewClient = createClient({...config, host: 'preview.contentful.com'})
|
||||
}
|
||||
exports.getCourses = () => {
|
||||
// to get all the courses we simply request from Contentful all the entries
|
||||
@@ -11,6 +13,14 @@ exports.getCourses = () => {
|
||||
return client.getEntries({content_type: 'course'})
|
||||
}
|
||||
|
||||
exports.getCourse = (slug) => {
|
||||
// the SDK support link resolution only when you request the collection endpoint
|
||||
// That's why we are using getEntries with a query instead of getEntry(entryId)
|
||||
// make sure to specify the content_type whenever you want to perform a query
|
||||
return client.getEntries({content_type: 'course', 'fields.slug': slug})
|
||||
.then((response) => response.items[0])
|
||||
}
|
||||
|
||||
exports.getLessons = (courseId) => {
|
||||
// TODO
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user