Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EdgeDB] Add PeriodicReport queries | refactor service/repo layers appropriately #3247

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/components/periodic-report/dto/periodic-report.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Field, InterfaceType, ObjectType } from '@nestjs/graphql';
import { keys as keysOf } from 'ts-transformer-keys';
import { MergeExclusive } from 'type-fest';
import {
Calculated,
CalendarDate,
Expand All @@ -17,8 +18,14 @@ 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>
>;

@RegisterResource({ db: e.PeriodicReport })
@Calculated()
@InterfaceType({
Expand Down Expand Up @@ -49,7 +56,7 @@ class PeriodicReport extends Resource {
@Field()
readonly skippedReason: SecuredStringNullable;

readonly reportFile: DefinedFile;
readonly reportFile: DefinedFile; //TODO? - Secured<LinkTo<'File'> | null>

@SensitivityField({
description: "Based on the project's sensitivity",
Expand Down Expand Up @@ -92,6 +99,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
194 changes: 194 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,194 @@
import { Injectable } from '@nestjs/common';
import { Query } from 'cypher-query-builder';
import { Without } from 'type-fest/source/merge-exclusive';
import {
CalendarDate,
EnhancedResource,
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.');
}

async getByDate(

Check failure on line 61 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 enhancedResource = EnhancedResource.of(
resolveReportType({ type: reportType }),
);
const resource = e.cast(enhancedResource.db, e.uuid(parentId));

const report = e.select(resource, (report) => ({
filter: e.all(
e.set(
e.op(resource.id, '=', report.container.id),
e.op(report.start, '<=', date),
e.op(report.end, '>=', date),
),
),
}));

const query = e.select(report, this.hydrate);

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

View workflow job for this annotation

GitHub Actions / lint

No overload matches this call.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CarsonF - There is an error on the return type here. The EdgeDB and Neo4j versions don't match. I thought that if I hydrated here it would fix that, but I'm getting this error I don't understand.


return await this.db.run(query);
}

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.');
}
}
Loading
Loading