Skip to content

Commit 0fb1488

Browse files
committed
Merge pull request #1795 from AletheiaFact/Fixing-duplicate-fonts-bug
Fixing duplicate sources bug when creating claim
1 parent 32ef811 commit 0fb1488

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

server/claim/claim-revision/claim-revision.service.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff 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);

server/source/source.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)