diff options
Diffstat (limited to 'server/helpers/database-utils.ts')
-rw-r--r-- | server/helpers/database-utils.ts | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index 6c5068fb0..87f10f913 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts | |||
@@ -79,6 +79,15 @@ function afterCommitIfTransaction (t: Transaction, fn: Function) { | |||
79 | return fn() | 79 | return fn() |
80 | } | 80 | } |
81 | 81 | ||
82 | function deleteNonExistingModels <T extends { hasSameUniqueKeysThan (other: T): boolean } & Model<T>> ( | ||
83 | fromDatabase: T[], | ||
84 | newModels: T[], | ||
85 | t: Transaction | ||
86 | ) { | ||
87 | return fromDatabase.filter(f => !newModels.find(newModel => newModel.hasSameUniqueKeysThan(f))) | ||
88 | .map(f => f.destroy({ transaction: t })) | ||
89 | } | ||
90 | |||
82 | // --------------------------------------------------------------------------- | 91 | // --------------------------------------------------------------------------- |
83 | 92 | ||
84 | export { | 93 | export { |
@@ -86,5 +95,6 @@ export { | |||
86 | retryTransactionWrapper, | 95 | retryTransactionWrapper, |
87 | transactionRetryer, | 96 | transactionRetryer, |
88 | updateInstanceWithAnother, | 97 | updateInstanceWithAnother, |
89 | afterCommitIfTransaction | 98 | afterCommitIfTransaction, |
99 | deleteNonExistingModels | ||
90 | } | 100 | } |