oura.a f56f95123b Merged PR 376: [Sp17完了MISO]バリデータをクラスを使用した記述に統一する
## 概要
[Task2502: [Sp17完了MISO]バリデータをクラスを使用した記述に統一する](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2502)

バリデータの記述方法をクラスで外だしする形に統一しました。
また、未使用の引数を削除しました。

## レビューポイント
期待通りの修正内容であるか。
未使用の引数を削除してしまったが、問題ないか。

## UIの変更
なし

## 動作確認状況
ローカルで該当バリデーションを使用しているAPIを実行し、動作を確認済み

## 補足
なし
2023-09-01 09:12:52 +00:00

40 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {
registerDecorator,
ValidationOptions,
ValidatorConstraint,
ValidatorConstraintInterface,
} from 'class-validator';
@ValidatorConstraint()
export class IsAdminPassword implements ValidatorConstraintInterface {
validate(value: string): boolean {
// 8文字64文字でなければ早期に不合格
const minLength = 8;
const maxLength = 64;
if (value.length < minLength || value.length > maxLength) {
return false;
}
// 英字の大文字、英字の小文字、アラビア数字、記号(@#$%^&*\-_+=[]{}|\:',.?/`~"();!から2種類以上組み合わせ
const charaTypePattern =
/^((?=.*[a-z])(?=.*[A-Z])|(?=.*[a-z])(?=.*[\d])|(?=.*[a-z])(?=.*[@#$%^&*\\\-_+=\[\]{}|:',.?\/`~"();!])|(?=.*[A-Z])(?=.*[\d])|(?=.*[A-Z])(?=.*[@#$%^&*\\\-_+=\[\]{}|:',.?\/`~"();!])|(?=.*[\d])(?=.*[@#$%^&*\\\-_+=\[\]{}|:',.?\/`~"();!]))[a-zA-Z\d@#$%^&*\\\-_+=\[\]{}|:',.?\/`~"();!]/;
return new RegExp(charaTypePattern).test(value);
}
defaultMessage(): string {
return 'Admin password rule not satisfied';
}
}
export const IsAdminPasswordvalid = (validationOptions?: ValidationOptions) => {
return (object: any, propertyName: string) => {
registerDecorator({
name: 'IsAdminPasswordvalid',
target: object.constructor,
propertyName: propertyName,
constraints: [],
options: validationOptions,
validator: IsAdminPassword,
});
};
};