@@ -10,13 +10,13 @@ const createProject = function (username, title) {
10
10
reject ( "User not signed in" ) ;
11
11
}
12
12
const db = mongoUtils . getDb ( ) ;
13
- const getUser = db . collection ( 'userData' ) . findOne ( { user : username } ) ;
13
+ const getUser = db . collection ( 'userData' ) . findOne ( { " user.username" : username } ) ;
14
14
getUser . then ( ( usr ) => {
15
15
if ( usr . projectNames . includes ( title ) ) {
16
16
reject ( "Project title already taken" ) ;
17
17
}
18
18
db . collection ( 'userData' ) . updateOne ( {
19
- user : 'username'
19
+ " user.username" : 'username'
20
20
} , {
21
21
$push : { projectNames : title }
22
22
} ) . then ( ( _ ) => {
@@ -36,7 +36,7 @@ const addLog = function (username, activity, projectName) {
36
36
}
37
37
assert ( activity == 'start' || activity == 'end' ) ;
38
38
const db = mongoUtils . getDb ( ) ;
39
- const searchUser = db . collection ( 'userData' ) . findOne ( { user : username } ) ;
39
+ const searchUser = db . collection ( 'userData' ) . findOne ( { " user.username" : username } ) ;
40
40
searchUser . then ( ( result ) => {
41
41
console . log ( result ) ;
42
42
console . log ( projectName ) ;
@@ -47,7 +47,7 @@ const addLog = function (username, activity, projectName) {
47
47
if ( ! result . currentProject ) {
48
48
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 } ;
49
49
insertLogToDb ( log ) ;
50
- db . collection ( 'userData' ) . updateOne ( { user : username } ,
50
+ db . collection ( 'userData' ) . updateOne ( { " user.username" : username } ,
51
51
{
52
52
$set : {
53
53
currentProject : projectName
@@ -58,7 +58,7 @@ const addLog = function (username, activity, projectName) {
58
58
}
59
59
} else {
60
60
if ( result . currentProject ) {
61
- db . collection ( 'userData' ) . findOne ( { user : username } ) . then ( ( result ) => {
61
+ db . collection ( 'userData' ) . findOne ( { " user.username" : username } ) . then ( ( result ) => {
62
62
db . collection ( 'logs' ) . findOne ( { projectName : result . currentProject , finish : null } )
63
63
. then ( ( log ) => {
64
64
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) => {
113
113
const nullifyCurrentProject = ( username ) => {
114
114
const db = mongoUtils . getDb ( ) ;
115
115
db . collection ( 'userData' ) . updateOne ( {
116
- user : username
116
+ " user.username" : username
117
117
} , {
118
118
$set : {
119
119
currentProject : null
@@ -130,7 +130,7 @@ const removeProject = function (username, projectName) {
130
130
}
131
131
const db = mongoUtils . getDb ( ) ;
132
132
db . collection ( 'userData' ) . updateOne ( {
133
- user : username
133
+ " user.username" : username
134
134
} , {
135
135
$pull : {
136
136
projectNames : projectName
@@ -149,8 +149,9 @@ const listProjects = function (username) {
149
149
reject ( "User not signed in" ) ;
150
150
}
151
151
const db = mongoUtils . getDb ( ) ;
152
- db . collection ( 'userData' ) . findOne ( { user : username } )
152
+ db . collection ( 'userData' ) . findOne ( { " user.username" : username } )
153
153
. then ( ( suc ) => {
154
+ console . log ( suc ) ;
154
155
suc . projectNames . forEach ( ( name ) => console . log ( name + '\t' ) ) ;
155
156
resolve ( suc . projectNames ) ;
156
157
} )
@@ -215,6 +216,7 @@ const report = function (username, days) {
215
216
var lastWeek = parseInt ( today ) - days ;
216
217
var lastMonth = thisMonth ;
217
218
var lastYear = thisYear ;
219
+ console . log ( days ) ;
218
220
if ( lastWeek < 1 ) {
219
221
console . log ( "AAAA" ) ;
220
222
lastMonth -- ;
@@ -224,6 +226,7 @@ const report = function (username, days) {
224
226
}
225
227
lastWeek = dateSeverDaysAgoLastMonth ( lastMonth , lastWeek ) ;
226
228
}
229
+ console . log ( `${ lastWeek > 0 } ${ lastMonth > 0 } && ${ lastYear > 0 } && ${ today > 0 } && ${ thisMonth > 0 } && ${ thisYear > 0 } ` )
227
230
assert ( lastWeek > 0 && lastMonth > 0 && lastYear > 0 && today > 0 && thisMonth > 0 && thisYear > 0 ) ;
228
231
db . collection ( 'logs' ) . aggregate ( [
229
232
{ '$match' : {
@@ -260,7 +263,7 @@ const getCurrentProjData = function (username) {
260
263
reject ( "User not signed in" ) ;
261
264
}
262
265
const db = mongoUtils . getDb ( ) ;
263
- db . collection ( 'userData' ) . findOne ( { user : username } ) . then ( ( usr ) => {
266
+ db . collection ( 'userData' ) . findOne ( { " user.username" : username } ) . then ( ( usr ) => {
264
267
if ( usr . currentProject ) {
265
268
console . log ( "Current project: " + usr . currentProject ) ;
266
269
resolve ( "Current project: " + usr . currentProject ) ;
@@ -283,16 +286,17 @@ const signup = function (username) {
283
286
reject ( "User must not be null" ) ;
284
287
}
285
288
const db = mongoUtils . getDb ( ) ;
286
- const checkUserNames = db . collection ( 'userData' ) . findOne ( { user : username } ) ;
289
+ const checkUserNames = db . collection ( 'userData' ) . findOne ( { " user.username" : username } ) ;
287
290
checkUserNames . then ( ( usr ) => {
288
291
console . log ( usr ) ;
289
292
if ( usr ) {
290
293
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 } ) .
293
296
then ( ( _ ) => {
294
297
resolve ( "Username registered" )
295
298
} ) . catch ( ( e ) => reject ( e ) ) ;
299
+ }
296
300
} ) ;
297
301
} )
298
302
) ;
0 commit comments