-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfetchSigWeeklyRecap.ts
More file actions
74 lines (62 loc) · 2.1 KB
/
Copy pathfetchSigWeeklyRecap.ts
File metadata and controls
74 lines (62 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import dbConnect from '../../lib/dbConnect';
import IssueObjectModel from '../../models/IssueObjectModel';
interface FollowUpSummary {
practice: string;
didHappen: boolean | null;
deliverableLink: string | null;
deliverableNotes: string | null;
reflections: { prompt: string; response: string }[];
}
interface PersonFollowUps {
person: string;
followUps: FollowUpSummary[];
}
export interface ProjectRecap {
projectName: string;
byPerson: PersonFollowUps[];
}
export const fetchSigWeeklyRecap = async (
sigName: string,
weekStart: Date
): Promise<ProjectRecap[]> => {
await dbConnect();
const weekEnd = new Date(weekStart);
weekEnd.setDate(weekEnd.getDate() + 7);
const issues = await IssueObjectModel.find({
sig: sigName,
date: { $gte: weekStart, $lt: weekEnd },
wasDeleted: { $ne: true },
}).sort({ project: 1 });
const projectMap = new Map<string, Map<string, FollowUpSummary[]>>();
for (const issue of issues) {
if (!projectMap.has(issue.project)) {
projectMap.set(issue.project, new Map());
}
const personMap = projectMap.get(issue.project)!;
for (const fu of issue.followUps) {
const person = fu.parsedPractice?.person || 'Unknown';
if (!personMap.has(person)) {
personMap.set(person, []);
}
const didHappen: boolean | null = fu.outcome?.didHappen ?? null;
const reflectionIndex = didHappen === true ? 1 : 0;
const reflectionArray = fu.outcome?.reflections?.[reflectionIndex] ?? [];
personMap.get(person)!.push({
practice: fu.parsedPractice?.practice || fu.practice,
didHappen,
deliverableLink: fu.outcome?.deliverableLink ?? null,
deliverableNotes: fu.outcome?.deliverableNotes ?? null,
reflections: reflectionArray
.filter((r: any) => r.response)
.map((r: any) => ({ prompt: r.prompt, response: r.response })),
});
}
}
return Array.from(projectMap.entries()).map(([projectName, personMap]) => ({
projectName,
byPerson: Array.from(personMap.entries()).map(([person, followUps]) => ({
person,
followUps,
})),
}));
};