Merged PR 417: ActiveWorktypeIDを未設定に戻せるように修正

## 概要
[Task2677: ActiveWorktypeIDを未設定に戻せるように修正](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2677)

- ActiveWorktypeIDを設定後、未選択に戻す操作ができるように修正

## レビューポイント
- 修正箇所の共有

## UIの変更
- なし

## 動作確認状況
- ローカルで確認
This commit is contained in:
makabe.t 2023-09-19 02:56:19 +00:00
parent b5ecd6de15
commit d1a8b887e5
3 changed files with 50 additions and 11 deletions

View File

@ -140,7 +140,7 @@ const WorktypeIdSettingPage: React.FC = (): JSX.Element => {
<select
name="Active Worktype"
className={styles.formInput}
value={activeWorktypeId}
value={activeWorktypeId ?? ""}
onChange={onChangeActiveWorktype}
>
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}

View File

@ -4402,6 +4402,37 @@ describe('updateActiveWorktype', () => {
}
});
it('アカウントのActiveWorktypeIDをNULLに更新できるWorkTypeID⇒NULL', async () => {
const module = await makeTestingModule(source);
// 第五階層のアカウント作成
const { account, admin } = await makeTestAccount(source, { tier: 5 });
const service = module.get<AccountsService>(AccountsService);
const context = makeContext(admin.external_id);
const worktype1 = await createWorktype(
source,
account.id,
'worktype1',
'description1',
true,
);
//作成したデータを確認
{
const beforeAccount = await getAccount(source, account.id);
expect(beforeAccount.active_worktype_id).toBe(worktype1.id);
}
await service.updateActiveWorktype(context, admin.external_id, undefined);
//実行結果を確認
{
const { active_worktype_id } = await getAccount(source, account.id);
expect(active_worktype_id).toBe(null);
}
});
it('自アカウント内に指定されたIDのWorktypeIDが存在しない場合、400エラーとなることWorkTypeIDが存在しない場合', async () => {
const module = await makeTestingModule(source);
// 第五階層のアカウント作成

View File

@ -771,14 +771,18 @@ export class AccountsRepositoryService {
/**
* ActiveWorktypeIdを更新する
* @param accountId
* @param id ActiveWorktypeIdの内部ID
* @param [id] ActiveWorktypeIdの内部ID
* @returns active worktype id
*/
async updateActiveWorktypeId(accountId: number, id: number): Promise<void> {
async updateActiveWorktypeId(
accountId: number,
id?: number | undefined,
): Promise<void> {
return await this.dataSource.transaction(async (entityManager) => {
const worktypeRepo = entityManager.getRepository(Worktype);
const accountRepo = entityManager.getRepository(Account);
if (id) {
// 自アカウント内に指定IDのワークタイプが存在するか確認
const worktype = await worktypeRepo.findOne({
where: { account_id: accountId, id: id },
@ -788,9 +792,13 @@ export class AccountsRepositoryService {
if (!worktype) {
throw new WorktypeIdNotFoundError('Worktype is not found. id: ${id}');
}
}
// アカウントのActiveWorktypeIDを更新
await accountRepo.update({ id: accountId }, { active_worktype_id: id });
await accountRepo.update(
{ id: accountId },
{ active_worktype_id: id ?? null },
);
});
}
}