fix: Fix previw/delivery switch

This commit is contained in:
Khaled Garbaya
2017-10-16 15:52:01 +02:00
committed by Benedikt Rötsch
parent 3f16c4531c
commit f61c13d02e
7 changed files with 25 additions and 14 deletions

View File

@@ -3,8 +3,11 @@ const { createClient } = require('contentful')
let cdaClient = null
let cpaClient = null
// Initialize our client
exports.initClient = (options) => {
// Getting the version the app version
const { version } = require('../package.json')
const config = options || {
space: process.env.CF_SPACE,
cda: process.env.CF_ACCESS_TOKEN,
@@ -28,9 +31,9 @@ exports.getSpace = assert((api = `cda`) => {
return client.getSpace()
}, 'Space')
// to get all the courses we request all the entries
// with the content_type `course` from Contentful
exports.getCourses = assert((locale = 'en-US', api = `cda`) => {
// to get all the courses we request all the entries
// with the content_type `course` from Contentful
const client = api === 'cda' ? cdaClient : cpaClient
return client.getEntries({
content_type: 'course',
@@ -41,8 +44,8 @@ exports.getCourses = assert((locale = 'en-US', api = `cda`) => {
.then((response) => response.items)
}, 'Course')
// Landing pages like the home or about page are fully controlable via Contentful.
exports.getLandingPage = (slug, locale = 'en-US', api = `cda`) => {
// Landing pages like the home or about page are fully controlable via Contentful.
const client = api === 'cda' ? cdaClient : cpaClient
return client.getEntries({
content_type: 'landingPage',
@@ -53,10 +56,10 @@ exports.getLandingPage = (slug, locale = 'en-US', api = `cda`) => {
.then((response) => response.items[0])
}
// the SDK supports link resolution only when you call the collection endpoints
// 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
exports.getCourse = assert((slug, locale = 'en-US', api = `cda`) => {
// the SDK supports link resolution only when you call the collection endpoints
// 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
const client = api === 'cda' ? cdaClient : cpaClient
return client.getEntries({
content_type: 'course',
@@ -73,6 +76,9 @@ exports.getCategories = assert((locale = 'en-US', api = `cda`) => {
.then((response) => response.items)
}, 'Course')
// Getting a course by Category is simply querying all entries
// with a query params `fields.categories.sys.id` equal to the desired category id
// Note that you need to send the `content_type` param to be able to query the entry
exports.getCoursesByCategory = assert((category, locale = 'en-US', api = `cda`) => {
const client = api === 'cda' ? cdaClient : cpaClient
return client.getEntries({
@@ -85,6 +91,7 @@ exports.getCoursesByCategory = assert((category, locale = 'en-US', api = `cda`)
.then((response) => response.items)
}, 'Category')
// Utitlities functions
function assert (fn, context) {
return function (req, res, next) {
return fn(req, res, next)