Skip to content

Commit c33b0f0

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

File tree

3 files changed

+192
-1
lines changed

3 files changed

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

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)