mongoose + tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const getAnswer = (errors, data, success = true) => {
|
||||
exports.getAnswer = (errors, data, success = true) => {
|
||||
if (errors) {
|
||||
return {
|
||||
success: false,
|
||||
@@ -12,7 +12,7 @@ const getAnswer = (errors, data, success = true) => {
|
||||
}
|
||||
}
|
||||
|
||||
const getResponse = (errors, data, success = true) => {
|
||||
exports.getResponse = (errors, data, success = true) => {
|
||||
if (errors.length) {
|
||||
return {
|
||||
success: false,
|
||||
@@ -28,8 +28,3 @@ const getResponse = (errors, data, success = true) => {
|
||||
warnings: [],
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getAnswer,
|
||||
getResponse,
|
||||
}
|
||||
|
||||
4
server/utils/const.js
Normal file
4
server/utils/const.js
Normal file
@@ -0,0 +1,4 @@
|
||||
const rc = require('../../.serverrc')
|
||||
|
||||
// Connection URL
|
||||
exports.mongoUrl = `mongodb://${rc.mongoAddr}:${rc.mongoPort}`
|
||||
@@ -1,15 +1,13 @@
|
||||
const MDBClient = require('mongodb').MongoClient
|
||||
|
||||
const rc = require('../../.serverrc')
|
||||
|
||||
// Connection URL
|
||||
const url = `mongodb://${rc.mongoAddr}:${rc.mongoPort}`
|
||||
const { mongoUrl } = require('./const')
|
||||
|
||||
const dbInstanses = {
|
||||
}
|
||||
|
||||
const mongoDBConnect = async () => {
|
||||
try {
|
||||
const MongoClient = new MDBClient(url, {
|
||||
const MongoClient = new MDBClient(mongoUrl, {
|
||||
useUnifiedTopology: true,
|
||||
})
|
||||
return await MongoClient.connect()
|
||||
|
||||
5
server/utils/mongoose.js
Normal file
5
server/utils/mongoose.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
const { mongoUrl } = require('./const')
|
||||
|
||||
mongoose.connect(`${mongoUrl}/mongoose`)
|
||||
Reference in New Issue
Block a user