Merged PR 500: ActiveWorktypeIDの削除処理を追加
## 概要 [Task2861: ActiveWorktypeIDの削除処理を追加](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2861) - 削除で指定したワークタイプIDをActiveWorktypeIDに指定していた場合にNULLをセットする処理を追加しました。 ## レビューポイント - ActiveWorktypeID設定内容は適切か - テストケース追加に不足はないか ## UIの変更 - なし ## 動作確認状況 - ローカルで確認
This commit is contained in:
parent
7196491cf0
commit
a6206a624a
@ -3920,7 +3920,7 @@ describe('deleteWorktype', () => {
|
||||
source = null;
|
||||
});
|
||||
|
||||
it('WorktypeIDを削除できる', async () => {
|
||||
it('WorktypeIDを削除できること', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
// 第五階層のアカウント作成
|
||||
const { account, admin } = await makeTestAccount(source, { tier: 5 });
|
||||
@ -3966,6 +3966,51 @@ describe('deleteWorktype', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('指定されたWorktypeIDがアカウントのActiveWorktypeIDの場合、削除できること', 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 { id: worktypeId1 } = await createWorktype(
|
||||
source,
|
||||
account.id,
|
||||
'worktype1',
|
||||
'description1',
|
||||
true,
|
||||
);
|
||||
await createOptionItems(source, worktypeId1);
|
||||
|
||||
// 作成したデータを確認
|
||||
{
|
||||
const worktypes = await getWorktypes(source, account.id);
|
||||
const optionItems = await getOptionItems(source);
|
||||
const accounts = await getAccounts(source);
|
||||
|
||||
expect(worktypes.length).toBe(1);
|
||||
expect(worktypes[0].id).toBe(worktypeId1);
|
||||
expect(worktypes[0].custom_worktype_id).toBe('worktype1');
|
||||
expect(optionItems.length).toBe(10);
|
||||
expect(accounts.length).toBe(1);
|
||||
expect(accounts[0].active_worktype_id).toBe(worktypeId1);
|
||||
}
|
||||
|
||||
await service.deleteWorktype(context, admin.external_id, worktypeId1);
|
||||
|
||||
//実行結果を確認
|
||||
{
|
||||
const worktypes = await getWorktypes(source, account.id);
|
||||
const optionItems = await getOptionItems(source);
|
||||
const accounts = await getAccounts(source);
|
||||
expect(worktypes.length).toBe(0);
|
||||
expect(optionItems.length).toBe(0);
|
||||
expect(accounts.length).toBe(1);
|
||||
expect(accounts[0].active_worktype_id).toBe(null);
|
||||
}
|
||||
});
|
||||
|
||||
it('指定したWorktypeIDが登録されていない場合、400エラーとなること', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
// 第五階層のアカウント作成
|
||||
|
||||
@ -176,6 +176,19 @@ export class WorktypesRepositoryService {
|
||||
throw new WorktypeIdNotFoundError(`Worktype is not found. id: ${id}`);
|
||||
}
|
||||
|
||||
// アカウントのActiveWorktypeIDが削除対象のワークタイプIDの場合はActiveWorktypeIDをnullに更新
|
||||
const accountRepo = entityManager.getRepository(Account);
|
||||
const account = await accountRepo.findOne({
|
||||
where: { id: accountId },
|
||||
});
|
||||
|
||||
if (account?.active_worktype_id === id) {
|
||||
await accountRepo.update(
|
||||
{ id: accountId },
|
||||
{ active_worktype_id: null },
|
||||
);
|
||||
}
|
||||
|
||||
// ワークタイプがワークフローに紐づいている場合はエラー
|
||||
const workflowRepo = entityManager.getRepository(Workflow);
|
||||
const workflows = await workflowRepo.find({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user