controller.js
const extend = require("extend"); const logger = require("../../helpers/logger"); const mongoose = require("mongoose"); const zanzar = require("../../mongo"); const controllerActions = {}; const customMethods = { perquisar: async (req, res) => { logger.info("Dashboard :: "); await zanzar .find() .then((result) => { res.status(200).send(result); logger.info("Dashboard :: result :: " + result.length); }) .catch((error) => { logger.info({ error: error.message, stack: error.stack }); res.status(400).json("Erro ao montar informações do gráfico !"); }); }, listarCampanhas: async (req, res) => { logger.info("listarCampanhas :: "); await mongoose .model("dashboards") .find() .then((result) => { res.status(200).send(result); logger.info("listarCampanhas :: result :: " + result.length); }) .catch((error) => { logger.info({ error: error.message, stack: error.stack }); res.status(400).json("Erro buscar lista de campanhas !"); }); }, }; extend(controllerActions, customMethods); module.exports = controllerActions;
mongo.js
const mongoose = require("mongoose"); const logger = require("./helpers/logger"); mongoose.Promise = global.Promise; mongoose .connect("mongodb://127.0.0.1:27017/zanzar", { useNewUrlParser: true }) .then(() => logger.info("mongodb conectado :: ")) .catch((erro) => logger.error(erro)); const Zanzar = new mongoose.Schema({ data_hora: { type: Date, required: true, }, nome_campanha: { type: String, required: true, }, idCampanha: { type: Number, required: true, }, idEvento: { type: String, required: true, }, idPlayer: { type: Number, required: true, }, latitude: { type: Number, required: true, }, longitude: { type: Number, required: true, }, nomePlayer: { type: Number, required: true, }, }); module.exports = { Mongoose: mongoose, zanzar: Zanzar }