Skip to content

Commit 4ee73fb

Browse files
Merge pull request #2090 from AletheiaFact/refactor-filters-Generalize-filtering-mechanism-for-Verification-Request-board
POC: New board on verification request page
2 parents 489f38a + 6678a57 commit 4ee73fb

26 files changed

+1258
-552
lines changed

public/locales/en/search.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"searchPageTittle": "Search",
66
"searchInputLabel": "searching",
77
"advancedSearchLabel": "Advanced search",
8-
"advancedSearchPlaceHolder": "Filter by topics"
8+
"advancedSearchPlaceHolder": "Enter a topic..."
9+
910
}

public/locales/en/verificationRequest.json

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,26 @@
5858
"contentFilterLabel": "Content:",
5959
"filterByTypeLabel": "Filter by",
6060
"topicsFilterOption": "Topics",
61+
"impactAreaFilterOption": "Impact Areas",
6162
"contentFilterOption": "Content",
6263
"filterByContentLabel": "Filter by Content",
6364
"applyButtonLabel": "Apply",
6465
"showText": "Show",
65-
"reportedContent": "Reported Content",
66-
"contentTypeLabel": "Content Type",
67-
"receptionChannelLabel": "Reception Channel",
68-
"impactAreaLabel": "Impact Area",
69-
"severityLabel": "Severity",
70-
"editVerificationRequestSuccess": "Verification Request edited successfully",
71-
"editVerificationRequestError": "Error while editing the Verification Request",
72-
"titleEditVerificationRequest": "Verification Request Edition"
73-
}
66+
"statusPreTriage": "Pre Triage",
67+
"statusInTriage": "In Triage",
68+
"statusPosted": "Posted",
69+
"statusDeclined": "Declined",
70+
"allPriorities": "All Priorities",
71+
"allSourceChannels": "All Source Channels",
72+
"priorityCritical": "Critical",
73+
"priorityHigh": "High",
74+
"priorityMedium": "Medium",
75+
"priorityLow": "Low",
76+
"automated_monitoring": "Automated Monitoring",
77+
"filterByPriority": "Filter by Priority",
78+
"filterBySourceChannel": "Filter by Source Channel",
79+
"noRequestsInStatus": "No requests in this status",
80+
"statusFilterOption": "Status",
81+
"statusFilterLabel": "Status:",
82+
"impactAreaFilterLabel": "Impact Area:"
83+
}

public/locales/pt/search.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"searchPageTittle": "Busca",
66
"searchInputLabel": "pesquisar",
77
"advancedSearchLabel": "Pesquisa avançada",
8-
"advancedSearchPlaceHolder": "Filtrar por tópicos"
8+
"advancedSearchPlaceHolder": "Digite um tópico..."
99
}

public/locales/pt/verificationRequest.json

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,26 @@
5858
"contentFilterLabel": "Conteúdo:",
5959
"filterByTypeLabel": "Filtrar por",
6060
"topicsFilterOption": "Tópicos",
61+
"impactAreaFilterOption": "Áreas de impacto",
6162
"contentFilterOption": "Conteudo",
6263
"filterByContentLabel": "Filtrar por Conteudo",
6364
"applyButtonLabel": "Aplicar",
6465
"showText": "Mostrar",
65-
"reportedContent": "Conteúdo Reportado",
66-
"contentTypeLabel": "Tipo de Conteúdo",
67-
"receptionChannelLabel": "Canal de Recepção",
68-
"impactAreaLabel": "Área de impacto",
69-
"severityLabel": "Prioridade",
70-
"editVerificationRequestSuccess": "Denúncia editada com sucesso",
71-
"editVerificationRequestError": "Erro ao editar a denúncia",
72-
"titleEditVerificationRequest": "Edição de Denúncia"
66+
"statusPreTriage": "Pré-Triagem",
67+
"statusInTriage": "Em Triagem",
68+
"statusPosted": "Publicado",
69+
"statusDeclined": "Recusado",
70+
"allPriorities": "Todas as Prioridades",
71+
"allSourceChannels": "Todos os Canais de Origem",
72+
"priorityCritical": "Crítica",
73+
"priorityHigh": "Alta",
74+
"priorityMedium": "Média",
75+
"priorityLow": "Baixa",
76+
"automated_monitoring": "Monitoramento Automatizado",
77+
"filterByPriority": "Filtrar por Prioridade",
78+
"filterBySourceChannel": "Filtrar por Canal de Origem",
79+
"noRequestsInStatus": "Nenhuma solicitação neste status",
80+
"statusFilterOption": "Status",
81+
"statusFilterLabel": "Status:",
82+
"impactAreaFilterLabel": "Área de Impacto:"
7383
}

server/claim/types/image/image.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Inject, Injectable, NotFoundException, Scope } from "@nestjs/common";
1+
import { BadRequestException, Inject, Injectable, NotFoundException, Scope } from "@nestjs/common";
22
import { InjectModel } from "@nestjs/mongoose";
33
import { HistoryService } from "../../../history/history.service";
44
import { Model } from "mongoose";
@@ -46,6 +46,9 @@ export class ImageService {
4646
}
4747

4848
async getByDataHash(data_hash) {
49+
if (typeof data_hash !== "string" || data_hash.length !== 32) {
50+
throw new BadRequestException("Invalid data hash format.");
51+
}
4952
const report = await this.reportService.findByDataHash(data_hash);
5053
const image = await this.ImageModel.findOne({ data_hash });
5154
if (image) {

server/claim/types/sentence/sentence.service.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable, NotFoundException } from "@nestjs/common";
1+
import { BadRequestException, Injectable, NotFoundException } from "@nestjs/common";
22
import { Model } from "mongoose";
33
import { SentenceDocument, Sentence } from "./schemas/sentence.schema";
44
import { InjectModel } from "@nestjs/mongoose";
@@ -29,8 +29,13 @@ export class SentenceService {
2929
}
3030

3131
async getByDataHash(data_hash) {
32+
if (typeof data_hash !== "string") {
33+
throw new BadRequestException("Invalid data_hash: must be a string.");
34+
}
3235
const report = await this.reportService.findByDataHash(data_hash);
33-
const sentence = await this.SentenceModel.findOne({ data_hash });
36+
const sentence = await this.SentenceModel.findOne({
37+
data_hash: { $eq: data_hash },
38+
});
3439
if (sentence) {
3540
sentence.props = {
3641
classification: report?.classification,
@@ -45,11 +50,18 @@ export class SentenceService {
4550
async updateSentenceWithTopics(topics, data_hash) {
4651
const sentence = await this.getByDataHash(data_hash);
4752

53+
if (!Array.isArray(topics) || !topics.every((t) => typeof t === "string")) {
54+
throw new BadRequestException("Invalid topics array.");
55+
}
56+
4857
const newSentence = {
4958
...sentence.toObject(),
5059
topics,
5160
};
52-
return this.SentenceModel.updateOne({ _id: sentence._id }, newSentence);
61+
return this.SentenceModel.updateOne(
62+
{ _id: sentence._id },
63+
{ $set: { topics } }
64+
);
5365
}
5466

5567
async findAll({
@@ -179,4 +191,4 @@ export class SentenceService {
179191
),
180192
};
181193
}
182-
}
194+
}

server/report/report.service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable } from "@nestjs/common";
1+
import { BadRequestException, Injectable } from "@nestjs/common";
22
import { InjectModel } from "@nestjs/mongoose";
33
import { Model } from "mongoose";
44
import { SourceService } from "../source/source.service";
@@ -54,7 +54,11 @@ export class ReportService {
5454
return this.sourceService.update(data_hash, newSourceBody);
5555
}
5656

57-
findByDataHash(data_hash) {
58-
return this.ReportModel.findOne({ data_hash });
59-
}
57+
findByDataHash(data_hash: string) {
58+
if (!data_hash || typeof data_hash !== "string" || data_hash.length !== 32) {
59+
throw new BadRequestException("Invalid data hash provided.");
60+
}
61+
62+
return this.ReportModel.findOne({ data_hash: { $eq: data_hash } });
6063
}
64+
}

server/topic/topic.controller.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,31 @@ import { ApiTags } from "@nestjs/swagger";
55

66
@Controller()
77
export class TopicController {
8-
constructor(private topicService: TopicService) {}
8+
constructor(private topicService: TopicService) {}
99

10-
@IsPublic()
11-
@ApiTags("topics")
12-
@Get("api/topics")
13-
public async getAll(@Query() getTopics) {
14-
return this.topicService.findAll(getTopics);
15-
}
10+
@IsPublic()
11+
@ApiTags("topics")
12+
@Get("api/topics")
13+
public async getAll(@Query() getTopics) {
14+
return this.topicService.findAll(getTopics);
15+
}
1616

17-
@ApiTags("topics")
18-
@Get("api/topics/search")
19-
async searchTopics(@Query("query") query: string) {
20-
const topicsList = await this.topicService.searchTopics(query);
21-
return topicsList;
22-
}
17+
@ApiTags("topics")
18+
@Get("api/topics/search")
19+
async searchTopics(
20+
@Query("query") query: string,
21+
@Query("limit") limit: number = 10,
22+
@Query("language") language: string = "pt"
23+
) {
24+
return this.topicService.searchTopics(query, language, limit);
25+
}
2326

24-
@ApiTags("topics")
25-
@Post("api/topics")
26-
create(@Body() topicBody, @Req() req) {
27-
return this.topicService.create(
28-
topicBody,
29-
req.cookies.default_language
30-
);
31-
}
27+
@ApiTags("topics")
28+
@Post("api/topics")
29+
create(@Body() topicBody, @Req() req) {
30+
return this.topicService.create(
31+
topicBody,
32+
req.cookies.default_language
33+
);
34+
}
3235
}

server/topic/topic.service.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,23 @@ export class TopicService {
2525
);
2626
}
2727

28-
async searchTopics(query: string, language = "pt"): Promise<Topic[]> {
29-
return this.TopicModel.find({
30-
name: { $regex: query, $options: "i" },
31-
language,
32-
});
28+
async searchTopics(
29+
query: string,
30+
language = "pt",
31+
limit = 10
32+
): Promise<Topic[]> {
33+
if (typeof language !== "string") {
34+
throw new TypeError("Invalid language");
3335
}
3436

37+
return this.TopicModel.find({
38+
name: { $regex: query, $options: "i" },
39+
language: { $eq: language }
40+
})
41+
.limit(limit)
42+
.sort({ name: 1 });
43+
}
44+
3545
/**
3646
*
3747
* @param getTopics options to fetch topics
@@ -121,4 +131,12 @@ export class TopicService {
121131
getBySlug(slug) {
122132
return this.TopicModel.findOne({ slug });
123133
}
134+
/**
135+
*
136+
* @param names topic names array
137+
* @returns topics
138+
*/
139+
findByNames(names: string[]) {
140+
return this.TopicModel.find({ name: { $in: names } });
141+
}
124142
}

server/verification-request/dto/types.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ export enum VerificationRequestStatus {
1818
DECLINED = "Declined",
1919
}
2020

21+
export enum VerificationRequestSourceChannel {
22+
Website = "Web",
23+
Instagram = "instagram",
24+
Whatsapp = "whatsapp",
25+
Telegram = "telegram",
26+
AutomatedMonitoring = "automated_monitoring",
27+
}
28+
2129
export enum VerificationRequestStateMachineStates {
2230
REQUESTING = 'requesting',
2331
CREATING = 'creating',
@@ -42,7 +50,7 @@ export enum VerificationRequestStateMachineEvents {
4250
DEFINE_TOPICS = 'defineTopics',
4351
DEFINE_IMPACT_AREA = 'defineImpactArea',
4452
DEFINE_SEVERITY = 'defineSeverity',
45-
}
53+
}
4654

4755
export const VerificationRequestMessages = {
4856
DESCRIPTIONS: {
@@ -56,7 +64,7 @@ export const VerificationRequestMessages = {
5664
CANCELLING: 'Verification is being cancelled. Status changes to Cancelled.',
5765
CANCELLED: 'Verification has been cancelled.',
5866
ERROR:
59-
'An unhandled error occurred on any of the steps of the request process.\n\nShould notify all entities associated and to inner channels.',
67+
'An unhandled error occurred on any of the steps of the request process.\n\nShould notify all entities associated and to inner channels.',
6068
},
6169
ERRORS: {
6270
LOCATION_SERVICE_PROVIDER_OR_USER_NOT_FOUND: 'Location, Service, Provider or User not found.',

0 commit comments

Comments
 (0)