Skip to content

Commit d843f3e

Browse files
committed
chore(): type defs
1 parent 5d2d445 commit d843f3e

5 files changed

Lines changed: 96 additions & 9 deletions

File tree

src/models/eventsFactory.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ class EventsFactory extends Factory {
199199
$gte: new ObjectID(paginationCursor),
200200
}
201201
} : {},
202+
},
203+
{
202204
$sort: {
203205
groupingTimestamp: -1,
204206
[sort]: -1,
@@ -296,9 +298,10 @@ class EventsFactory extends Factory {
296298
lastEvent = result.pop();
297299
}
298300

301+
299302
return {
300303
nextCursor: lastEvent ? lastEvent._id.toString() : null,
301-
...result,
304+
dailyEvents: result,
302305
};
303306
}
304307

src/models/projectsFactory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export default class ProjectsFactory extends AbstractModelFactory<ProjectDBSchem
3535
* @param id - user id
3636
*/
3737
public async findById(id: string): Promise<ProjectModel | null> {
38+
console.log('id in data loader', id)
39+
3840
const projectData = await this.dataLoaders.projectById.load(id);
3941

4042
if (!projectData) {

src/resolvers/event.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ module.exports = {
6161
* @return {Promise<UserModel[]> | null}
6262
*/
6363
async visitedBy({ visitedBy, projectId }, _args, { factories, user }) {
64+
console.log('visitedBy, projectId', visitedBy, projectId)
65+
6466
/**
6567
* Crutch for Demo Workspace
6668
*/

src/resolvers/project.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const EventsFactory = require('../models/eventsFactory');
88
const ProjectToWorkspace = require('../models/projectToWorkspace');
99
const { dateFromObjectId } = require('../utils/dates');
1010
const ProjectModel = require('../models/project').default;
11+
const { composeFullRepetitionEvent } = require('../utils/merge');
1112

1213
const EVENTS_GROUP_HASH_INDEX_NAME = 'groupHashUnique';
1314
const REPETITIONS_GROUP_HASH_INDEX_NAME = 'groupHash_hashed';
@@ -289,6 +290,7 @@ module.exports = {
289290
*/
290291
async event(project, { id: eventId }) {
291292
const factory = new EventsFactory(project._id);
293+
292294
const event = await factory.findById(eventId);
293295

294296
if (!event) {
@@ -344,7 +346,7 @@ module.exports = {
344346
*
345347
* @return {Promise<RecentEventSchema[]>}
346348
*/
347-
async dailyEventsPortion(project, { limit, skip, sort, filters, search }) {
349+
async dailyEventsPortion(project, { limit, cursor, sort, filters, search }) {
348350
if (search) {
349351
if (search.length > MAX_SEARCH_QUERY_LENGTH) {
350352
search = search.slice(0, MAX_SEARCH_QUERY_LENGTH);
@@ -353,22 +355,29 @@ module.exports = {
353355

354356
const factory = new EventsFactory(project._id);
355357

356-
// @todo - rename
357-
const res = factory.findRecentDailyEventsWithEventAndRepetition(limit, skip, sort, filters, search);
358+
const dailyEventsPortion = await factory.findRecentDailyEventsWithEventAndRepetition(limit, cursor, sort, filters, search);
358359

359-
res.forEach((dailyEvent) => {
360+
dailyEventsPortion.dailyEvents.forEach((dailyEvent) => {
360361
const dailyEventLatestRepetition = dailyEvent.repetition;
361362
const dailyEventOriginalEvent = dailyEvent.event;
362363

363-
// wait for util implementation
364-
// const mergedRepetition = merge(dailyEventOriginalEvent, dailyEventLatestRepetition);
364+
const mergedRepetition = composeFullRepetitionEvent(dailyEventOriginalEvent, dailyEventLatestRepetition);
365+
const stringifiedId = dailyEvent._id.toString();
366+
367+
365368
delete dailyEvent.repetition;
366369
delete dailyEvent.event;
367-
368-
// dailyEvent.event = mergedRepetition;
370+
delete dailyEvent._id;
371+
372+
dailyEvent.event = mergedRepetition;
373+
dailyEvent.id = stringifiedId;
369374

370375
return dailyEvent;
371376
})
377+
378+
console.log('daily events portion composed, ...[event]', dailyEventsPortion);
379+
380+
return dailyEventsPortion;
372381
},
373382

374383
/**

src/typeDefs/project.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,47 @@ enum EventsSortOrder {
1111
BY_AFFECTED_USERS
1212
}
1313
14+
"""
15+
Pagination cursor of events portion and list of daily events
16+
"""
17+
type DailyEventsPortion {
18+
"""
19+
Cursor to the next portion of the events, null if there are no events left
20+
"""
21+
nextCursor: String
22+
23+
"""
24+
Daily event information
25+
"""
26+
dailyEvents: [DailyEvent]
27+
}
28+
29+
"""
30+
Daily event information with event itself
31+
"""
32+
type DailyEvent {
33+
"""
34+
ID of the daily event
35+
"""
36+
id: ID!
37+
"""
38+
Count of events in this day
39+
"""
40+
count: Int!
41+
"""
42+
Count of the users affected by this event in this day
43+
"""
44+
affectedUsers: Int!
45+
"""
46+
Timestamp of the event grouping
47+
"""
48+
groupingTimestamp: Int!
49+
"""
50+
Event itself
51+
"""
52+
event: Event!
53+
}
54+
1455
"""
1556
Events filters input type
1657
"""
@@ -128,6 +169,36 @@ type Project {
128169
"Search query"
129170
search: String
130171
): RecentEvents
172+
"""
173+
Portion of daily events
174+
"""
175+
dailyEventsPortion(
176+
"""
177+
Maximum number of results
178+
"""
179+
limit: Int! = 50
180+
181+
"""
182+
Next Cursor to fetch next portion of events
183+
"""
184+
nextCursor: String
185+
186+
"""
187+
Events sort order
188+
"""
189+
sort: EventsSortOrder = lastRepetitionTime
190+
191+
"""
192+
Event marks by which events should be sorted
193+
"""
194+
filters: EventsFiltersInput
195+
196+
"""
197+
Search query
198+
"""
199+
search: String
200+
): DailyEventsPortion
201+
131202
"""
132203
Return events that occurred after a certain timestamp
133204
"""

0 commit comments

Comments
 (0)