-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dmirano/4570 new prev activities mmis (#4588)
* added new files for mmis results of prev activities * updated files related to schema changes * updated migrations * updated frontend tests * added front end test for new mmis tables * added cypress test * updated backend tests * updated file names * updated file names again * updated file paths * for HITECH APDs, merged the hitech tables component and the mmis tables component together * updated snapshots * added plural to file name of prev activity tables * updated prev act totals table file name * fixed hitech prev activities * updated snapshots * updated front end tests * updated cypress tests - hitech results of prev activities * updated cypress test * updated cypress tests again * even more cypress fixes * reverted some changes * updated snapshots * cypress change * typo * even more cypress fixes * running into problem with tables being synced * fixed table sync issue * fixed frontend tests * fixed linter * removed console.log * refactors based on Amy's comments * updated backend snapshot * results of previous activities should not inlude the current year * reverted prev years change * updated snapshots
- Loading branch information
1 parent
5a745e6
commit 3a94636
Showing
42 changed files
with
2,870 additions
and
991 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
api/migrations/20230302152346_results-of-prev-activities-mmis.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import loggerFactory from '../logger/index.js'; | ||
import { setup, teardown } from '../db/mongodb.js'; | ||
import { MMIS } from '../models/index.js'; | ||
|
||
const logger = loggerFactory( | ||
'mongoose-migrate/migrate-results-of-previous-activities-mmis' | ||
); | ||
|
||
/** | ||
* Update Results of Previous Activities page in MMIS APDs to have DDI and M&O | ||
*/ | ||
export const up = async () => { | ||
//Grab all APDs | ||
await setup(); | ||
const apds = await MMIS.find().lean(); | ||
logger.info(`Updating ${apds.length} APDs`); | ||
|
||
const updatedApds = apds.map(apd => { | ||
const years = apd.years; | ||
let prevYears = []; | ||
|
||
[0, 1, 2].map(past => prevYears.unshift(years[0] - past)); | ||
|
||
if (apd.previousActivities.actualExpenditures[prevYears[0]].ddi) { | ||
return apd; | ||
} | ||
|
||
return { | ||
...apd, | ||
id: apd._id, | ||
previousActivities: { | ||
...apd.previousActivities, | ||
actualExpenditures: prevYears.reduce( | ||
(acc, year) => ({ | ||
...acc, | ||
[year]: { | ||
ddi: { | ||
50: { | ||
federalActual: 0, | ||
totalApproved: 0 | ||
}, | ||
75: { | ||
federalActual: 0, | ||
totalApproved: 0 | ||
}, | ||
90: { | ||
federalActual: 0, | ||
totalApproved: 0 | ||
} | ||
}, | ||
mando: { | ||
50: { | ||
federalActual: 0, | ||
totalApproved: 0 | ||
}, | ||
75: { | ||
federalActual: 0, | ||
totalApproved: 0 | ||
} | ||
} | ||
} | ||
}), | ||
{} | ||
) | ||
} | ||
}; | ||
}); | ||
|
||
// Update them into the database | ||
await Promise.all( | ||
updatedApds.map(async apd => { | ||
logger.info( | ||
`Updating MMIS APD ${apd.id} to add ddi and mando to results of previous activities` | ||
); | ||
return MMIS.replaceOne({ _id: apd.id }, { ...apd }); | ||
}) | ||
).catch(err => { | ||
logger.error(err); | ||
}); | ||
await teardown(); | ||
}; | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
export const down = async () => {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.