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
'use strict' | |
var MongoClient = require('mongodb').MongoClient; | |
var url = 'mongodb://localhost:27020'; | |
const findCourse = async (db, courseName) => { | |
const course = await db.collection('courses').findOne({name: courseName}); | |
if (!course) { | |
throw new Error('Course not found'); | |
} | |
return course; |
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
test('POST /repository/demo3/skills > should get 201 and create a new ressource', async t => { | |
const body = { | |
ref: '123', | |
locales: { | |
fr: {name: 'Littérature'}, | |
en: {name: 'Literature'} | |
} | |
}; | |
const app = createServer(); // function having the express application with the exegesis-swagger |
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
// supossing a POST to /repository/{repository}/skills | |
const skillsPOST = async context => { | |
try { | |
const {params, req} = exegesisContext; | |
const repository = params.path.repository; | |
const {res, next, body} = req; | |
const newSkill = await createSkill(body); // my DAO fonction | |
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
const sessionAuthenticator = ({jwt: config}) => async (pluginContext, info) => { | |
try { | |
const params = await pluginContext.getParams(); | |
const apiToken = _.get('authorization', pluginContext.req.headers); | |
// Business logic for authorization | |
return {type: 'success', user: pluginContext.req.user}; | |
} catch (err) { | |
return {type: 'invalid', statusCode: 401, message: 'Invalid or missing authorization key'}; | |
} | |
}; |
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
'use strict'; | |
module.exports.getWeather = (req, res, next) => { | |
const requestData = { | |
search: req.swagger.params.location.value, //instead of req.params.location | |
degreeType: req.swagger.params.unit.value //instead of req.query.unit | |
} | |
res.send(requestData); | |
}; |
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
var swaggerDoc = require('./api/swagger.json'); | |
swaggerTools.initializeMiddleware(swaggerDoc, middleware => { | |
app.use(middleware.swaggerValidator()); | |
app.use(middleware.swaggerRouter({ | |
controllers: './controllers' // your folder with your middleware endpoints | |
})); | |
http.createServer(app).listen(serverPort, () => { | |
console.log('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort); |
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
'use strict'; | |
const _ = require('lodash'); | |
const bookshelf = require('../bookshelf'); | |
const model = bookshelf.Model.extend( | |
{ | |
parse: function (attrs) { | |
_.forEach(this.booleanFields || [], (field) => { | |
attrs[field] = !!attrs[field]; |