Added models
This commit is contained in:
parent
aa0619b124
commit
b9469d89b5
3 changed files with 70 additions and 0 deletions
15
models/Histories.js
Normal file
15
models/Histories.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
module.exports = mongoose => {
|
||||||
|
const schema = new mongoose.Schema({
|
||||||
|
radio: String,
|
||||||
|
artist: String,
|
||||||
|
title: String,
|
||||||
|
createdAt: {
|
||||||
|
type: Date,
|
||||||
|
default: Date.now
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const Histories = mongoose.model('Histories', schema)
|
||||||
|
|
||||||
|
return Histories
|
||||||
|
}
|
14
models/Notifications.js
Normal file
14
models/Notifications.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
module.exports = mongoose => {
|
||||||
|
const schema = new mongoose.Schema({
|
||||||
|
user: String,
|
||||||
|
property: {
|
||||||
|
type: String,
|
||||||
|
enum: ['artist', 'title']
|
||||||
|
},
|
||||||
|
value: String
|
||||||
|
})
|
||||||
|
|
||||||
|
const Notifications = mongoose.model('Notifications', schema)
|
||||||
|
|
||||||
|
return Notifications
|
||||||
|
}
|
41
models/index.js
Normal file
41
models/index.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
const mongoose = require('mongoose')
|
||||||
|
|
||||||
|
const basename = path.basename(__filename)
|
||||||
|
|
||||||
|
mongoose.set('useNewUrlParser', true)
|
||||||
|
mongoose.set('useUnifiedTopology', true)
|
||||||
|
mongoose.set('useFindAndModify', false)
|
||||||
|
mongoose.set('useCreateIndex', true)
|
||||||
|
mongoose.set('debug', true)
|
||||||
|
|
||||||
|
mongoose.connect(process.env.MONGO_URL)
|
||||||
|
|
||||||
|
const db = mongoose.connection
|
||||||
|
|
||||||
|
const getSchemas = () => {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
db.on('error', console.error.bind(console, 'Mongodb connection error:'))
|
||||||
|
|
||||||
|
const models = getSchemas()
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
models: models,
|
||||||
|
mongoose: mongoose
|
||||||
|
}
|
Loading…
Reference in a new issue