Skip to content

Commit b5675f6

Browse files
committed
Create PeriodicReport queries
1 parent bf5d382 commit b5675f6

File tree

2 files changed

+202
-0
lines changed

2 files changed

+202
-0
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,5 +1,6 @@
11
import { Field, InterfaceType, ObjectType } from '@nestjs/graphql';
22
import { keys as keysOf } from 'ts-transformer-keys';
3+
import { MergeExclusive } from 'type-fest';
34
import {
45
Calculated,
56
CalendarDate,
@@ -17,8 +18,14 @@ import { e } from '~/core/edgedb';
1718
import { RegisterResource } from '~/core/resources';
1819
import { ScopedRole } from '../../authorization/dto';
1920
import { DefinedFile } from '../../file/dto';
21+
import { ProgressReport } from '../../progress-report/dto';
2022
import { ReportType } from './report-type.enum';
2123

24+
export type AnyReport = MergeExclusive<
25+
FinancialReport,
26+
MergeExclusive<NarrativeReport, ProgressReport>
27+
>;
28+
2229
@RegisterResource({ db: e.PeriodicReport })
2330
@Calculated()
2431
@InterfaceType({
@@ -92,6 +99,12 @@ export class NarrativeReport extends PeriodicReport {
9299
})
93100
export class SecuredPeriodicReport extends SecuredProperty(PeriodicReport) {}
94101

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

0 commit comments

Comments
 (0)