Skip to content

Commit d42d74f

Browse files
committed
Create Gel PeriodicReport queries
1 parent 8719878 commit d42d74f

File tree

3 files changed

+215
-1
lines changed

3 files changed

+215
-1
lines changed

src/components/periodic-report/dto/periodic-report.dto.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Field, InterfaceType, ObjectType } from '@nestjs/graphql';
2+
import { type MergeExclusive } from 'type-fest';
23
import {
34
Calculated,
45
CalendarDate,
@@ -15,8 +16,14 @@ import { e } from '~/core/gel';
1516
import { RegisterResource } from '~/core/resources';
1617
import { type ScopedRole } from '../../authorization/dto';
1718
import { type DefinedFile } from '../../file/dto';
19+
import { ProgressReport } from '../../progress-report/dto';
1820
import { ReportType } from './report-type.enum';
1921

22+
export type AnyReport = MergeExclusive<
23+
FinancialReport,
24+
MergeExclusive<NarrativeReport, ProgressReport>
25+
>;
26+
2027
@RegisterResource({ db: e.PeriodicReport })
2128
@Calculated()
2229
@InterfaceType({
@@ -83,6 +90,12 @@ export class NarrativeReport extends PeriodicReport {
8390
})
8491
export class SecuredPeriodicReport extends SecuredProperty(PeriodicReport) {}
8592

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

src/components/periodic-report/periodic-report.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { forwardRef, Module } from '@nestjs/common';
2+
import { splitDb } from '~/core';
23
import { AuthorizationModule } from '../authorization/authorization.module';
34
import { EngagementModule } from '../engagement/engagement.module';
45
import { FileModule } from '../file/file.module';
@@ -7,6 +8,7 @@ import { ProjectModule } from '../project/project.module';
78
import * as handlers from './handlers';
89
import { PeriodicReportParentResolver } from './periodic-report-parent.resolver';
910
import { PeriodicReportProjectConnectionResolver } from './periodic-report-project-connection.resolver';
11+
import { PeriodicReportGelRepository } from './periodic-report.gel.repository';
1012
import { PeriodicReportLoader } from './periodic-report.loader';
1113
import { PeriodicReportRepository } from './periodic-report.repository';
1214
import { PeriodicReportResolver } from './periodic-report.resolver';
@@ -25,7 +27,7 @@ import { PeriodicReportService } from './periodic-report.service';
2527
PeriodicReportResolver,
2628
PeriodicReportProjectConnectionResolver,
2729
PeriodicReportParentResolver,
28-
PeriodicReportRepository,
30+
splitDb(PeriodicReportRepository, PeriodicReportGelRepository),
2931
PeriodicReportLoader,
3032
...Object.values(handlers),
3133
],

0 commit comments

Comments
 (0)