@@ -23,9 +23,9 @@ const { ObjectID } = require('mongodb');
2323
2424/**
2525 * @typedef {Object } EventsFilters
26- * @property {boolean } [starred]
27- * @property {boolean } [resolved]
28- * @property {boolean } [ignored]
26+ * @property {boolean } [starred] - if true, events with 'starred' mark should be included to the output
27+ * @property {boolean } [resolved] - if true, events with 'resolved' should be included to the output
28+ * @property {boolean } [ignored] - if true, events with 'ignored' mark should be included to the output
2929 * @property {string|number } [dateFrom]
3030 * @property {string|number } [dateTo]
3131 */
@@ -167,6 +167,9 @@ class EventsFactory extends Factory {
167167 throw new Error ( 'Search parameter must be a string' ) ;
168168 }
169169
170+ /**
171+ * Check if pattern is safe RegExp
172+ */
170173 if ( ! safe ( search ) ) {
171174 throw new Error ( 'Invalid regular expression pattern' ) ;
172175 }
@@ -234,7 +237,6 @@ class EventsFactory extends Factory {
234237 ...searchFilter ,
235238 } ;
236239
237- // Filter by marks (event.marks.{key})
238240 [ 'starred' , 'resolved' , 'ignored' ] . forEach ( ( mark ) => {
239241 if ( typeof filters [ mark ] === 'boolean' ) {
240242 matchFilter [ `event.marks.${ mark } ` ] = { $exists : filters [ mark ] } ;
@@ -298,6 +300,14 @@ class EventsFactory extends Factory {
298300 const cursor = this . getCollection ( this . TYPES . DAILY_EVENTS ) . aggregate ( pipeline ) ;
299301 const result = ( await cursor . toArray ( ) ) . shift ( ) ;
300302
303+ /**
304+ * aggregation can return empty array so that
305+ * result can be undefined
306+ *
307+ * for that we check result existence
308+ *
309+ * extra field `projectId` needs to satisfy GraphQL query
310+ */
301311 if ( result && result . events ) {
302312 result . events . forEach ( event => {
303313 event . projectId = this . projectId ;
0 commit comments