Skip to content

Commit

Permalink
Merge pull request #1242 from AletheiaFact/crate-sources-crud
Browse files Browse the repository at this point in the history
Create sources CRUD
  • Loading branch information
thesocialdev committed Jun 8, 2024
2 parents 74466a7 + bf819d2 commit 1e32cf2
Show file tree
Hide file tree
Showing 48 changed files with 1,031 additions and 142 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
54 changes: 54 additions & 0 deletions cypress/e2e/tests/header.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ describe("Test the header menus", () => {
});

describe("Test the side drawer routes", () => {
it("Open side bar and click personality", () => {
cy.get(locators.menu.SIDE_MENU).click();
cy.get("[data-cy=testPersonalitytItem]").click();
cy.url().should("contains", "personality");
});

it("Open side bar and click claim", () => {
cy.get(locators.menu.SIDE_MENU).click();
cy.get("[data-cy=testClaimtItem]").click();
cy.url().should("contains", "claim");
});

it("Open side bar and click sources", () => {
cy.get(locators.menu.SIDE_MENU).click();
cy.get("[data-cy=testSourcestItem]").click();
cy.url().should("contains", "sources");
});

it("Open side bar and click about", () => {
cy.get(locators.menu.SIDE_MENU).click();
cy.get("[data-cy=testAboutItem]").click();
Expand All @@ -28,6 +46,42 @@ describe("Test the header menus", () => {
cy.get("[data-cy=testCodeOfConductItem]").click();
cy.url().should("contains", "code-of-conduct");
});

it("Open side bar and click supportive materials", () => {
cy.get(locators.menu.SIDE_MENU).click();
cy.get("[data-cy=testSupportiveMaterialsItem]").click();
cy.url().should("contains", "supportive-materials");
});
});

describe("Test the side drawer routes that requires user permission", () => {
it("Should be able to access Kanban page when logged in", () => {
cy.login();
cy.get(locators.menu.SIDE_MENU).click();
cy.get("[data-cy=testKanbantItem]").click();
cy.url().should("contains", "kanban");
});

it("Should be able to access Admin page when logged in", () => {
cy.login();
cy.get(locators.menu.SIDE_MENU).click();
cy.get("[data-cy=testadminItem]").click();
cy.url().should("contains", "admin");
});

it("Should be able to access Badges page when logged in", () => {
cy.login();
cy.get(locators.menu.SIDE_MENU).click();
cy.get("[data-cy=testadminBadgeItem]").click();
cy.url().should("contains", "admin/badges");
});

it("Should be able to access Namespaces page when logged in", () => {
cy.login();
cy.get(locators.menu.SIDE_MENU).click();
cy.get("[data-cy=testadminNameSpaceItem]").click();
cy.url().should("contains", "admin/name-spaces");
});
});

describe("Test the user icon menu actions", () => {
Expand Down
1 change: 1 addition & 0 deletions public/locales/en/affix.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"affixButtonTitle": "Click here to add a claim or a personality",
"affixButtonCreateClaim": "Click here to add a claim",
"affixButtonCreatePersonality": "Click here to add a personality",
"affixButtonCreateVerifiedSources": "Click here to add a source",
"affixCallToActionButton": "Click here",
"AffixCloseTooltip": "Close"
}
1 change: 1 addition & 0 deletions public/locales/en/claim.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"errorWhileFetching": "Error while fetching Claim",
"cardLinkToImage": "see full image",
"cardLinkToDebate": "see full debate",
"claimListTitle": "Repository",
"claimListHeader": "Claims",
"imageAlreadyExists": "Image already exists in the platform",

Expand Down
4 changes: 2 additions & 2 deletions public/locales/en/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"claimItem": "Claims",
"kanbanItem": "Kanban",
"nameSpaceItem": "Namespace",
"supportiveMaterials": "Supportive Materials"

"supportiveMaterials": "Supportive Materials",
"sourcesItem": "Sources"
}
6 changes: 4 additions & 2 deletions public/locales/en/seo.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"sourcesDescription": "Claim sources {{claimId}}",
"claimReviewDescription": "See sentence reviews {{sentence}} on AletheiaFact.org",
"siteName": "AletheiaFact.org",
"noPersonalityClaimListTitle": "Claims",
"noPersonalityClaimListDescription": "See claims without a related personality"
"claimListTitle": "Claims",
"claimListDescription": "See claims on AletheiaFact.org",
"createSourceTitle": "Create source",
"createSourceDescription": "Create sources to AletheiaFact.org"
}
7 changes: 6 additions & 1 deletion public/locales/en/sourceForm.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
"editorEmptySourcesWithButton": "Add sources by selecting the desire text or clicking in the button.",
"editorEmptySources": "Add sources by selecting the desire text.",
"intertArchiveTooltip": "Internet Archive prevents your source may your source never cease to exist",
"deleteSourceButton": "Delete"
"deleteSourceButton": "Delete",
"sourceLabel": "Source",
"summaryLabel": "Summary",
"summaryPlaceholder": "Insert the source summary",
"classificationLabel": "Review this source",
"classificationPlaceholder": "Choose a classification"
}
8 changes: 8 additions & 0 deletions public/locales/en/sources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"sourceListHeader": "Sources",
"sourceReview": "Source reviewed as ",
"sourceCardButton": "Access the source",
"sourceCreateCTAButton": "Create source",
"sourcesCreateSuccess": "Source created successfully",
"sourcesCreateError": "Error while creating the source"
}
1 change: 1 addition & 0 deletions public/locales/pt/affix.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"affixButtonTitle": "Clique aqui para adicionar um discurso ou personalidade",
"affixButtonCreateClaim": "Clique aqui para adicionar um discurso",
"affixButtonCreatePersonality": "Clique aqui para adicionar uma personalidade",
"affixButtonCreateVerifiedSources": "Clique aqui para adicionar uma informação checada",
"affixCallToActionButton": "Clique aqui",
"AffixCloseTooltip": "Fechar"
}
3 changes: 2 additions & 1 deletion public/locales/pt/claim.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"errorWhileFetching": "Erro ao buscar o Discurso",
"cardLinkToImage": "veja a imagem completa",
"cardLinkToDebate": "veja o debate completo",
"claimListHeader": "Repositório",
"claimListTitle": "Repositório",
"claimListHeader": "Afirmações",
"imageAlreadyExists": "Essa imagem já existe em nossa plataforma",

"hideModalTitle": "Esconder afirmação",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/pt/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"claimItem": "Repositório",
"kanbanItem": "Meu Trabalho",
"nameSpaceItem": "Namespace",
"supportiveMaterials": "Materiais de Apoio"
"supportiveMaterials": "Materiais de Apoio",
"sourcesItem": "Fontes"
}
6 changes: 4 additions & 2 deletions public/locales/pt/seo.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"sourcesDescription": "Fontes do discurso {{claimId}}",
"claimReviewDescription": "Veja as revisões da sentença {{sentence}} na AletheiaFact.org",
"siteName": "AletheiaFact.org",
"noPersonalityClaimListTitle": "Declarações",
"noPersonalityClaimListDescription": "Veja declarações sem personalidade associada"
"claimListTitle": "Declarações",
"claimListDescription": "Veja declarações na AletheiaFact.org",
"createSourceTitle": "Adicione uma fonte",
"createSourceDescription": "Adiciona uma fonte na AletheiaFact.org"
}
7 changes: 6 additions & 1 deletion public/locales/pt/sourceForm.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
"editorEmptySourcesWithButton": "Adicione fontes selecionando o texto desejado ou clicando no botão.",
"editorEmptySources": "Adicione fontes selecionando o texto desejado.",
"intertArchiveTooltip": "Internet Archive previne que sua fonte não deixe de existir",
"deleteSourceButton": "Deletar"
"deleteSourceButton": "Deletar",
"sourceLabel": "Fonte",
"summaryLabel": "Resumo",
"summaryPlaceholder": "Insira o resumo da fonte",
"classificationLabel": "Revise essa fonte",
"classificationPlaceholder": "Selecione uma classificação"
}
8 changes: 8 additions & 0 deletions public/locales/pt/sources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"sourceListHeader": "Fontes",
"sourceReview": "Fonte avaliada como ",
"sourceCardButton": "Acesse a fonte",
"sourceCreateCTAButton": "Incluir fonte",
"sourcesCreateSuccess": "Fonte criado com sucesso",
"sourcesCreateError": "Erro ao criar a fonte"
}
6 changes: 3 additions & 3 deletions server/claim/claim.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ export class ClaimController {
await this.viewService.getNextServer().render(
req,
res,
"/image-claims-page",
"/claim-list-page",
Object.assign(parsedUrl.query, {
nameSpace: req.params.namespace,
})
Expand Down Expand Up @@ -740,7 +740,7 @@ export class ClaimController {
await this.viewService.getNextServer().render(
req,
res,
"/sources-page",
"/claim-sources-page",
Object.assign(parsedUrl.query, {
targetId: claim._id,
nameSpace: namespace,
Expand Down Expand Up @@ -779,7 +779,7 @@ export class ClaimController {
await this.viewService.getNextServer().render(
req,
res,
"/sources-page",
"/claim-sources-page",
Object.assign(parsedUrl.query, {
targetId: report._id,
nameSpace: req.params.namespace,
Expand Down
55 changes: 43 additions & 12 deletions server/daily-report/daily-report.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@ import { AbilitiesGuard } from "../auth/ability/abilities.guard";
import { DailyReportService } from "../daily-report/daily-report.service";
import { ClaimReviewService } from "../claim-review/claim-review.service";
import { NotificationService } from "../notifications/notifications.service";
import { SourceService } from "../source/source.service";
import { SourceProps } from "../source/dto/create-source.dto";

interface DailyReportQuery {
date?: object;
isHidden?: boolean;
isDeleted?: boolean;
nameSpace: string;
props?: SourceProps;
}

@Controller()
export class DailyReportController {
constructor(
private readonly dailyReportService: DailyReportService,
private claimReviewService: ClaimReviewService,
private notificationService: NotificationService
private notificationService: NotificationService,
private sourceService: SourceService
) {}

@Post("api/daily-report/topic/:topic/send/:nameSpace")
Expand All @@ -23,37 +34,57 @@ export class DailyReportController {
@Param("topic") topic,
@Param("nameSpace") nameSpace
) {
const query: any = { isHidden: false, isDeleted: false, nameSpace };
const claimReviewsQuery: DailyReportQuery = {
isHidden: false,
isDeleted: false,
nameSpace,
};
const sourceReviewsQuery: DailyReportQuery = { nameSpace };

const [lastDailyReportSent] =
await this.dailyReportService.getLastDailyReportSent({ nameSpace });

if (lastDailyReportSent) {
query.date = { $gt: lastDailyReportSent?.date };
claimReviewsQuery.date = { $gt: lastDailyReportSent?.date };
sourceReviewsQuery["props.date"] = {
$gt: lastDailyReportSent?.date,
};
}

const dailyClaimReviews =
await this.claimReviewService.listDailyClaimReviews(query);
const dailyReviews = (
await Promise.all([
this.claimReviewService.listDailyClaimReviews(
claimReviewsQuery
),
this.sourceService.listAllDailySourceReviews(
sourceReviewsQuery
),
])
).reduce((acc, current) => [...acc, ...current], []);

if (dailyReviews.length > 0) {
const reports = dailyReviews.map((review: any) =>
review?.report?._id ? review.report._id : review._id
);

if (dailyClaimReviews.length > 0) {
const reportIds = dailyClaimReviews.map(({ report }) => report._id);
await this.dailyReportService.create({
reports: reportIds,
reports,
nameSpace,
date: new Date(),
nameSpace: nameSpace,
});
}

const dailyReport = await this.dailyReportService.generateDailyReport(
dailyClaimReviews,
dailyReviews,
nameSpace
);

this.notificationService.sendDailyReviewsEmail(topic, dailyReport);

if (dailyClaimReviews.length < 1) {
if (dailyReviews.length < 1) {
throw new Error("No daily reports today");
}

return dailyClaimReviews;
return dailyReviews;
}
}
2 changes: 2 additions & 0 deletions server/daily-report/daily-report.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ClaimReviewModule } from "../claim-review/claim-review.module";
import { NotificationModule } from "../notifications/notifications.module";
import { DailyReportController } from "./daily-report.controller";
import { ConfigModule } from "@nestjs/config";
import { SourceModule } from "../source/source.module";

export const DailyReportModel = MongooseModule.forFeature([
{
Expand All @@ -20,6 +21,7 @@ export const DailyReportModel = MongooseModule.forFeature([
imports: [
DailyReportModel,
ClaimReviewModule,
SourceModule,
SummarizationModule,
AbilityModule,
NotificationModule,
Expand Down
4 changes: 2 additions & 2 deletions server/daily-report/daily-report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ export class DailyReportService {
}

async generateDailyReport(
dailyClaimReviews,
dailyReviews,
nameSpace?: string
): Promise<string> {
try {
const summarizedReviews =
await this.summarizationService.getSummarizedReviews(
dailyClaimReviews
dailyReviews
);

return this.summarizationService.generateHTMLReport(
Expand Down
13 changes: 4 additions & 9 deletions server/daily-report/schemas/daily-report.schema.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import * as mongoose from "mongoose";
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { Report } from "../../report/schemas/report.schema";

export type DailyReportDocument = DailyReport & mongoose.Document;

@Schema({ toObject: { virtuals: true }, toJSON: { virtuals: true } })
export class DailyReport {
@Prop({
type: [
{
type: mongoose.Types.ObjectId,
required: true,
ref: "Report",
},
],
type: mongoose.Types.ObjectId,
required: true,
refPath: "onModel",
})
reports: Report[];
reports: mongoose.Types.ObjectId[];

@Prop({ required: true })
date: Date;
Expand Down
Loading

0 comments on commit 1e32cf2

Please sign in to comment.