File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed
Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -204,17 +204,17 @@ export class ClaimRevisionService {
204204 if ( sources && Array . isArray ( sources ) ) {
205205 for ( let source of sources ) {
206206 try {
207- if ( typeof source === "string" ) {
207+ const existingSource = await this . sourceService . findHref ( source ) ;
208+ if ( existingSource && existingSource . length > 0 ) {
209+ for ( let source of existingSource ) {
210+ await this . sourceService . updateTargetId ( source . _id , claimId ) ;
211+ }
212+ } else {
208213 await this . sourceService . create ( {
209214 href : source ,
210215 targetId : claimId ,
211216 targetModel : SourceTargetModel . Claim ,
212217 } ) ;
213- } else {
214- await this . sourceService . updateTargetId (
215- source . _id ,
216- claimId
217- ) ;
218218 }
219219 } catch ( e ) {
220220 this . logger . error ( e ) ;
Original file line number Diff line number Diff line change @@ -63,6 +63,10 @@ export class SourceService {
6363 return this . SourceModel . find ( { match } , { _id : 1 , href : 1 } ) ;
6464 }
6565
66+ findHref ( href : string ) {
67+ return this . SourceModel . find ( { href } ) . exec ( ) ;
68+ }
69+
6670 getById ( _id ) {
6771 return this . SourceModel . findById ( _id ) ;
6872 }
You can’t perform that action at this time.
0 commit comments