@@ -7,30 +7,45 @@ const g_db = require("@arangodb").db;
77const g_lib = require ( "./support" ) ;
88const error = require ( "./lib/error_codes" ) ;
99const permissions = require ( "./lib/permissions" ) ;
10-
10+ const basePath = "note" ;
11+ const logger = require ( "./lib/logger" ) ;
1112module . exports = router ;
1213
1314//==================== ACL API FUNCTIONS
1415
1516router
1617 . post ( "/create" , function ( req , res ) {
17- console . log ( "note/create" ) ;
18+
19+ var client = null ;
20+ var doc = null ;
1821 try {
22+ client = req . queryParams . client
23+ ? g_lib . getUserFromClientID ( req . queryParams . client )
24+ : null ;
25+
26+ logger . logRequestStarted ( {
27+ client : client ?. _id ,
28+ correlationId : req . headers [ "x-correlation-id" ] ,
29+ httpVerb : "POST" ,
30+ routePath : basePath + "/create" ,
31+ status : "Started" ,
32+ description : "Create an annotation on an object" ,
33+ } ) ;
34+
1935 g_db . _executeTransaction ( {
2036 collections : {
2137 read : [ "u" , "uuid" , "accn" , "d" , "c" ] ,
2238 write : [ "d" , "n" , "note" ] ,
2339 } ,
2440 action : function ( ) {
25- const client = g_lib . getUserFromClientID ( req . queryParams . client ) ;
26- var id = g_lib . resolveDataCollID ( req . queryParams . subject , client ) ,
27- doc = g_db . _document ( id ) ;
41+ client = g_lib . getUserFromClientID ( req . queryParams . client ) ;
42+ var id = g_lib . resolveDataCollID ( req . queryParams . subject , client ) ;
43+ doc = g_db . _document ( id ) ;
2844
2945 if ( ! permissions . hasAdminPermObject ( client , id ) ) {
3046 if (
3147 ( permissions . getPermissions ( client , doc , permissions . PERM_RD_REC ) &
32- permissions . PERM_RD_REC ) ==
33- 0
48+ permissions . PERM_RD_REC ) == 0
3449 ) {
3550 throw error . ERR_PERM_DENIED ;
3651 }
@@ -87,9 +102,28 @@ router
87102 results : [ note . new ] ,
88103 updates : Object . values ( updates ) ,
89104 } ) ;
105+ logger . logRequestSuccess ( {
106+ client : client ?. _id ,
107+ correlationId : req . headers [ "x-correlation-id" ] ,
108+ httpVerb : "POST" ,
109+ routePath : basePath + "/create" ,
110+ status : "Success" ,
111+ description : "Create an annotation on an object" ,
112+ extra : doc
113+ } ) ;
90114 } ,
91115 } ) ;
92116 } catch ( e ) {
117+ logger . logRequestFailure ( {
118+ client : client ?. _id ,
119+ correlationId : req . headers [ "x-correlation-id" ] ,
120+ httpVerb : "POST" ,
121+ routePath : basePath + "/create" ,
122+ status : "Failure" ,
123+ description : "Create an annotation on an object" ,
124+ extra : doc ,
125+ error : e
126+ } ) ;
93127 g_lib . handleException ( e , res ) ;
94128 }
95129 } )
@@ -108,15 +142,25 @@ router
108142
109143router
110144 . post ( "/update" , function ( req , res ) {
111- console . log ( "note/update" ) ;
145+ var client = null ;
112146 try {
147+ client = g_lib . getUserFromClientID ( req . queryParams . client ) ;
148+ logger . logRequestStarted ( {
149+ client : client ?. _id ,
150+ correlationId : req . headers [ "x-correlation-id" ] ,
151+ httpVerb : "POST" ,
152+ routePath : basePath + "/update" ,
153+ status : "Started" ,
154+ description : "Update an annotation" ,
155+ } ) ;
156+
113157 g_db . _executeTransaction ( {
114158 collections : {
115159 read : [ "u" , "uuid" , "accn" ] ,
116160 write : [ "d" , "n" , "note" ] ,
117161 } ,
118162 action : function ( ) {
119- const client = g_lib . getUserFromClientID ( req . queryParams . client ) ;
163+ client = g_lib . getUserFromClientID ( req . queryParams . client ) ;
120164
121165 if ( ! req . queryParams . id . startsWith ( "n/" ) )
122166 throw [
@@ -232,9 +276,29 @@ router
232276 results : [ note ] ,
233277 updates : Object . values ( updates ) ,
234278 } ) ;
279+
280+ logger . logRequestSuccess ( {
281+ client : client ?. _id ,
282+ correlationId : req . headers [ "x-correlation-id" ] ,
283+ httpVerb : "POST" ,
284+ routePath : basePath + "/update" ,
285+ status : "Success" ,
286+ description : "Update an annotation" ,
287+ extra : doc
288+ } ) ;
235289 } ,
236290 } ) ;
237291 } catch ( e ) {
292+ logger . logRequestFailure ( {
293+ client : client ?. _id ,
294+ correlationId : req . headers [ "x-correlation-id" ] ,
295+ httpVerb : "POST" ,
296+ routePath : basePath + "/update" ,
297+ status : "Failure" ,
298+ description : "Update an annotation" ,
299+ extra : doc ,
300+ error : e
301+ } ) ;
238302 g_lib . handleException ( e , res ) ;
239303 }
240304 } )
@@ -253,14 +317,26 @@ router
253317
254318router
255319 . post ( "/comment/edit" , function ( req , res ) {
320+ var client = null ;
321+ var note = null ;
256322 try {
323+ client = g_lib . getUserFromClientID ( req . queryParams . client ) ;
324+ logger . logRequestStarted ( {
325+ client : client ?. _id ,
326+ correlationId : req . headers [ "x-correlation-id" ] ,
327+ httpVerb : "POST" ,
328+ routePath : basePath + "/comment/edit" ,
329+ status : "Started" ,
330+ description : "Edit an annotation comment"
331+ } ) ;
332+
257333 g_db . _executeTransaction ( {
258334 collections : {
259335 read : [ "u" , "uuid" , "accn" ] ,
260336 write : [ "n" ] ,
261337 } ,
262338 action : function ( ) {
263- const client = g_lib . getUserFromClientID ( req . queryParams . client ) ;
339+ client = g_lib . getUserFromClientID ( req . queryParams . client ) ;
264340
265341 if ( ! req . queryParams . id . startsWith ( "n/" ) )
266342 throw [
@@ -274,7 +350,7 @@ router
274350 "Annotaion ID '" + req . queryParams . id + "' does not exist." ,
275351 ] ;
276352
277- var note = g_db . n . document ( req . queryParams . id ) ;
353+ note = g_db . n . document ( req . queryParams . id ) ;
278354
279355 if ( req . queryParams . comment_idx >= note . comments . length )
280356 throw [ error . ERR_INVALID_PARAM , "Comment index out of range." ] ;
@@ -300,9 +376,28 @@ router
300376 res . send ( {
301377 results : [ note . new ] ,
302378 } ) ;
379+ logger . logRequestSuccess ( {
380+ client : client ?. _id ,
381+ correlationId : req . headers [ "x-correlation-id" ] ,
382+ httpVerb : "POST" ,
383+ routePath : basePath + "/comment/edit" ,
384+ status : "Success" ,
385+ description : "Edit an annotation comment" ,
386+ extra : note
387+ } ) ;
303388 } ,
304389 } ) ;
305390 } catch ( e ) {
391+ logger . logRequestSuccess ( {
392+ client : client ?. _id ,
393+ correlationId : req . headers [ "x-correlation-id" ] ,
394+ httpVerb : "POST" ,
395+ routePath : basePath + "/comment/edit" ,
396+ status : "Success" ,
397+ description : "Edit an annotation comment" ,
398+ extra : note ,
399+ error : e
400+ } ) ;
306401 g_lib . handleException ( e , res ) ;
307402 }
308403 } )
@@ -315,8 +410,17 @@ router
315410
316411router
317412 . get ( "/view" , function ( req , res ) {
413+ var client = null ;
318414 try {
319- const client = g_lib . getUserFromClientID_noexcept ( req . queryParams . client ) ;
415+ client = g_lib . getUserFromClientID_noexcept ( req . queryParams . client ) ;
416+ logger . logRequestStarted ( {
417+ client : client ?. _id ,
418+ correlationId : req . headers [ "x-correlation-id" ] ,
419+ httpVerb : "GET" ,
420+ routePath : basePath + "/view" ,
421+ status : "Started" ,
422+ description : "Edit an annotation comment"
423+ } ) ;
320424
321425 if ( ! req . queryParams . id . startsWith ( "n/" ) )
322426 throw [
@@ -369,7 +473,28 @@ router
369473 res . send ( {
370474 results : [ note ] ,
371475 } ) ;
476+ logger . logRequestSuccess ( {
477+ client : client ?. _id ,
478+ correlationId : req . headers [ "x-correlation-id" ] ,
479+ httpVerb : "GET" ,
480+ routePath : basePath + "/view" ,
481+ status : "Success" ,
482+ description : "View annotation" ,
483+ extra : note ,
484+ } ) ;
485+
372486 } catch ( e ) {
487+ logger . logRequestFailure ( {
488+ client : client ?. _id ,
489+ correlationId : req . headers [ "x-correlation-id" ] ,
490+ httpVerb : "GET" ,
491+ routePath : basePath + "/view" ,
492+ status : "Failure" ,
493+ description : "View annotation" ,
494+ extra : note ,
495+ error : e
496+ } ) ;
497+
373498 g_lib . handleException ( e , res ) ;
374499 }
375500 } )
@@ -380,8 +505,17 @@ router
380505
381506router
382507 . get ( "/list/by_subject" , function ( req , res ) {
508+ let client = null ;
383509 try {
384- const client = g_lib . getUserFromClientID_noexcept ( req . queryParams . client ) ;
510+ client = g_lib . getUserFromClientID_noexcept ( req . queryParams . client ) ;
511+ logger . logRequestStarted ( {
512+ client : client ?. _id ,
513+ correlationId : req . headers [ "x-correlation-id" ] ,
514+ httpVerb : "GET" ,
515+ routePath : basePath + "/list/by_subject" ,
516+ status : "Started" ,
517+ description : "List annotations by subject"
518+ } ) ;
385519
386520 var results ,
387521 qry ,
@@ -411,7 +545,26 @@ router
411545 res . send ( {
412546 results : results . toArray ( ) ,
413547 } ) ;
548+ logger . logRequestSuccess ( {
549+ client : client ?. _id ,
550+ correlationId : req . headers [ "x-correlation-id" ] ,
551+ httpVerb : "GET" ,
552+ routePath : basePath + "/list/by_subject" ,
553+ status : "Success" ,
554+ description : "List annotations by subject" ,
555+ extra : results . toArray ( )
556+ } ) ;
414557 } catch ( e ) {
558+ logger . logRequestFailure ( {
559+ client : client ?. _id ,
560+ correlationId : req . headers [ "x-correlation-id" ] ,
561+ httpVerb : "GET" ,
562+ routePath : basePath + "/list/by_subject" ,
563+ status : "Failure" ,
564+ description : "List annotations by subject" ,
565+ extra : results . toArray ( ) ,
566+ error : e
567+ } ) ;
415568 g_lib . handleException ( e , res ) ;
416569 }
417570 } )
@@ -422,7 +575,19 @@ router
422575
423576router
424577 . get ( "/purge" , function ( req , res ) {
578+ let client = null ;
579+ let id = null ;
425580 try {
581+ client = g_lib . getUserFromClientID_noexcept ( req . queryParams . client ) ;
582+ logger . logRequestStarted ( {
583+ client : client ?. _id ,
584+ correlationId : req . headers [ "x-correlation-id" ] ,
585+ httpVerb : "GET" ,
586+ routePath : basePath + "/purge" ,
587+ status : "Started" ,
588+ description : "Purge old closed annotations" ,
589+ } ) ;
590+
426591 g_db . _executeTransaction ( {
427592 collections : {
428593 read : [ "u" , "uuid" , "accn" ] ,
@@ -432,8 +597,9 @@ router
432597 //console.log("note purge, age:", req.queryParams.age_sec );
433598
434599 var t = Date . now ( ) / 1000 - req . queryParams . age_sec ;
435- var id ,
436- notes = g_db . _query (
600+
601+ //maybe id = below
602+ var notes = g_db . _query (
437603 "for i in n filter i.state == " +
438604 g_lib . NOTE_CLOSED +
439605 " && i.ut < " +
@@ -447,8 +613,28 @@ router
447613 g_lib . annotationDelete ( id ) ;
448614 }
449615 } ,
616+
617+ } ) ;
618+ logger . logRequestSuccess ( {
619+ client : client ?. _id ,
620+ correlationId : req . headers [ "x-correlation-id" ] ,
621+ httpVerb : "GET" ,
622+ routePath : basePath + "/purge" ,
623+ status : "Success" ,
624+ description : "Purge old closed annotations" ,
625+ extra : `Id of purged note: ${ id } `
450626 } ) ;
451627 } catch ( e ) {
628+ logger . logRequestFailure ( {
629+ client : client ?. _id ,
630+ correlationId : req . headers [ "x-correlation-id" ] ,
631+ httpVerb : "GET" ,
632+ routePath : basePath + "/purge" ,
633+ status : "Failure" ,
634+ description : "Purge old closed annotations" ,
635+ extra : id ,
636+ error : e
637+ } ) ;
452638 g_lib . handleException ( e , res ) ;
453639 }
454640 } )
0 commit comments