Skip to content

Commit 1e13972

Browse files
committed
fix: lint
1 parent 57582bd commit 1e13972

4 files changed

Lines changed: 48 additions & 72 deletions

File tree

src/models/eventsFactory.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class EventsFactory extends Factory {
9595

9696
/**
9797
* Creates Event instance
98-
* @param {ObjectId} projectId
98+
* @param {ObjectId} projectId - project id
9999
*/
100100
constructor(projectId) {
101101
super();
@@ -948,7 +948,7 @@ class EventsFactory extends Factory {
948948

949949
return {
950950
updatedEventIds,
951-
failedEventIds: [ ...new Set([ ...failedEventIds, ...failedByUpdate ]) ],
951+
failedEventIds: this._mergeFailedEventIds(failedEventIds, failedByUpdate),
952952
};
953953
}
954954

@@ -1068,7 +1068,7 @@ class EventsFactory extends Factory {
10681068

10691069
return {
10701070
updatedEventIds,
1071-
failedEventIds: [ ...new Set([ ...failedEventIds, ...failedByUpdate ]) ],
1071+
failedEventIds: this._mergeFailedEventIds(failedEventIds, failedByUpdate),
10721072
};
10731073
}
10741074

@@ -1088,6 +1088,7 @@ class EventsFactory extends Factory {
10881088

10891089
const normalizedAssignee = assignee ? String(assignee) : '';
10901090
const docsToUpdate = found.filter(doc => String(doc.assignee || '') !== normalizedAssignee);
1091+
10911092
if (docsToUpdate.length === 0) {
10921093
return {
10931094
updatedEventIds: [],
@@ -1132,7 +1133,7 @@ class EventsFactory extends Factory {
11321133

11331134
return {
11341135
updatedEventIds,
1135-
failedEventIds: [ ...new Set([ ...failedEventIds, ...failedByUpdate ]) ],
1136+
failedEventIds: this._mergeFailedEventIds(failedEventIds, failedByUpdate),
11361137
};
11371138
}
11381139

@@ -1207,6 +1208,23 @@ class EventsFactory extends Factory {
12071208
};
12081209
}
12091210

1211+
/**
1212+
* Merge two failed ids collections preserving uniqueness.
1213+
*
1214+
* @param {string[]} baseFailedEventIds - existing failed ids
1215+
* @param {string[]} extraFailedEventIds - failed ids collected from update results
1216+
* @returns {string[]}
1217+
*/
1218+
_mergeFailedEventIds(baseFailedEventIds, extraFailedEventIds) {
1219+
const mergedFailedEventIds = new Set(baseFailedEventIds);
1220+
1221+
extraFailedEventIds.forEach((eventId) => {
1222+
mergedFailedEventIds.add(eventId);
1223+
});
1224+
1225+
return Array.from(mergedFailedEventIds);
1226+
}
1227+
12101228
/**
12111229
* Compose event with repetition
12121230
*

src/resolvers/event.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
const getEventsFactory = require('./helpers/eventsFactory').default;
22
const {
33
parseBulkEventIds,
4-
withMergedInvalidEventIds,
54
enqueueAssigneeNotification,
6-
enqueueBulkAssigneeNotifications,
75
} = require('./helpers/bulkEventUtils');
86
const { aiService } = require('../services/ai');
97
const { UserInputError } = require('apollo-server-express');
@@ -163,8 +161,12 @@ module.exports = {
163161

164162
const factory = getEventsFactory(context, projectId);
165163
const result = await factory.bulkVisitEvents(validEventIds, user.id);
164+
const failedEventIds = Array.from(new Set([...(result.failedEventIds || []), ...invalidEventIds]));
166165

167-
return withMergedInvalidEventIds(result, invalidEventIds);
166+
return {
167+
...result,
168+
failedEventIds,
169+
};
168170
},
169171

170172
/**
@@ -207,8 +209,12 @@ module.exports = {
207209

208210
const factory = getEventsFactory(context, projectId);
209211
const result = await factory.bulkToggleEventMark(validEventIds, mark);
212+
const failedEventIds = Array.from(new Set([...(result.failedEventIds || []), ...invalidEventIds]));
210213

211-
return withMergedInvalidEventIds(result, invalidEventIds);
214+
return {
215+
...result,
216+
failedEventIds,
217+
};
212218
},
213219

214220
/**
@@ -332,15 +338,20 @@ module.exports = {
332338
}
333339

334340
const result = await factory.bulkUpdateAssignee(validEventIds, assignee);
335-
const resultWithInvalid = withMergedInvalidEventIds(result, invalidEventIds);
341+
const resultWithInvalid = {
342+
...result,
343+
failedEventIds: Array.from(new Set([...(result.failedEventIds || []), ...invalidEventIds])),
344+
};
336345

337346
if (assignee && resultWithInvalid.updatedEventIds.length > 0) {
338-
enqueueBulkAssigneeNotifications({
339-
assigneeData,
340-
assigneeId: assignee,
341-
projectId,
342-
whoAssignedId: user.id,
343-
eventIds: resultWithInvalid.updatedEventIds,
347+
resultWithInvalid.updatedEventIds.forEach((eventId) => {
348+
enqueueAssigneeNotification({
349+
assigneeData,
350+
assigneeId: assignee,
351+
projectId,
352+
whoAssignedId: user.id,
353+
eventId,
354+
});
344355
});
345356
}
346357

src/resolvers/helpers/bulkEventUtils.ts

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { SenderWorkerTaskType } from '../../types/userNotifications/task-type';
77
/**
88
* Validate and normalize bulk event ids from resolver input.
99
*
10-
* @param eventIds - raw event ids from GraphQL input
10+
* @param {string[]} eventIds - raw event ids from GraphQL input
11+
* @returns {object} normalized ids grouped by validity
1112
*/
1213
export function parseBulkEventIds(eventIds: string[]): { validEventIds: string[]; invalidEventIds: string[] } {
1314
if (!eventIds || !eventIds.length) {
@@ -32,26 +33,6 @@ export function parseBulkEventIds(eventIds: string[]): { validEventIds: string[]
3233
};
3334
}
3435

35-
/**
36-
* Merge failed ids returned by factory with invalid ids from resolver validation.
37-
*/
38-
export function mergeFailedEventIds(result: { failedEventIds?: string[] }, invalidEventIds: string[]): string[] {
39-
return [ ...new Set([ ...(result.failedEventIds || []), ...invalidEventIds ]) ];
40-
}
41-
42-
/**
43-
* Merge resolver-level invalid ids into factory-level failed ids.
44-
*/
45-
export function withMergedInvalidEventIds<T extends { failedEventIds?: string[] }>(
46-
result: T,
47-
invalidEventIds: string[]
48-
): T & { failedEventIds: string[] } {
49-
return {
50-
...result,
51-
failedEventIds: mergeFailedEventIds(result, invalidEventIds),
52-
};
53-
}
54-
5536
type AssigneeNotificationParams = {
5637
assigneeData: UserDBScheme | null;
5738
assigneeId: string;
@@ -74,7 +55,7 @@ export function enqueueAssigneeNotification({
7455
return;
7556
}
7657

77-
void sendPersonalNotification(assigneeData, {
58+
sendPersonalNotification(assigneeData, {
7859
type: SenderWorkerTaskType.Assignee,
7960
payload: {
8061
assigneeId,
@@ -86,24 +67,3 @@ export function enqueueAssigneeNotification({
8667
console.error('Failed to enqueue assignee notification', error);
8768
});
8869
}
89-
90-
/**
91-
* Enqueue assignee notifications for all updated original events.
92-
*/
93-
export function enqueueBulkAssigneeNotifications({
94-
assigneeData,
95-
assigneeId,
96-
projectId,
97-
whoAssignedId,
98-
eventIds,
99-
}: Omit<AssigneeNotificationParams, 'eventId'> & { eventIds: string[] }): void {
100-
eventIds.forEach((eventId) => {
101-
enqueueAssigneeNotification({
102-
assigneeData,
103-
assigneeId,
104-
projectId,
105-
whoAssignedId,
106-
eventId,
107-
});
108-
});
109-
}

test/resolvers/bulk-events-helper.test.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import '../../src/env-test';
22
// eslint-disable-next-line @typescript-eslint/no-var-requires
3-
const { parseBulkEventIds, mergeFailedEventIds } = require('../../src/resolvers/helpers/bulkEventUtils') as {
3+
const { parseBulkEventIds } = require('../../src/resolvers/helpers/bulkEventUtils') as {
44
parseBulkEventIds: (eventIds: string[]) => { validEventIds: string[]; invalidEventIds: string[] };
5-
mergeFailedEventIds: (
6-
result: { failedEventIds?: string[] },
7-
invalidEventIds: string[]
8-
) => string[];
95
};
106

117
describe('bulkEvents helper', () => {
@@ -21,15 +17,6 @@ describe('bulkEvents helper', () => {
2117
});
2218
});
2319

24-
it('should merge failed ids from factory and invalid resolver ids', () => {
25-
const result = mergeFailedEventIds(
26-
{ failedEventIds: [ '507f1f77bcf86cd799439011' ] },
27-
[ 'bad-id', '507f1f77bcf86cd799439011' ]
28-
);
29-
30-
expect(result).toEqual([ '507f1f77bcf86cd799439011', 'bad-id' ]);
31-
});
32-
3320
it('should throw when eventIds is empty', () => {
3421
expect(() => parseBulkEventIds([])).toThrow('eventIds must contain at least one id');
3522
});

0 commit comments

Comments
 (0)