UNPKG

warrior-code-api

Version:
50 lines (40 loc) 940 B
'use strict'; const Boom = require('boom'); const mongoose = require('mongoose'); const Map = mongoose.models.Map; /** * Get the list of campaigns for the current user. */ module.exports.index = (request, reply) => { const mapReduce = { map: function() { emit(this.world, this); } }; Map.mapReduce(mapReduce, (err, data) => { data = data.map((world) => { let o = {}; o[world._id] = world.value; return o; }); reply(data); }); }; /** * Show an existing campaign. */ module.exports.show = (request, reply) => { let worldName = request.params.name; Map.find({world: worldName}, (err, maps) => { // Check if there are errors or no maps. if (err || maps.length < 0) { if (err) console.error(err); return reply(Boom.notFound('World not found')); } // Reply with the list of maps. reply({ name: worldName, maps: maps }); }); };