Skip to content

Commit 2e9ea25

Browse files
committed
Add project step condition
1 parent 85f7b13 commit 2e9ea25

File tree

6 files changed

+37
-71
lines changed

6 files changed

+37
-71
lines changed

src/components/engagement/dto/engagement.dto.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ class Engagement extends Interfaces {
6969

7070
declare readonly __typename: 'LanguageEngagement' | 'InternshipEngagement';
7171

72-
readonly project: LinkTo<'Project'> & Pick<IProject, 'status' | 'type'>;
72+
readonly project: LinkTo<'Project'> &
73+
Pick<UnsecuredDto<IProject>, 'type' | 'step' | 'status'>;
7374

7475
@Field(() => IProject)
7576
declare readonly parent: BaseNode;

src/components/engagement/engagement.repository.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ export class EngagementRepository extends CommonRepository {
158158
relation('out', '', 'status', ACTIVE),
159159
node('status'),
160160
])
161+
.match([
162+
node('project'),
163+
relation('out', '', 'step', ACTIVE),
164+
node('projectStep'),
165+
])
161166
.return<{ dto: UnsecuredDto<Engagement> }>(
162167
merge('props', 'changedProps', {
163168
__typename: typenameForView(
@@ -169,6 +174,7 @@ export class EngagementRepository extends CommonRepository {
169174
id: 'project.id',
170175
type: 'project.type',
171176
status: 'status.value',
177+
step: 'projectStep.value',
172178
},
173179
language: 'language.id',
174180
ceremony: 'ceremony.id',

src/components/engagement/workflow/engagement-workflow.neo4j.repository.ts

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import { Injectable } from '@nestjs/common';
22
import { inArray, node, Query, relation } from 'cypher-query-builder';
3-
import {
4-
ID,
5-
Order,
6-
PublicOf,
7-
ServerException,
8-
Session,
9-
UnsecuredDto,
10-
} from '~/common';
3+
import { ID, Order, PublicOf, Session, UnsecuredDto } from '~/common';
114
import { DtoRepository } from '~/core/database';
125
import {
136
ACTIVE,
@@ -18,7 +11,6 @@ import {
1811
requestingUser,
1912
sorting,
2013
} from '~/core/database/query';
21-
import { ProjectStep } from '../../project/dto';
2214
import { EngagementStatus, IEngagement } from '../dto';
2315
import {
2416
ExecuteEngagementTransitionInput,
@@ -138,58 +130,4 @@ export class EngagementWorkflowNeo4jRepository
138130
.first();
139131
return result?.step ?? null;
140132
}
141-
142-
async getCurrentProjectStep(engagementId: ID, changeset?: ID) {
143-
const result = await this.db
144-
.query()
145-
.match([
146-
node('engagement', 'Engagement', { id: engagementId }),
147-
relation('in', '', 'engagement'), // Removed active true due to changeset aware
148-
node('project', 'Project'),
149-
])
150-
.raw('return project.id as projectId')
151-
.asResult<{ projectId: ID }>()
152-
.first();
153-
154-
if (!result?.projectId) {
155-
throw new ServerException(`Could not find project`);
156-
}
157-
const projectId = result.projectId;
158-
159-
let currentStep;
160-
if (changeset) {
161-
const result = await this.db
162-
.query()
163-
.match([
164-
node('project', 'Project', { id: projectId }),
165-
relation('out', '', 'step', INACTIVE),
166-
node('step', 'Property'),
167-
relation('in', '', 'changeset', ACTIVE),
168-
node('', 'Changeset', { id: changeset }),
169-
])
170-
.raw('return step.value as step')
171-
.asResult<{ step: ProjectStep }>()
172-
.first();
173-
currentStep = result?.step;
174-
}
175-
if (!currentStep) {
176-
const result = await this.db
177-
.query()
178-
.match([
179-
node('project', 'Project', { id: projectId }),
180-
relation('out', '', 'step', ACTIVE),
181-
node('step', 'Property'),
182-
])
183-
.raw('return step.value as step')
184-
.asResult<{ step: ProjectStep }>()
185-
.first();
186-
currentStep = result?.step;
187-
}
188-
189-
if (!currentStep) {
190-
throw new ServerException(`Could not find project's step`);
191-
}
192-
193-
return currentStep;
194-
}
195133
}

src/components/engagement/workflow/engagement-workflow.repository.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,4 @@ export class EngagementWorkflowRepository extends RepoFor(
6969
`);
7070
return await this.db.run(query, { engagementId, steps });
7171
}
72-
73-
async getCurrentProjectStep(engagementId: ID) {
74-
const engagement = e.cast(e.Engagement, e.uuid(engagementId));
75-
const project = e.cast(e.Project, engagement.project.id);
76-
const query = e.select(project.step);
77-
return await this.db.run(query);
78-
}
7972
}

src/components/engagement/workflow/engagement-workflow.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { EngagementStatus as Status } from '../dto';
44
import { EngagementWorkflowEvent } from './dto';
55
import { BackTo, BackToActive } from './transitions/back';
66
import { EngagementWorkflowContext } from './transitions/context';
7+
import { ProjectStep } from './transitions/project-step';
78

89
// This also controls the order shown in the UI.
910
// Therefore, these should generally flow down.
@@ -20,18 +21,21 @@ export const EngagementWorkflow = defineWorkflow({
2021
to: Status.Rejected,
2122
label: 'Reject',
2223
type: Type.Reject,
24+
conditions: ProjectStep('Rejected'),
2325
},
2426
'End Development': {
2527
from: Status.InDevelopment,
2628
to: Status.DidNotDevelop,
2729
label: 'End Development',
2830
type: Type.Reject,
31+
conditions: ProjectStep('DidNotDevelop'),
2932
},
3033
'Approve to Active': {
3134
from: Status.InDevelopment,
3235
to: Status.Active,
3336
label: 'Approve',
3437
type: Type.Approve,
38+
conditions: ProjectStep('Active'),
3539
},
3640
'Discuss Change To Plan': {
3741
from: [Status.Active, Status.ActiveChangedPlan],
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { setOf } from '@seedcompany/common';
2+
import { ProjectStep as Step } from '../../../project/dto';
3+
import { TransitionCondition } from '../../../workflow/transitions/conditions';
4+
import { EngagementWorkflowContext } from './context';
5+
6+
type Condition = TransitionCondition<EngagementWorkflowContext>;
7+
8+
export const ProjectStep = (...steps: Step[]): Condition => {
9+
const stepSet = setOf(steps);
10+
const description =
11+
'Project needs to be ' +
12+
[...stepSet].map((step) => Step.entry(step).label).join(' / ');
13+
return {
14+
description,
15+
resolve({ engagement }) {
16+
return {
17+
status: steps.includes(engagement.project.step)
18+
? 'ENABLED'
19+
: 'DISABLED',
20+
disabledReason: description,
21+
};
22+
},
23+
};
24+
};

0 commit comments

Comments
 (0)