File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed
Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -204,17 +204,15 @@ export class ClaimRevisionService {
204204 if ( sources && Array . isArray ( sources ) ) {
205205 for ( let source of sources ) {
206206 try {
207- if ( typeof source === "string" ) {
207+ const existingSources = await this . sourceService . getSourceByHref ( source ) ;
208+ if ( existingSources ) {
209+ this . sourceService . updateTargetId ( existingSources . _id , claimId )
210+ } else {
208211 await this . sourceService . create ( {
209212 href : source ,
210213 targetId : claimId ,
211214 targetModel : SourceTargetModel . Claim ,
212215 } ) ;
213- } else {
214- await this . sourceService . updateTargetId (
215- source . _id ,
216- claimId
217- ) ;
218216 }
219217 } catch ( e ) {
220218 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+ getSourceByHref ( href : string ) {
67+ return this . SourceModel . findOne ( { href : { $eq : 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