-// Sequelize always skip the update if we only update updatedAt field
-function setAsUpdated (table: string, id: number, transaction?: Transaction) {
- return sequelizeTypescript.query(
- `UPDATE "${table}" SET "updatedAt" = :updatedAt WHERE id = :id`,
- {
- replacements: { table, id, updatedAt: new Date() },
- type: QueryTypes.UPDATE,
- transaction
- }
- )
+function deleteAllModels <T extends Pick<Model, 'destroy'>> (models: T[], transaction: Transaction) {
+ return Promise.all(models.map(f => f.destroy({ transaction })))
+}
+
+// ---------------------------------------------------------------------------
+
+function runInReadCommittedTransaction <T> (fn: (t: Transaction) => Promise<T>) {
+ const options = { isolationLevel: Transaction.ISOLATION_LEVELS.READ_COMMITTED }
+
+ return sequelizeTypescript.transaction(options, t => fn(t))
+}
+
+function afterCommitIfTransaction (t: Transaction, fn: Function) {
+ if (t) return t.afterCommit(() => fn())
+
+ return fn()