|
1 | | -import { AnyIdentity, Query, Logger, Logs, LogTransport, LogRecord } from '@akdasa-studios/framework' |
| 1 | +import { AnyIdentity, Query, Logger } from '@akdasa-studios/framework' |
2 | 2 | import { SyncAggregate } from '@lib/SyncAggregate' |
3 | 3 | import { SyncRepository } from '@lib/SyncRepository' |
4 | 4 | import { SyncConflictSolver } from '@lib/SyncConflictSolver' |
@@ -120,30 +120,26 @@ export class SyncService< |
120 | 120 |
|
121 | 121 | for (const sourceEntity of findResult.entities) { |
122 | 122 | let targetEntity: TAggregate|undefined = undefined |
123 | | - try { targetEntity = await target.get(sourceEntity.id) } catch { /** pass */} |
| 123 | + try { targetEntity = await target.get(sourceEntity.id) } catch { /** pass **/ } |
| 124 | + |
124 | 125 | if (!targetEntity) { |
125 | | - this.logger.debug(`${sourceEntity.id.value}: no at target`) |
126 | 126 | repResult.aggregatesSynced++ |
| 127 | + this.logger.debug(`${sourceEntity.id.value}: no at target`) |
127 | 128 | await target.save(this.makeCopy(sourceEntity), repOptions) |
128 | | - await source.save(sourceEntity, repOptions) |
129 | | - } else { |
130 | | - if (sourceEntity.version !== targetEntity.version) { |
131 | | - repResult.aggregatesSynced++ |
132 | | - const winner = this.conflictSolver.solve(sourceEntity, targetEntity) |
133 | | - if (winner === sourceEntity) { |
134 | | - this.logger.debug(`${sourceEntity.id}: source won`) |
135 | | - await target.save(this.makeCopy(sourceEntity), repOptions) |
136 | | - await source.save(sourceEntity, repOptions) |
137 | | - } else { |
138 | | - this.logger.debug(`${sourceEntity.id}: target won`) |
139 | | - await source.save(this.makeCopy(targetEntity), repOptions) |
140 | | - await target.save(targetEntity, repOptions) |
141 | | - } |
| 129 | + } else if (sourceEntity.version !== targetEntity.version) { |
| 130 | + repResult.aggregatesSynced++ |
| 131 | + const winner = this.conflictSolver.solve(sourceEntity, targetEntity) |
| 132 | + if (winner === sourceEntity) { |
| 133 | + this.logger.debug(`${sourceEntity.id}: source won`) |
| 134 | + await target.save(this.makeCopy(sourceEntity), repOptions) |
| 135 | + } else { |
| 136 | + this.logger.debug(`${sourceEntity.id}: target won`) |
| 137 | + await source.save(this.makeCopy(targetEntity), repOptions) |
142 | 138 | } |
143 | 139 | } |
144 | 140 | } |
145 | 141 |
|
146 | | - console.groupEnd() |
| 142 | + this.logger.endGroup() |
147 | 143 | } |
148 | 144 | return repResult |
149 | 145 | } |
|
0 commit comments