Skip to content

Commit

Permalink
Merge pull request #1795 from AletheiaFact/Fixing-duplicate-fonts-bug
Browse files Browse the repository at this point in the history
Fixing duplicate sources bug when creating claim
  • Loading branch information
thesocialdev authored Jan 26, 2025
2 parents 306ec7d + 8212746 commit 61a0b99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 4 additions & 6 deletions server/claim/claim-revision/claim-revision.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,15 @@ export class ClaimRevisionService {
if (sources && Array.isArray(sources)) {
for (let source of sources) {
try {
if (typeof source === "string") {
const existingSources = await this.sourceService.getSourceByHref(source);
if (existingSources) {
this.sourceService.updateTargetId(existingSources._id, claimId)
} else {
await this.sourceService.create({
href: source,
targetId: claimId,
targetModel: SourceTargetModel.Claim,
});
} else {
await this.sourceService.updateTargetId(
source._id,
claimId
);
}
} catch (e) {
this.logger.error(e);
Expand Down
4 changes: 4 additions & 0 deletions server/source/source.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export class SourceService {
return this.SourceModel.find({ match }, { _id: 1, href: 1 });
}

getSourceByHref(href: string) {
return this.SourceModel.findOne({ href: { $eq: href } }).exec();
}

getById(_id) {
return this.SourceModel.findById(_id);
}
Expand Down

0 comments on commit 61a0b99

Please sign in to comment.