Skip to content

Instantly share code, notes, and snippets.

View jomaora's full-sized avatar

Joan Ortega jomaora

  • Bloomays
  • Paris
View GitHub Profile
'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;
@jomaora
jomaora / tava.js
Last active February 15, 2019 13:47
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
// 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
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'};
}
};
'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);
};
@jomaora
jomaora / T.js
Last active February 14, 2019 16:21
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);
@jomaora
jomaora / basemodel.js
Created April 7, 2016 17:22
Parsing MySQL TINYINT to Boolean using Bookshelf NodeJS
'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];