## 概要 [Task2428: API実装(TypistGroup追加API)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2428) - IFを修正 - typistIdsの要素が数値であることをOpenAPIに明記する - typistIdsのチェックバリデータを追加・修正 - entity修正 - typistGuroup作成処理を実装 - テスト作成 ## レビューポイント - テストケースは足りているか - entityの修正に問題はないか - typistIdsのチェック処理で漏れているものはないか ## UIの変更 - Before/Afterのスクショなど - スクショ置き場 ## 動作確認状況 - ローカルで確認 ## 補足 - 相談、参考資料などがあれば
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import {
|
|
registerDecorator,
|
|
ValidationOptions,
|
|
ValidationArguments,
|
|
} from 'class-validator';
|
|
import { Assignee } from '../../features/tasks/types/types';
|
|
// TODO タスク 2502: バリデータをクラスを使用した記述に統一するで修正する
|
|
/**
|
|
* Validations options
|
|
* @param [validationOptions]
|
|
* @returns
|
|
*/
|
|
export const IsAssignees = (validationOptions?: ValidationOptions) => {
|
|
return (object: any, propertyName: string) => {
|
|
registerDecorator({
|
|
name: 'IsAssignees',
|
|
target: object.constructor,
|
|
propertyName: propertyName,
|
|
options: validationOptions,
|
|
validator: {
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
validate: (values: Assignee[], args: ValidationArguments) => {
|
|
return values.every((value) => {
|
|
const { typistUserId, typistGroupId, typistName } = value;
|
|
if (typistUserId === undefined && typistGroupId === undefined) {
|
|
return false;
|
|
}
|
|
if (typistUserId !== undefined && typistGroupId !== undefined) {
|
|
return false;
|
|
}
|
|
if (!typistName) {
|
|
return false;
|
|
}
|
|
return true;
|
|
});
|
|
},
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
defaultMessage: (args?: ValidationArguments): string => {
|
|
return 'Request body is invalid format';
|
|
},
|
|
},
|
|
});
|
|
};
|
|
};
|