Skip to content

Commit

Permalink
Create PeriodicReport queries
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanjnelson committed Jul 3, 2024
1 parent 4aeaf58 commit 07d8f1b
Show file tree
Hide file tree
Showing 2 changed files with 212 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/components/periodic-report/dto/periodic-report.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Field, InterfaceType, ObjectType } from '@nestjs/graphql';
import { simpleSwitch } from '@seedcompany/common';
import { keys as keysOf } from 'ts-transformer-keys';
import { MergeExclusive } from 'type-fest';
import {
Calculated,
CalendarDate,
Expand All @@ -11,14 +13,29 @@ import {
SecuredStringNullable,
Sensitivity,
SensitivityField,
ServerException,
} from '~/common';
import { BaseNode as DbBaseNode } from '~/core/database/results';
import { e } from '~/core/edgedb';
import { RegisterResource } from '~/core/resources';
import { ScopedRole } from '../../authorization/dto';
import { DefinedFile } from '../../file/dto';
import { ProgressReport } from '../../progress-report/dto';
import { ReportType } from './report-type.enum';

export type AnyReport = MergeExclusive<
FinancialReport,
MergeExclusive<NarrativeReport, ProgressReport>
>;

export const resolveReportType = (val: Pick<AnyReport, 'type'>) => {
const type = simpleSwitch(val.type, ReportConcretes);
if (!type) {
throw new ServerException(`Could not resolve report type: '${val.type}'`);
}
return type;
};

@RegisterResource({ db: e.PeriodicReport })
@Calculated()
@InterfaceType({
Expand Down Expand Up @@ -92,6 +109,12 @@ export class NarrativeReport extends PeriodicReport {
})
export class SecuredPeriodicReport extends SecuredProperty(PeriodicReport) {}

export const ReportConcretes = {
Financial: FinancialReport,
Narrative: NarrativeReport,
Progress: ProgressReport,
};

declare module '~/core/resources/map' {
interface ResourceMap {
PeriodicReport: typeof PeriodicReport;
Expand Down
189 changes: 189 additions & 0 deletions src/components/periodic-report/periodic-report.edgedb.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
import { Injectable } from '@nestjs/common';
import { Query } from 'cypher-query-builder';
import { Without } from 'type-fest/source/merge-exclusive';
import {
CalendarDate,
ID,
PublicOf,
Range,
Session,
UnsecuredDto,
} from '~/common';
import { castToEnum, e, RepoFor } from '~/core/edgedb';
import { Variable } from '../../core/database/query';
import { ProgressReport } from '../progress-report/dto';
import {
FinancialReport,
IPeriodicReport,
MergePeriodicReports,
NarrativeReport,
ReportType,
resolveReportType,
} from './dto';
import { PeriodicReportRepository } from './periodic-report.repository';

@Injectable()
export class PeriodicReportEdgeDBRepository
extends RepoFor(IPeriodicReport, {
hydrate: (periodicReport) => ({
...periodicReport['*'],
type: castToEnum(periodicReport.__type__.name.slice(9, -7), ReportType),
reportFile: true,
sensitivity: periodicReport.container.is(e.Project.ContextAware)
.sensitivity,
scope: false,
parent: e.tuple({
identity: periodicReport.id,
labels: e.array_agg(e.set(periodicReport.__type__.name.slice(9, null))),
properties: e.tuple({
id: periodicReport.id,
createdAt: periodicReport.createdAt,
}),
}),
}),
})
implements PublicOf<PeriodicReportRepository>
{
merge(
input: MergePeriodicReports,
): Promise<ReadonlyArray<{ id: ID; interval: Range<CalendarDate> }>> {
throw new Error('Method not implemented.');
}

matchCurrentDue(
parentId: ID | Variable,
reportType: ReportType,
): (query: Query) => Query {
throw new Error('Method not implemented.');
}

getByDate(

Check failure on line 60 in src/components/periodic-report/periodic-report.edgedb.repository.ts

View workflow job for this annotation

GitHub Actions / lint

Property 'getByDate' in type 'PeriodicReportEdgeDBRepository' is not assignable to the same property in base type 'PublicOf<PeriodicReportRepository>'.
parentId: ID,
date: CalendarDate,
reportType: ReportType,
_session: Session,
) {
const resource = e.cast(e.Resource, e.uuid(parentId));

const report = e.select(e.PeriodicReport, (report) => ({

Check failure on line 68 in src/components/periodic-report/periodic-report.edgedb.repository.ts

View workflow job for this annotation

GitHub Actions / lint

No overload matches this call.
filter: e.all(
e.set(
e.op(resource.id, '=', report.container.id),
e.op(report.start, '<=', date),
e.op(report.end, '>=', date),
),
),
...report.is(resolveReportType(reportType)),

Check failure on line 76 in src/components/periodic-report/periodic-report.edgedb.repository.ts

View workflow job for this annotation

GitHub Actions / lint

Argument of type 'typeof ProgressReport | typeof FinancialReport | typeof NarrativeReport' is not assignable to parameter of type 'ObjectTypeSet'.

Check failure on line 76 in src/components/periodic-report/periodic-report.edgedb.repository.ts

View workflow job for this annotation

GitHub Actions / lint

Argument of type 'string' is not assignable to parameter of type 'Pick<(Without<FinancialReport, (Without<NarrativeReport, ProgressReport> & ProgressReport) | (Without<...> & NarrativeReport)> & ((Without<...> & ProgressReport) | (Without<...> & NarrativeReport))) | (Without<...> & FinancialReport), "type">'.
}));

return this.db.run(report);
}

getCurrentDue(
parentId: ID,
reportType: ReportType,
session: Session,
): Promise<
| UnsecuredDto<
| (Without<
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
| (Without<NarrativeReport, FinancialReport> & FinancialReport),
ProgressReport
> &
ProgressReport)
| (Without<
ProgressReport,
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
> &
(
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
))
>
| undefined
> {
throw new Error('Method not implemented.');
}

getNextDue(
parentId: ID,
reportType: ReportType,
session: Session,
): Promise<
| UnsecuredDto<
| (Without<
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
| (Without<NarrativeReport, FinancialReport> & FinancialReport),
ProgressReport
> &
ProgressReport)
| (Without<
ProgressReport,
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
> &
(
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
))
>
| undefined
> {
throw new Error('Method not implemented.');
}

getLatestReportSubmitted(
parentId: ID,
type: ReportType,
session: Session,
): Promise<
| UnsecuredDto<
| (Without<
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
| (Without<NarrativeReport, FinancialReport> & FinancialReport),
ProgressReport
> &
ProgressReport)
| (Without<
ProgressReport,
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
> &
(
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
))
>
| undefined
> {
throw new Error('Method not implemented.');
}

getFinalReport(
parentId: ID,
type: ReportType,
session: Session,
): Promise<
| UnsecuredDto<
| (Without<
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
| (Without<NarrativeReport, FinancialReport> & FinancialReport),
ProgressReport
> &
ProgressReport)
| (Without<
ProgressReport,
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
> &
(
| (Without<FinancialReport, NarrativeReport> & NarrativeReport)
| (Without<NarrativeReport, FinancialReport> & FinancialReport)
))
>
| undefined
> {
throw new Error('Method not implemented.');
}
}

0 comments on commit 07d8f1b

Please sign in to comment.