Merged PR 770: AuthorIDを大文字とアンダースコアのみとするバリデーションを入れたことによるデグレの解消
## 概要 [Task3784: AuthorIDを大文字とアンダースコアのみとするバリデーションを入れたことによるデグレの解消](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3784) - タイトルの通り - ロールがAuthorの時のみチェックするように修正 ## レビューポイント - 特になし ## UIの変更 - Before/Afterのスクショなど - スクショ置き場 ## 動作確認状況 - ローカルで確認、develop環境で確認など ## 補足 - 相談、参考資料などがあれば
This commit is contained in:
parent
12d168d14c
commit
ebbf957419
@ -5,11 +5,26 @@ import {
|
||||
ValidationOptions,
|
||||
registerDecorator,
|
||||
} from 'class-validator';
|
||||
import {
|
||||
PostUpdateUserRequest,
|
||||
SignupRequest,
|
||||
} from '../../features/users/types/types';
|
||||
import { USER_ROLES } from '../../constants';
|
||||
|
||||
// 大文字英数字とアンダースコアのみを許可するバリデータ
|
||||
@ValidatorConstraint({ name: 'IsAuthorId', async: false })
|
||||
export class IsAuthorId implements ValidatorConstraintInterface {
|
||||
validate(value: any, args: ValidationArguments) {
|
||||
const request = args.object as SignupRequest | PostUpdateUserRequest;
|
||||
// requestの存在チェック
|
||||
if (!request) {
|
||||
return false;
|
||||
}
|
||||
const { role } = request;
|
||||
// roleがauthor以外の場合はスキップする
|
||||
if (role !== USER_ROLES.AUTHOR) {
|
||||
return true;
|
||||
}
|
||||
return /^[A-Z0-9_]*$/.test(value);
|
||||
}
|
||||
defaultMessage(args: ValidationArguments) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user