fix(course): fix non resolved lessons

This commit is contained in:
Khaled Garbaya
2017-09-28 11:25:25 +02:00
committed by Benedikt Rötsch
parent 928ccc0ade
commit 07c5cc77b0
5 changed files with 36 additions and 23 deletions

View File

@@ -1,47 +1,54 @@
const { createClient } = require('contentful')
let client = null
let previewClient = null
let cdaClient = null
let cpaClient = null
exports.initClient = (config = {space: process.env.CF_SPACE, accessToken: process.env.CF_ACCESS_TOKEN}) => {
client = createClient(config)
previewClient = createClient({...config, host: 'preview.contentful.com'})
cdaClient = createClient(config)
cpaClient = createClient({...config, host: 'preview.contentful.com'})
}
exports.getCourses = () => {
exports.getCourses = (locale = 'en-US', api = `cda`) => {
// to get all the courses we simply request from Contentful all the entries
// with the content_type `course`
return client.getEntries({content_type: 'course', include: 10})
const client = api === 'cda' ? cdaClient : cpaClient
return client.getEntries({content_type: 'course', locale, include: 10})
.then((response) => response.items)
}
exports.getLandingPage = () => {
exports.getLandingPage = (locale = 'en-US', api = `cda`) => {
// our Home page is fully configureable via contentful
return client.getEntries({content_type: 'landingPage', 'fields.slug': 'contentful-university', include: 10})
const client = api === 'cda' ? cdaClient : cpaClient
return client.getEntries({content_type: 'landingPage', locale, 'fields.slug': 'contentful-university', include: 10})
.then((response) => response.items[0])
}
exports.getCourse = (slug) => {
exports.getCourse = (slug, locale = 'en-US', api = `cda`) => {
// 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, include: 10})
const client = api === 'cda' ? cdaClient : cpaClient
return client.getEntries({content_type: 'course', 'fields.slug': slug, locale, include: 10})
.then((response) => response.items[0])
}
exports.getLessons = (courseId) => {
exports.getLessons = (courseId, locale = 'en-US', api = `cda`) => {
// TODO
}
exports.getCategories = () => {
return client.getEntries({content_type: 'category'})
exports.getCategories = (locale = 'en-US', api = `cda`) => {
const client = api === 'cda' ? cdaClient : cpaClient
return client.getEntries({content_type: 'category', locale})
.then((response) => response.items)
}
exports.getCoursesByCategory = (category) => {
exports.getCoursesByCategory = (category, locale = 'en-US', api = `cda`) => {
const client = api === 'cda' ? cdaClient : cpaClient
return client.getEntries({
content_type: 'course',
'fields.category.sys.contentType.sys.id': category
'fields.category.sys.contentType.sys.id': category,
locale,
include: 10
})
.then((response) => response.items)
}