Limited arr length to 1

This commit is contained in:
nannal 2020-10-07 18:57:40 +03:00
parent e12739b781
commit cb6e84dab2
3 changed files with 10 additions and 4 deletions

View File

@ -1,7 +1,6 @@
const express = require('express') const express = require('express')
const bodyParser = require('body-parser'); const bodyParser = require('body-parser');
const list = require("./listManager.js"); const list = require("./listManager.js");
const { response } = require('express');
const app = express() const app = express()
app.use(bodyParser.json(),function (req, res, next) { app.use(bodyParser.json(),function (req, res, next) {

View File

@ -48,13 +48,20 @@ list = {
return await mongo.get("list","list",{"status": status}) return await mongo.get("list","list",{"status": status})
}, },
getUser: async (username) => { getUser: async (username) => {
return await mongo.get("list","list",{"user": username}) res = await mongo.get("list","list",{"user": username})
return res[0]
}, },
writeUser: async (obj) => { writeUser: async (obj) => {
ver = await verifyMsg(obj) ver = await verifyMsg(obj)
if (ver == true) { if (ver == true) {
console.log(obj) console.log(obj)
mongo.put("list","list",obj) res = await mongo.get("list","list",{"user": obj.user})
if (res.length > 0 ){
mongo.update("list","list",{"user": obj.user}, obj)
} else {
mongo.put("list","list", obj)
}
mongo.update("list","list",{"user": obj.user}, obj)
return {"Message":"Success"} return {"Message":"Success"}
} else { } else {
return ver return ver

View File

@ -1,3 +1,3 @@
users = ["nannal", "hightouch"] users = ["nannal", "hightouch", "heimindanger"]
module.exports = users module.exports = users