mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
Added util dir
This commit is contained in:
+1
-1
@@ -19,8 +19,8 @@ async function startServer () {
|
||||
|
||||
// Connect to the Mongo Database.
|
||||
mongoose.Promise = global.Promise
|
||||
await mongoose.connect(config.database, { useNewUrlParser: true })
|
||||
mongoose.set('useCreateIndex', true) // Stop deprecation warning.
|
||||
await mongoose.connect(config.database, { useNewUrlParser: true })
|
||||
|
||||
// MIDDLEWARE START
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
This directory contains utility functions for managing the database.
|
||||
@@ -0,0 +1,36 @@
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
const config = require('../../config')
|
||||
|
||||
const USERNAME = 'test'
|
||||
const PASSWORD = 'pass'
|
||||
|
||||
// Connect to the Mongo Database.
|
||||
mongoose.Promise = global.Promise
|
||||
|
||||
async function addUser () {
|
||||
await mongoose.connect(config.database)
|
||||
|
||||
const User = require('../../src/models/users')
|
||||
|
||||
const userData = {
|
||||
username: USERNAME,
|
||||
password: PASSWORD
|
||||
}
|
||||
|
||||
const user = new User(userData)
|
||||
|
||||
// Enforce default value of 'user'
|
||||
user.type = 'user'
|
||||
|
||||
await user.save()
|
||||
|
||||
await mongoose.connection.close()
|
||||
|
||||
console.log(`User ${USERNAME} created.`)
|
||||
}
|
||||
addUser()
|
||||
|
||||
module.exports = {
|
||||
addUser
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
const config = require('../../config')
|
||||
|
||||
const User = require('../../src/models/users')
|
||||
|
||||
async function getUsers () {
|
||||
// Connect to the Mongo Database.
|
||||
mongoose.Promise = global.Promise
|
||||
mongoose.set('useCreateIndex', true) // Stop deprecation warning.
|
||||
await mongoose.connect(config.database, { useNewUrlParser: true })
|
||||
|
||||
const users = await User.find({}, '-password')
|
||||
console.log(`users: ${JSON.stringify(users, null, 2)}`)
|
||||
|
||||
mongoose.connection.close()
|
||||
}
|
||||
getUsers()
|
||||
@@ -0,0 +1,34 @@
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
const config = require('../config')
|
||||
|
||||
// Connect to the Mongo Database.
|
||||
mongoose.Promise = global.Promise
|
||||
mongoose.connect(config.database, () => {
|
||||
// mongoose.connection.db.dropDatabase()
|
||||
})
|
||||
|
||||
console.log(`config: ${JSON.stringify(config, null, 2)}`)
|
||||
|
||||
/*
|
||||
// Wipe the DB.
|
||||
function cleanDb () {
|
||||
for (const collection in mongoose.connection.collections) {
|
||||
if (mongoose.connection.collections.hasOwnProperty(collection)) {
|
||||
mongoose.connection.collections[collection].remove()
|
||||
}
|
||||
}
|
||||
console.log(`Database wiped.`)
|
||||
}
|
||||
cleanDb()
|
||||
*/
|
||||
|
||||
mongoose.connection.close()
|
||||
|
||||
console.log(`
|
||||
Here's how to wipe the db:
|
||||
1. mongo
|
||||
2. use p2pvps-server-dev
|
||||
3. db.dropDatabase()
|
||||
4. exit
|
||||
`)
|
||||
Reference in New Issue
Block a user