From 4e6478474929632e00a47ff0c2d22ef5ccd4a252 Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Thu, 27 Feb 2020 18:11:50 -0800 Subject: [PATCH 1/4] fix(demo): switch to fruit content filter --- examples/first-demo/controllers/comments.ts | 6 ++-- examples/first-demo/controllers/posts.ts | 20 ++++++------ examples/first-demo/pages/posts/[id].tsx | 2 ++ examples/first-demo/pages/posts/[id]/edit.js | 2 ++ examples/first-demo/pages/posts/index.tsx | 2 +- examples/first-demo/pages/posts/new.js | 2 ++ examples/first-demo/utils/contentFilter.ts | 34 ++++++++++++++++++++ 7 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 examples/first-demo/utils/contentFilter.ts diff --git a/examples/first-demo/controllers/comments.ts b/examples/first-demo/controllers/comments.ts index 2348ed98ee..145756cebb 100644 --- a/examples/first-demo/controllers/comments.ts +++ b/examples/first-demo/controllers/comments.ts @@ -1,5 +1,5 @@ import {Controller} from '@blitzjs/core' -import alex from 'alex' +import {validContent} from '../utils/contentFilter' export const CommentsController = Controller(({db}) => ({ name: 'CommentsController', @@ -7,8 +7,8 @@ export const CommentsController = Controller(({db}) => ({ permit: ['content'], async create(params, newData) { - if (alex(newData.content).messages.length || newData.content?.toLowerCase().includes('4chan')) { - newData.content = 'Be nice' + if (!validContent(newData.content)) { + newData.content = 'Fruit' } const data = await db.comment.create({ diff --git a/examples/first-demo/controllers/posts.ts b/examples/first-demo/controllers/posts.ts index d04f75001e..fa044b8b20 100644 --- a/examples/first-demo/controllers/posts.ts +++ b/examples/first-demo/controllers/posts.ts @@ -1,5 +1,5 @@ import {Controller} from '@blitzjs/core' -import alex from 'alex' +import {validContent} from '../utils/contentFilter' export const PostsController = Controller(({db}) => ({ name: 'PostsController', @@ -7,7 +7,7 @@ export const PostsController = Controller(({db}) => ({ permit: ['title', 'content'], async index() { - const posts = await db.post.findMany({orderBy: {id: 'asc'}}) + const posts = await db.post.findMany({orderBy: {id: 'desc'}, first: 20}) return { data: {posts}, @@ -23,11 +23,11 @@ export const PostsController = Controller(({db}) => ({ }, async create(params, newData) { - if (alex(newData.title).messages.length || newData.title?.toLowerCase().includes('4chan')) { - newData.title = 'Be nice' + if (!validContent(newData.title)) { + newData.title = 'Fruit' } - if (alex(newData.content).messages.length || newData.content?.toLowerCase().includes('4chan')) { - newData.content = 'Be nice' + if (!validContent(newData.content)) { + newData.content = 'Fruit' } const data = await db.post.create({ @@ -44,11 +44,11 @@ export const PostsController = Controller(({db}) => ({ }, async update(params, newData) { - if (alex(newData.title).messages.length || newData.title?.toLowerCase().includes('4chan')) { - newData.title = 'Be nice' + if (!validContent(newData.title)) { + newData.title = 'Fruit' } - if (alex(newData.content).messages.length || newData.content?.toLowerCase().includes('4chan')) { - newData.content = 'Be nice' + if (!validContent(newData.content)) { + newData.content = 'Fruit' } const data = await db.post.update({ diff --git a/examples/first-demo/pages/posts/[id].tsx b/examples/first-demo/pages/posts/[id].tsx index e91c9185af..5164d3f081 100644 --- a/examples/first-demo/pages/posts/[id].tsx +++ b/examples/first-demo/pages/posts/[id].tsx @@ -63,6 +63,8 @@ function Page({post}) { + +
For your safety, content can only be the name of a fruit
) } diff --git a/examples/first-demo/pages/posts/[id]/edit.js b/examples/first-demo/pages/posts/[id]/edit.js index df34c3faab..43b653ce7f 100644 --- a/examples/first-demo/pages/posts/[id]/edit.js +++ b/examples/first-demo/pages/posts/[id]/edit.js @@ -17,6 +17,8 @@ function Page({post}) {For your safety, content can only be the name of a fruit
+