From cb6e84dab26bd04572aeb685a55d19ca7e0d115c Mon Sep 17 00:00:00 2001 From: nannal Date: Wed, 7 Oct 2020 18:57:40 +0300 Subject: [PATCH] Limited arr length to 1 --- index.js | 1 - listManager.js | 11 +++++++++-- users.js | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 81a0473..0a3270e 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,6 @@ const express = require('express') const bodyParser = require('body-parser'); const list = require("./listManager.js"); -const { response } = require('express'); const app = express() app.use(bodyParser.json(),function (req, res, next) { diff --git a/listManager.js b/listManager.js index 69e5ef6..43728d4 100644 --- a/listManager.js +++ b/listManager.js @@ -48,13 +48,20 @@ list = { return await mongo.get("list","list",{"status": status}) }, 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) => { ver = await verifyMsg(obj) if (ver == true) { 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"} } else { return ver diff --git a/users.js b/users.js index 4cd50ae..86cbc4b 100644 --- a/users.js +++ b/users.js @@ -1,3 +1,3 @@ -users = ["nannal", "hightouch"] +users = ["nannal", "hightouch", "heimindanger"] module.exports = users \ No newline at end of file