Skip to content

Commit ef598d6

Browse files
author
Bogdan Abaev
committed
minor bug fixes
1 parent 5b2614a commit ef598d6

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

server/mongoUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const { MongoClient} = require('mongodb');
33

44
//const connectionUrl = process.env.DB_URL? process.env.DB_URL:'mongodb://mongo:27017/';
5-
const connectionUrl = 'mongodb://mongo:27017/';
5+
const connectionUrl = 'mongodb://127.0.0.1:27017';
66
const database = 'task_manager'
77
var db;
88
var dbClient;

server/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var schema = buildSchema(`
3434
remove(projectName:String!): String!
3535
ls: [String]
3636
current: String!
37-
report: [Report]!
37+
report(days:Int!): [Report]!
3838
}
3939
4040
type Query {
@@ -108,7 +108,7 @@ class TimeTracker{
108108
}
109109

110110
report(days){
111-
var outcome = notes.report(this.username,days);
111+
var outcome = notes.report(this.username,days.days);
112112
return outcome.then((result) => {
113113
console.log(result);
114114
return(result);

server/timeTracker.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ const createProject = function (username, title) {
1010
reject("User not signed in");
1111
}
1212
const db = mongoUtils.getDb();
13-
const getUser = db.collection('userData').findOne({ user: username});
13+
const getUser = db.collection('userData').findOne({ "user.username": username});
1414
getUser.then((usr) => {
1515
if (usr.projectNames.includes(title)) {
1616
reject("Project title already taken");
1717
}
1818
db.collection('userData').updateOne({
19-
user: 'username'
19+
"user.username": 'username'
2020
}, {
2121
$push: { projectNames: title }
2222
}).then((_) => {
@@ -36,7 +36,7 @@ const addLog = function (username, activity, projectName) {
3636
}
3737
assert(activity == 'start' || activity == 'end');
3838
const db = mongoUtils.getDb();
39-
const searchUser = db.collection('userData').findOne({ user: username });
39+
const searchUser = db.collection('userData').findOne({ "user.username": username });
4040
searchUser.then((result) => {
4141
console.log(result);
4242
console.log(projectName);
@@ -47,7 +47,7 @@ const addLog = function (username, activity, projectName) {
4747
if (!result.currentProject) {
4848
log = { user: username, projectName: projectName, start: { year: Number(timestamp('YYYY')), month: Number(timestamp('MM')), day: Number(timestamp('DD')), time: timestamp('HH:mm:ss') }, finish: null, duration: null };
4949
insertLogToDb(log);
50-
db.collection('userData').updateOne({ user: username },
50+
db.collection('userData').updateOne({ "user.username": username },
5151
{
5252
$set: {
5353
currentProject: projectName
@@ -58,7 +58,7 @@ const addLog = function (username, activity, projectName) {
5858
}
5959
} else {
6060
if (result.currentProject) {
61-
db.collection('userData').findOne({ user: username }).then((result) => {
61+
db.collection('userData').findOne({ "user.username": username }).then((result) => {
6262
db.collection('logs').findOne({ projectName: result.currentProject, finish: null })
6363
.then((log) => {
6464
const fin = { year: Number(timestamp('YYYY')), month: Number(timestamp('MM')), day: Number(timestamp('DD')), time: timestamp('HH:mm:ss') };
@@ -113,7 +113,7 @@ const updateLogInDb = (log) => {
113113
const nullifyCurrentProject = (username) => {
114114
const db = mongoUtils.getDb();
115115
db.collection('userData').updateOne({
116-
user: username
116+
"user.username": username
117117
}, {
118118
$set: {
119119
currentProject: null
@@ -130,7 +130,7 @@ const removeProject = function (username, projectName) {
130130
}
131131
const db = mongoUtils.getDb();
132132
db.collection('userData').updateOne({
133-
user: username
133+
"user.username": username
134134
}, {
135135
$pull: {
136136
projectNames: projectName
@@ -149,8 +149,9 @@ const listProjects = function (username) {
149149
reject("User not signed in");
150150
}
151151
const db = mongoUtils.getDb();
152-
db.collection('userData').findOne({ user: username })
152+
db.collection('userData').findOne({ "user.username": username })
153153
.then((suc) => {
154+
console.log(suc);
154155
suc.projectNames.forEach((name) => console.log(name + '\t'));
155156
resolve(suc.projectNames);
156157
})
@@ -215,6 +216,7 @@ const report = function (username, days) {
215216
var lastWeek = parseInt(today) - days;
216217
var lastMonth = thisMonth;
217218
var lastYear = thisYear;
219+
console.log(days);
218220
if (lastWeek < 1) {
219221
console.log("AAAA");
220222
lastMonth--;
@@ -224,6 +226,7 @@ const report = function (username, days) {
224226
}
225227
lastWeek = dateSeverDaysAgoLastMonth(lastMonth, lastWeek);
226228
}
229+
console.log(`${lastWeek > 0} ${lastMonth > 0} && ${lastYear > 0} && ${today>0} && ${thisMonth>0} && ${thisYear>0}`)
227230
assert(lastWeek > 0 && lastMonth > 0 && lastYear > 0 &&today>0 &&thisMonth>0 &&thisYear>0);
228231
db.collection('logs').aggregate([
229232
{'$match': {
@@ -260,7 +263,7 @@ const getCurrentProjData = function (username) {
260263
reject("User not signed in");
261264
}
262265
const db = mongoUtils.getDb();
263-
db.collection('userData').findOne({ user: username }).then((usr) => {
266+
db.collection('userData').findOne({ "user.username": username }).then((usr) => {
264267
if (usr.currentProject) {
265268
console.log("Current project: " + usr.currentProject);
266269
resolve("Current project: " + usr.currentProject);
@@ -283,16 +286,17 @@ const signup = function (username) {
283286
reject("User must not be null");
284287
}
285288
const db = mongoUtils.getDb();
286-
const checkUserNames = db.collection('userData').findOne({ user: username });
289+
const checkUserNames = db.collection('userData').findOne({ "user.username": username});
287290
checkUserNames.then((usr) => {
288291
console.log(usr);
289292
if (usr) {
290293
reject("Username already exists");
291-
}
292-
db.collection('userData').insertOne({ user: username, projectNames: [], currentProject: null }).
294+
} else {
295+
db.collection('userData').insertOne({ user: username, projectNames: [], currentProject: null }).
293296
then((_) => {
294297
resolve("Username registered")
295298
}).catch((e) => reject(e));
299+
}
296300
});
297301
})
298302
);

0 commit comments

Comments
 (0)