chore: Permanent team deletion (#2493)

This commit is contained in:
Tom Moor
2021-09-20 20:58:39 -07:00
committed by GitHub
parent a88b54d26d
commit e1601fbe72
10 changed files with 425 additions and 24 deletions

View File

@ -54,6 +54,22 @@ const Attachment = sequelize.define(
}
);
Attachment.findAllInBatches = async (
query,
callback: (attachments: Array<Attachment>, query: Object) => Promise<void>
) => {
if (!query.offset) query.offset = 0;
if (!query.limit) query.limit = 10;
let results;
do {
results = await Attachment.findAll(query);
await callback(results, query);
query.offset += query.limit;
} while (results.length >= query.limit);
};
Attachment.beforeDestroy(async (model) => {
await deleteFromS3(model.key);
});