Skip to content

Commit 1d3efe9

Browse files
committed
Create PeriodicReport queries
1 parent 4aeaf58 commit 1d3efe9

File tree

1 file changed

+191
-0
lines changed

1 file changed

+191
-0
lines changed
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
import { Injectable } from '@nestjs/common';
2+
import { Query } from 'cypher-query-builder';
3+
import { Without } from 'type-fest/source/merge-exclusive';
4+
import {
5+
CalendarDate,
6+
ID,
7+
PublicOf,
8+
Range,
9+
Session,
10+
UnsecuredDto,
11+
} from '~/common';
12+
import { castToEnum, e, RepoFor } from '~/core/edgedb';
13+
import { Variable } from '../../core/database/query';
14+
import { ProgressReport } from '../progress-report/dto';
15+
import {
16+
FinancialReport,
17+
IPeriodicReport,
18+
MergePeriodicReports,
19+
NarrativeReport,
20+
ReportType,
21+
} from './dto';
22+
import { PeriodicReportRepository } from './periodic-report.repository';
23+
24+
@Injectable()
25+
export class PeriodicReportEdgeDBRepository
26+
extends RepoFor(IPeriodicReport, {
27+
hydrate: (periodicReport) => ({
28+
...periodicReport['*'],
29+
type: castToEnum(periodicReport.__type__.name.slice(9, -7), ReportType),
30+
reportFile: true,
31+
sensitivity: periodicReport.container.is(e.Project.ContextAware)
32+
.sensitivity,
33+
scope: false,
34+
parent: e.tuple({
35+
identity: periodicReport.id,
36+
labels: e.array_agg(e.set(periodicReport.__type__.name.slice(9, null))),
37+
properties: e.tuple({
38+
id: periodicReport.id,
39+
createdAt: periodicReport.createdAt,
40+
}),
41+
}),
42+
}),
43+
})
44+
implements PublicOf<PeriodicReportRepository>
45+
{
46+
merge(
47+
input: MergePeriodicReports,
48+
): Promise<ReadonlyArray<{ id: ID; interval: Range<CalendarDate> }>> {
49+
throw new Error('Method not implemented.');
50+
}
51+
52+
matchCurrentDue(
53+
parentId: ID | Variable,
54+
reportType: 'Financial' | 'Progress' | 'Narrative',
55+
): (query: Query) => Query {
56+
throw new Error('Method not implemented.');
57+
}
58+
59+
getByDate(
60+
parentId: ID,
61+
date: CalendarDate,
62+
reportType: 'Financial' | 'Progress' | 'Narrative',
63+
_session: Session,
64+
) {
65+
const resource = e.cast(e.Resource, e.uuid(parentId));
66+
67+
//TODO: account for reportType (should replace e.FinancialReport below with the correct variable type)
68+
const report = e.select(
69+
e.PeriodicReport.is(e.FinancialReport),
70+
(report) => ({
71+
filter: e.all(
72+
e.set(
73+
e.op(resource.id, '=', report.container.id),
74+
e.op(report.start, '<=', date),
75+
e.op(report.end, '>=', date),
76+
),
77+
),
78+
}),
79+
);
80+
81+
return this.db.run(report);
82+
}
83+
84+
getCurrentDue(
85+
parentId: ID,
86+
reportType: 'Financial' | 'Progress' | 'Narrative',
87+
session: Session,
88+
): Promise<
89+
| UnsecuredDto<
90+
| (Without<
91+
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
92+
| (Without<NarrativeReport, FinancialReport> & FinancialReport),
93+
ProgressReport
94+
> &
95+
ProgressReport)
96+
| (Without<
97+
ProgressReport,
98+
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
99+
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
100+
> &
101+
(
102+
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
103+
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
104+
))
105+
>
106+
| undefined
107+
> {
108+
throw new Error('Method not implemented.');
109+
}
110+
111+
getNextDue(
112+
parentId: ID,
113+
reportType: 'Financial' | 'Progress' | 'Narrative',
114+
session: Session,
115+
): Promise<
116+
| UnsecuredDto<
117+
| (Without<
118+
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
119+
| (Without<NarrativeReport, FinancialReport> & FinancialReport),
120+
ProgressReport
121+
> &
122+
ProgressReport)
123+
| (Without<
124+
ProgressReport,
125+
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
126+
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
127+
> &
128+
(
129+
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
130+
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
131+
))
132+
>
133+
| undefined
134+
> {
135+
throw new Error('Method not implemented.');
136+
}
137+
138+
getLatestReportSubmitted(
139+
parentId: ID,
140+
type: 'Financial' | 'Progress' | 'Narrative',
141+
session: Session,
142+
): Promise<
143+
| UnsecuredDto<
144+
| (Without<
145+
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
146+
| (Without<NarrativeReport, FinancialReport> & FinancialReport),
147+
ProgressReport
148+
> &
149+
ProgressReport)
150+
| (Without<
151+
ProgressReport,
152+
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
153+
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
154+
> &
155+
(
156+
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
157+
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
158+
))
159+
>
160+
| undefined
161+
> {
162+
throw new Error('Method not implemented.');
163+
}
164+
165+
getFinalReport(
166+
parentId: ID,
167+
type: 'Financial' | 'Progress' | 'Narrative',
168+
session: Session,
169+
): Promise<
170+
| UnsecuredDto<
171+
| (Without<
172+
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
173+
| (Without<NarrativeReport, FinancialReport> & FinancialReport),
174+
ProgressReport
175+
> &
176+
ProgressReport)
177+
| (Without<
178+
ProgressReport,
179+
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
180+
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
181+
> &
182+
(
183+
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
184+
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
185+
))
186+
>
187+
| undefined
188+
> {
189+
throw new Error('Method not implemented.');
190+
}
191+
}

0 commit comments

Comments
 (0)