Skip to content

Commit

Permalink
fix: don't allow "@" in gratitude comment (#2542)
Browse files Browse the repository at this point in the history
* fix: don't allow "@" in gratitude comment

* chore: use ready-made decorator for validation
  • Loading branch information
AlreadyBored authored Oct 29, 2024
1 parent 758a203 commit 4877de9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions client/src/pages/gratitude.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ function GratitudePage() {
whitespace: true,
message: 'The comment must contain at least 20 characters',
},
{
validator: (_, value) => {
if (value.includes('@')) {
return Promise.reject();
}
return Promise.resolve();
},
message: 'The comment can\'t include "@" symbol',
},
]}
>
<Input.TextArea rows={8} />
Expand Down
5 changes: 4 additions & 1 deletion nestjs/src/gratitudes/dto/create-gratitude.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsArray, IsEnum, IsNotEmpty, IsNumber, IsString, MinLength } from 'class-validator';
import { IsArray, IsEnum, IsNotEmpty, IsNumber, IsString, MinLength, NotContains } from 'class-validator';
import { Badge } from './badge.dto';

export class CreateGratitudeDto {
Expand All @@ -16,6 +16,9 @@ export class CreateGratitudeDto {
@IsNotEmpty()
@IsString()
@MinLength(20)
@NotContains('@', {
message: 'The comment can not contain "@" symbol',
})
@ApiProperty()
comment: string;

Expand Down

0 comments on commit 4877de9

Please sign in to comment.