Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
Added option to disable the profanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
sopyb committed Oct 25, 2023
1 parent 63fa4e0 commit 2112595
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/controllers/roadmapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
responseRoadmapDeleted,
responseRoadmapNotFound,
responseRoadmapNotRated,
responseRoadmapProgressFound, responseRoadmapProgressNotFound,
responseRoadmapProgressFound,
responseRoadmapProgressNotFound,
responseRoadmapProgressUpdated,
responseRoadmapRated,
responseRoadmapUnrated,
Expand All @@ -25,13 +26,16 @@ import {
import {
deleteDBRoadmap,
deleteRoadmapLike,
getRoadmapLike,
getRoadmapObject,
getRoadmapLike, getRoadmapProgress,
getRoadmapProgress,
getUser,
insertRoadmap,
insertRoadmapLike,
insertRoadmapProgress,
updateRoadmap,
updateRoadmapLike, updateRoadmapProgress, insertRoadmapProgress,
updateRoadmapLike,
updateRoadmapProgress,
} from '@src/helpers/databaseManagement';
import { RequestWithBody } from '@src/middleware/validators/validateBody';
import { Roadmap, RoadmapTopic } from '@src/types/models/Roadmap';
Expand All @@ -40,6 +44,8 @@ import { addRoadmapView } from '@src/util/Views';
import logger from 'jet-logger';
import { RoadmapProgress } from '@src/types/models/RoadmapProgress';

const profanityCheckEnabled = false;

export async function createRoadmap(req: RequestWithBody, res: Response) {
// guaranteed to exist by middleware
const { name, description, data, miscData, version } = req.body;
Expand All @@ -57,7 +63,9 @@ export async function createRoadmap(req: RequestWithBody, res: Response) {
if (!topic || !Object.values(RoadmapTopic).includes(topic as RoadmapTopic))
topic = RoadmapTopic.PROGRAMMING;

const isPublic = !Boolean(req.body.isProfane);
const isPublic = profanityCheckEnabled
? !Boolean(req.body.isprofane)
: true;
if (isDraft !== true && isDraft !== false) isDraft = false;
if (!isPublic) isDraft = true;

Expand Down Expand Up @@ -109,8 +117,8 @@ export async function getRoadmap(req: RequestWithSession, res: Response) {
1,
);
const isLiked =
userId !== undefined && userId !== null ?
await db.sumWhere(
userId !== undefined && userId !== null
? await db.sumWhere(
'roadmapLikes',
'value',
'roadmapId',
Expand Down Expand Up @@ -153,7 +161,9 @@ export async function updateAboutRoadmap(req: RequestWithBody, res: Response) {
if (!Object.values(RoadmapTopic).includes(topic as RoadmapTopic))
return responseInvalidBody(res);

const isPublic = !Boolean(req.body.isProfane);
const isPublic = profanityCheckEnabled
? !Boolean(req.body.isprofane)
: roadmap.isPublic;

roadmap.set({
name: name as string,
Expand Down Expand Up @@ -193,7 +203,9 @@ export async function updateAllRoadmap(req: RequestWithBody, res: Response) {
if (!Object.values(RoadmapTopic).includes(topic as RoadmapTopic))
return responseInvalidBody(res);

const isPublic = !Boolean(req.body.isProfane);
const isPublic = profanityCheckEnabled
? !Boolean(req.body.isprofane)
: roadmap.isPublic;
if (!isPublic) isDraft = true;

roadmap.set({
Expand Down Expand Up @@ -227,7 +239,7 @@ export async function updateNameRoadmap(req: RequestWithBody, res: Response) {
if (roadmap.userId !== userId) return responseNotAllowed(res);

const { name } = req.body;
const isPublic = !Boolean(req.body.isProfane);
const isPublic = profanityCheckEnabled;

if (!name) return responseServerError(res);

Expand Down Expand Up @@ -261,7 +273,9 @@ export async function updateDescriptionRoadmap(
if (roadmap.userId !== userId) return responseNotAllowed(res);

const { description } = req.body;
const isPublic = !Boolean(req.body.isProfane);
const isPublic = profanityCheckEnabled
? !Boolean(req.body.isprofane)
: roadmap.isPublic;

if (!description) return responseServerError(res);

Expand Down Expand Up @@ -292,7 +306,9 @@ export async function updateDataRoadmap(req: RequestWithBody, res: Response) {
if (roadmap.userId !== userId) return responseNotAllowed(res);

const { data } = req.body;
const isPublic = !Boolean(req.body.isProfane);
const isPublic = profanityCheckEnabled
? !Boolean(req.body.isprofane)
: roadmap.isPublic;

if (!data) return responseServerError(res);

Expand Down

0 comments on commit 2112595

Please sign in to comment.