Initial commit

This commit is contained in:
Damien Broqua 2020-03-02 20:50:33 +01:00
parent a13ceef804
commit 8641fc9723
19 changed files with 303532 additions and 0 deletions

42
models/Stations.js Normal file
View file

@ -0,0 +1,42 @@
/**
* Model permettant de bufferiser les events reçus de Kafka
*/
module.exports = mongoose => {
const schema = new mongoose.Schema({
stationId: String,
location: {
type: { type: String },
coordinates: []
},
prices: [
{
gasType: String,
price: Number,
updatedAt: Object
}
],
services: [],
postCode: String,
address: String,
city: String
});
schema.index({ location: "2dsphere" });
const Stations = mongoose.model("Stations", schema);
Stations.createIndexes();
return Stations;
};
// INFO:
/*
schema.location = {
type: 'Point',
coordinates: [
Number(longitude),
Number(latitude)
]
}
*/

37
models/index.js Normal file
View file

@ -0,0 +1,37 @@
/* eslint-disable global-require */
/* eslint-disable import/no-dynamic-require */
import fs from "fs";
import path from "path";
import Mongoose from "mongoose";
import config from "../config";
const basename = path.basename(__filename);
Mongoose.set("useNewUrlParser", true);
Mongoose.set("useFindAndModify", false);
Mongoose.set("useCreateIndex", true);
Mongoose.set("debug", config.mongodbDebug);
Mongoose.connect(config.mongodbUrl, config.mondeDbOptions);
const db = () => {
const m = {};
fs.readdirSync(__dirname)
.filter(file => {
return (
file.indexOf(".") !== 0 && file !== basename && file.slice(-3) === ".js"
);
})
.forEach(file => {
const model = require(path.resolve(__dirname, file))(Mongoose);
m[model.modelName] = model;
});
return m;
};
const models = db();
export const mongoose = Mongoose;
export default models;