Skip to content

Commit

Permalink
Merge pull request #1286 from AletheiaFact/fixed-claim-review-creation
Browse files Browse the repository at this point in the history
Added `target` and `targetModel` fields in claim review schema
  • Loading branch information
thesocialdev authored Jul 18, 2024
2 parents feea970 + b7fd423 commit 6c18460
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Db } from "mongodb";

export async function up(db: Db) {
const claimReviewCursor = await db.collection("claimreviews").find();

while (await claimReviewCursor.hasNext()) {
const claimReview = await claimReviewCursor.next();
if (claimReview.claim) {
await db.collection("claimreviews").updateOne(
{ _id: claimReview._id },
{
$set: {
target: claimReview.claim,
targetModel: "Claim",
},
$unset: {
claim: undefined,
},
}
);
}

if (claimReview.source) {
await db.collection("claimreviews").updateOne(
{ _id: claimReview._id },
{
$set: {
target: claimReview.source,
targetModel: "Source",
},
$unset: {
source: undefined,
},
}
);
}
}
}
53 changes: 28 additions & 25 deletions server/claim-review/claim-review.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { SentenceService } from "../claim/types/sentence/sentence.service";
import { REQUEST } from "@nestjs/core";
import type { BaseRequest } from "../types";
import { ImageService } from "../claim/types/image/image.service";
import { ContentModelEnum } from "../types/enums";
import { ContentModelEnum, ReviewTaskTypeEnum } from "../types/enums";
import { NameSpaceEnum } from "../auth/name-space/schemas/name-space.schema";
import { EditorParseService } from "../editor-parse/editor-parse.service";
import { WikidataService } from "../wikidata/wikidata.service";
Expand All @@ -38,11 +38,11 @@ export class ClaimReviewService {
// Currently only list claim reviews
const pipeline = this.ClaimReviewModel.find({
...query,
source: { $exists: false },
targetModel: ReviewTaskTypeEnum.Claim,
})
.sort(latest ? { date: -1 } : { _id: order === "asc" ? 1 : -1 })
.populate({
path: "claim",
path: "target",
model: "Claim",
populate: {
path: "latestRevision",
Expand Down Expand Up @@ -82,10 +82,13 @@ export class ClaimReviewService {
}

async listDailyClaimReviews(query) {
const pipeline = this.ClaimReviewModel.find(query)
const pipeline = this.ClaimReviewModel.find({
...query,
targetModel: ReviewTaskTypeEnum.Claim,
})
.sort({ _id: 1 })
.populate({
path: "claim",
path: "target",
model: "Claim",
populate: {
path: "latestRevision",
Expand Down Expand Up @@ -131,7 +134,7 @@ export class ClaimReviewService {

async agreggateClassification(match: any) {
const claimReviews = await this.ClaimReviewModel.find(match).populate({
path: "claim",
path: "target",
model: "Claim",
match: {
"claim.isHidden": false,
Expand All @@ -158,17 +161,17 @@ export class ClaimReviewService {
{
$lookup: {
from: "claims",
localField: "claim",
localField: "target",
foreignField: "_id",
as: "claim",
as: "target",
},
},
{ $unwind: "$claim" },
{ $unwind: "$target" },
{
$match: {
"personality.isDeleted": false,
"claim.isHidden": query.isHidden,
"claim.isDeleted": false,
"target.isHidden": query.isHidden,
"target.isDeleted": false,
},
}
);
Expand All @@ -192,7 +195,7 @@ export class ClaimReviewService {

async getReviewStatsByClaimId(claimId) {
const reviews = await this.ClaimReviewModel.find({
claim: claimId,
target: claimId,
isDeleted: false,
isPublished: true,
isHidden: false,
Expand All @@ -210,7 +213,7 @@ export class ClaimReviewService {
async getReviewsByClaimId(claimId) {
const classificationCounts = {};
const claimReviews = await this.ClaimReviewModel.find({
claim: claimId,
target: claimId,
isDeleted: false,
isPublished: true,
isHidden: false,
Expand Down Expand Up @@ -365,10 +368,10 @@ export class ClaimReviewService {
this.req.query.nameSpace ||
NameSpaceEnum.Main;
const claim = {
contentModel: review.claim.latestRevision.contentModel,
date: review.claim.latestRevision.date,
slug: review.claim.latestRevision.slug,
title: review.claim.latestRevision.title,
contentModel: review.target.latestRevision.contentModel,
date: review.target.latestRevision.date,
slug: review.target.latestRevision.slug,
title: review.target.latestRevision.title,
};

const isContentImage = claim.contentModel === ContentModelEnum.Image;
Expand All @@ -382,21 +385,21 @@ export class ClaimReviewService {

let reviewHref =
nameSpace !== NameSpaceEnum.Main
? `/${nameSpace}/claim/${review.claim.latestRevision.claimId}`
: `/claim/${review.claim.latestRevision.claimId}`;
? `/${nameSpace}/claim/${review.target.latestRevision.claimId}`
: `/claim/${review.target.latestRevision.claimId}`;

if (isContentInformativeNews) {
reviewHref =
nameSpace !== NameSpaceEnum.Main
? `/${nameSpace}/claim/${review.claim.slug}`
: `/claim/${review.claim.slug}`;
? `/${nameSpace}/claim/${review.target.slug}`
: `/claim/${review.target.slug}`;
}

if (personality) {
reviewHref =
nameSpace !== NameSpaceEnum.Main
? `/${nameSpace}/personality/${personality?.slug}/claim/${review.claim.slug}`
: `/personality/${personality?.slug}/claim/${review.claim.slug}`;
? `/${nameSpace}/personality/${personality?.slug}/claim/${review.target.slug}`
: `/personality/${personality?.slug}/claim/${review.target.slug}`;
}

reviewHref += isContentImage
Expand All @@ -405,8 +408,8 @@ export class ClaimReviewService {
if (isContentDebate) {
reviewHref =
nameSpace !== NameSpaceEnum.Main
? `/${nameSpace}/claim/${review.claim.latestRevision.claimId}/debate`
: `/claim/${review.claim.latestRevision.claimId}/debate`;
? `/${nameSpace}/claim/${review.target.latestRevision.claimId}/debate`
: `/claim/${review.target.latestRevision.claimId}/debate`;
}

return {
Expand Down
13 changes: 4 additions & 9 deletions server/claim-review/schemas/claim-review.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,19 @@ export type ClaimReviewDocument = ClaimReview & mongoose.Document;

@Schema({ toObject: { virtuals: true }, toJSON: { virtuals: true } })
export class ClaimReview {
@Prop({
type: mongoose.Types.ObjectId,
required: false,
ref: "Claim",
})
claim: Claim;

@Prop({
type: mongoose.Types.ObjectId,
required: false,
ref: "Personality",
})
personality: Personality;

// TODO: Add targetModel field and use a single field to reference the target instead having source and claim fields
@Prop({
type: mongoose.Types.ObjectId,
required: false,
ref: "Source",
})
source: Source;
target: mongoose.Types.ObjectId;

@Prop({
type: mongoose.Types.ObjectId,
Expand Down Expand Up @@ -77,6 +69,9 @@ export class ClaimReview {

@Prop({ default: NameSpaceEnum.Main, required: true })
nameSpace: string;

@Prop({ required: true, type: String })
targetModel: string;
}

const ClaimReviewSchemaRaw = SchemaFactory.createForClass(ClaimReview);
Expand Down
2 changes: 1 addition & 1 deletion server/home/home.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class HomeController {
public async showHome(@Req() req: BaseRequest, @Res() res: Response) {
const parsedUrl = parse(req.url, true);
const reviews = await this.claimReviewService.listAll({
page: 1,
page: 0,
pageSize: 6,
order: "asc",
query: {
Expand Down
10 changes: 8 additions & 2 deletions server/review-task/review-task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ export class ReviewTaskService {
data_hash,
machine,
reportModel,
nameSpace
nameSpace,
target,
targetModel
) {
const reviewData = machine.context.review;

Expand All @@ -356,6 +358,8 @@ export class ReviewTaskService {
...reviewData,
report,
nameSpace,
target,
targetModel,
},
data_hash,
reportModel
Expand Down Expand Up @@ -744,7 +748,9 @@ export class ReviewTaskService {
data_hash,
reviewTaskMachine.machine,
reportModel,
nameSpace
nameSpace,
reviewTaskMachine.target,
reviewTaskMachine.reviewTaskType
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/tests/claim-review.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe("ClaimReviewController (e2e)", () => {
.expect(200)
.expect(({ body }) => {
claimReviewId = body.review._id;
expect(body.review.claim).toEqual(claimId.toString());
expect(body.review.target).toEqual(claimId.toString());
expect(body.review.personality).toEqual(
personalitiesId[0].toString()
);
Expand Down
3 changes: 2 additions & 1 deletion server/tests/utils/ClaimReviewMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export const ReviewMock = (claimId, personalitiesId, reportId, userId) => ({
isDeleted: false,
deletedAt: null,
personality: ObjectId(personalitiesId[0]),
claim: ObjectId(claimId),
target: ObjectId(claimId),
targetModel: "Claim",
usersId: [ObjectId(userId)],
report: ObjectId(reportId),
data_hash: "4be75d25957a3cc0dbc6975a6939a385",
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextAreaAutoSize.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from "styled-components";
import colors from "../styles/colors";
import { TextareaAutosize } from "@mui/base";
import { TextareaAutosize } from "@mui/material";

const AletheiaTextAreaAutoSize = styled(TextareaAutosize)`
background: ${(props) => (props.white ? colors.white : colors.lightGray)};
Expand Down

0 comments on commit 6c18460

Please sign in to comment.