Skip to content

Commit 2f335f9

Browse files
authored
Merge pull request #2914 from SeedCompany/0680-progress-explanation-change
2 parents f5338e4 + 7127391 commit 2f335f9

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { node, relation } from 'cypher-query-builder';
2+
import { BaseMigration, Migration } from '~/core';
3+
import { ACTIVE } from '~/core/database/query';
4+
5+
@Migration('2023-10-12T11:00:00')
6+
export class RenameReasonOptionMigration extends BaseMigration {
7+
async up() {
8+
await this.db
9+
.query()
10+
.match([
11+
node('', 'ProgressReportVarianceExplanation'),
12+
relation('out', '', 'reasons', ACTIVE),
13+
node('reason', 'Property'),
14+
])
15+
.raw('where any(x in reason.value where x = $old)', {
16+
old: 'Partner organization issues currently being addressed.',
17+
})
18+
.setValues({
19+
'reason.value': [
20+
'Partner organization issues currently being addressed',
21+
],
22+
})
23+
.return('count(reason) as count')
24+
.executeAndLogStats();
25+
}
26+
}

src/components/progress-report/variance-explanation/reason-options.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Field, ObjectType } from '@nestjs/graphql';
2+
import { stripIndent } from 'common-tags';
23
import { LazyGetter as Once } from 'lazy-get-decorator';
34
import { DataObject, JsonSet } from '~/common';
45

@@ -14,19 +15,34 @@ export class ProgressReportVarianceExplanationReasonOptions extends DataObject {
1415
return new JsonSet([...this.behind, ...this.onTime, ...this.ahead]);
1516
}
1617

18+
@Field(() => [String], {
19+
description: stripIndent`
20+
A list of deprecated options.
21+
If an option is deprecated, it is not available for selection/saving.
22+
This allows rendering old options while enforcing a soft migration
23+
to new values.
24+
`,
25+
})
26+
readonly deprecated: ReadonlySet<string> = new JsonSet([
27+
'Delayed activities; activities did not occur; slow start of project',
28+
]);
29+
1730
@Field(() => [String])
1831
readonly behind: ReadonlySet<string> = new JsonSet([
1932
'Delayed activities; activities did not occur; slow start of project',
2033
'Team is being trained at start of project; they expect to catch up by end of project',
2134
'Delayed hiring and/or replacement of personnel',
2235
'Economic/political/civil instability or unrest',
2336
'Late or delayed partner reporting',
24-
'Partner organization issues currently being addressed.',
37+
'Partner organization issues currently being addressed',
2538
'Health issues with team members or their families',
2639
'Team member passed away',
2740
'Security breach/teams in hiding',
2841
'Unstable internet',
2942
'Checking delayed because translation consultants not available',
43+
'Natural disaster prevented team from working',
44+
'Activities did not occur, rescheduled for later date',
45+
'Slow start to project, but team expects to catch up',
3046
]);
3147

3248
@Field(() => [String])

src/components/progress-report/variance-explanation/variance-explanation.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Module } from '@nestjs/common';
2+
import { RenameReasonOptionMigration } from './migrations/rename.migration';
23
import { ProgressReportVarianceExplanationLoader } from './variance-explanation.loader';
34
import { ProgressReportVarianceExplanationRepository } from './variance-explanation.repository';
45
import {
@@ -14,6 +15,7 @@ import { ProgressReportVarianceExplanationService } from './variance-explanation
1415
ProgressReportVarianceExplanationLoader,
1516
ProgressReportVarianceExplanationService,
1617
ProgressReportVarianceExplanationRepository,
18+
RenameReasonOptionMigration,
1719
],
1820
})
1921
export class ProgressReportVarianceExplanationModule {}

src/components/progress-report/variance-explanation/variance-explanation.service.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import { Injectable } from '@nestjs/common';
2-
import { mapFromList, NotFoundException, Session } from '~/common';
2+
import {
3+
InputException,
4+
mapFromList,
5+
NotFoundException,
6+
Session,
7+
} from '~/common';
38
import { ResourceLoader } from '~/core';
49
import { Privileges } from '../../authorization';
510
import { ProgressReport } from '../dto';
11+
import { ProgressReportVarianceExplanationReasonOptions as ReasonOptions } from './reason-options';
612
import {
713
ProgressReportVarianceExplanation as VarianceExplanation,
814
ProgressReportVarianceExplanationInput as VarianceExplanationInput,
@@ -50,6 +56,18 @@ export class ProgressReportVarianceExplanationService {
5056
return report;
5157
}
5258

59+
// Don't allow changing to a deprecated reason.
60+
// Here to be nice and allow updating the comments even if the current
61+
// reason is deprecated.
62+
if (
63+
changes.reasons?.some((r) => ReasonOptions.instance.deprecated.has(r))
64+
) {
65+
throw new InputException(
66+
'Reason is deprecated and cannot be used',
67+
'reasons',
68+
);
69+
}
70+
5371
this.privilegesFor(session, report).verifyChanges(changes);
5472

5573
await this.repo.update(report.id, changes, session);

0 commit comments

Comments
 (0)