-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from paritytech/chore/fixes
Chore/fixes
- Loading branch information
Showing
20 changed files
with
248 additions
and
87 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { CronJob, CronJobContext } from '#server/types' | ||
import * as formsDeleteDate from './forms-delete-data' | ||
import * as purgeFormSubmissions from './purge-form-submissions' | ||
|
||
module.exports.moduleCronJobsFactory = (ctx: CronJobContext): CronJob[] => { | ||
return [formsDeleteDate.jobFactory()] | ||
return [formsDeleteDate.jobFactory(), purgeFormSubmissions.jobFactory()] | ||
} |
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,38 @@ | ||
import { Op } from 'sequelize' | ||
import dayjs from 'dayjs' | ||
import { CronJob, CronJobContext } from '#server/types' | ||
|
||
const JOB_NAME = 'purge-form-submissions' | ||
|
||
export const jobFactory = (): CronJob => { | ||
return { | ||
name: JOB_NAME, | ||
cron: `0 0 * * *`, | ||
fn: async (ctx: CronJobContext) => { | ||
const forms = await ctx.models.Form.findAll({ | ||
where: { | ||
purgeSubmissionsAfterDays: { [Op.ne]: null }, | ||
}, | ||
attributes: ['id', 'title', 'purgeSubmissionsAfterDays'], | ||
}) | ||
for (const form of forms) { | ||
if (!form.purgeSubmissionsAfterDays) continue | ||
const deleted = await ctx.models.FormSubmission.destroy({ | ||
where: { | ||
formId: form.id, | ||
createdAt: { | ||
[Op.lt]: dayjs() | ||
.subtract(form.purgeSubmissionsAfterDays, 'day') | ||
.toDate(), | ||
}, | ||
}, | ||
}) | ||
if (deleted) { | ||
ctx.log.info( | ||
`${JOB_NAME}: Deleted ${deleted} submissions. Form "${form.title}"` | ||
) | ||
} | ||
} | ||
}, | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/modules/forms/server/migrations/20240228150156_forms_purge-submissions-after-days.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,13 @@ | ||
// @ts-check | ||
const { Sequelize, DataTypes } = require('sequelize') | ||
|
||
module.exports = { | ||
async up({ context: queryInterface, appConfig }) { | ||
await queryInterface.addColumn('forms', 'purgeSubmissionsAfterDays', { | ||
type: DataTypes.INTEGER, | ||
}) | ||
}, | ||
async down({ context: queryInterface, appConfig }) { | ||
await queryInterface.removeColumn('forms', 'purgeSubmissionsAfterDays') | ||
}, | ||
} |
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
Oops, something went wrong.