Skip to content

Commit 47d77ef

Browse files
Merge pull request #604 from HHS/TTAHUB-427/add-goal-scope
[TTAHUB-427] Only fetch goals with certain statuses for selection when creating a draft AR
2 parents d430004 + fd68e52 commit 47d77ef

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/services/goals.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Op } from 'sequelize';
12
import {
23
Goal,
34
Grant,
@@ -18,16 +19,28 @@ export async function goalsForGrants(grantIds) {
1819
});
1920

2021
/**
21-
* we need one big array that includes the old grantee id as well
22+
* we need one big array that includes the old grantee id as well,
23+
* removing all the nulls along the way
2224
*/
23-
const ids = grants.reduce((previous, current) => [...previous, current.id, current.oldGrantId],
24-
[]);
25+
const ids = grants
26+
.reduce((previous, current) => [...previous, current.id, current.oldGrantId], [])
27+
.filter((g) => g != null);
2528

2629
/*
2730
* finally, return all matching goals
2831
*/
2932

3033
return Goal.findAll({
34+
where: {
35+
[Op.or]: [
36+
{
37+
status: 'Not Started',
38+
},
39+
{
40+
status: 'In Progress',
41+
},
42+
],
43+
},
3144
include: [
3245
{
3346
model: Grant,

src/services/goals.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Op } from 'sequelize';
12
import {
23
copyGoalsToGrants, saveGoalsForReport, goalsForGrants,
34
} from './goals';
@@ -204,6 +205,16 @@ describe('goalsForGrants', () => {
204205
await goalsForGrants([506]);
205206

206207
expect(Goal.findAll).toHaveBeenCalledWith({
208+
where: {
209+
[Op.or]: [
210+
{
211+
status: 'Not Started',
212+
},
213+
{
214+
status: 'In Progress',
215+
},
216+
],
217+
},
207218
include: [
208219
{
209220
model: Grant,

0 commit comments

Comments
 (0)