fix: Refactor collection exports to not send email attachment (#2460)

Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
Saumya Pandey
2021-08-29 02:57:07 +05:30
committed by GitHub
parent 28aef82af9
commit 00ba65f3ef
38 changed files with 1252 additions and 167 deletions

View File

@ -4,7 +4,7 @@ import debug from "debug";
import Router from "koa-router";
import { documentPermanentDeleter } from "../commands/documentPermanentDeleter";
import { AuthenticationError } from "../errors";
import { Document } from "../models";
import { Document, FileOperation } from "../models";
import { Op } from "../sequelize";
const router = new Router();
@ -34,6 +34,26 @@ router.post("utils.gc", async (ctx) => {
log(`Destroyed ${countDeletedDocument} documents`);
log(`Expiring all the collection export older than 30 days…`);
const exports = await FileOperation.unscoped().findAll({
where: {
type: "export",
createdAt: {
[Op.lt]: subDays(new Date(), 30),
},
state: {
[Op.ne]: "expired",
},
},
});
await Promise.all(
exports.map(async (e) => {
await e.expire();
})
);
ctx.body = {
success: true,
};