Merged PR 894: API修正(アカウント削除系)

## 概要
[Task4034: API修正(アカウント削除系)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/4034)

- アカウント削除時にJobNumberテーブルのレコードも削除するように修正
- パートナー削除時にJobNumberテーブルのレコードも削除するように修正
- テスト修正

## レビューポイント
- テストケースに不足はないか
- ジョブナンバーテーブルの削除順に問題はないか

## クエリの変更
- Repositoryを変更し、クエリが変更された場合は変更内容を確認する
- JobNumberテーブルのレコードを削除する処理を追加した
  - 既存のクエリに影響はなし

## 動作確認状況
- ローカルで確認
- 行った修正がデグレを発生させていないことを確認できるか
  - 既存のテストが通ることを確認
  - テストしていなかった観点(ソート条件も削除されているか等)も確認するように修正

## 補足
- 相談、参考資料などがあれば
This commit is contained in:
saito.k 2024-05-14 02:12:41 +00:00
parent 35e2d626a0
commit dfdc6a33ad
13 changed files with 346 additions and 56 deletions

View File

@ -40,6 +40,7 @@ import { TermsModule } from '../../features/terms/terms.module';
import { CacheModule } from '@nestjs/common';
import { RedisModule } from '../../gateways/redis/redis.module';
import { RedisService } from '../../gateways/redis/redis.service';
import { JobNumberRepositoryModule } from '../../repositories/job_number/job_number.repository.module';
export const makeTestingModule = async (
datasource: DataSource,
@ -79,6 +80,7 @@ export const makeTestingModule = async (
SortCriteriaRepositoryModule,
WorktypesRepositoryModule,
TermsRepositoryModule,
JobNumberRepositoryModule,
RedisModule,
CacheModule.register({ isGlobal: true, ttl: 86400 }),
],

View File

@ -11,6 +11,7 @@ import { License } from '../../repositories/licenses/entity/license.entity';
import { AccountArchive } from '../../repositories/accounts/entity/account_archive.entity';
import { Task } from '../../repositories/tasks/entity/task.entity';
import { JobNumber } from '../../repositories/job_number/entity/job_number.entity';
import { SortCriteria } from '../../repositories/sort_criteria/entity/sort_criteria.entity';
type InitialTestDBState = {
tier1Accounts: { account: Account; users: User[] }[];
@ -239,6 +240,11 @@ export const makeTestAccount = async (
if (!account || !admin) {
throw new Error('Unexpected null');
}
// sort_criteriaテーブルにデータを追加
await createSortCriteria(datasource, userId, 'JOB_NUMBER', 'ASC');
// job_numberテーブルにデータを追加
await createJobNumber(datasource, accountId, '00000000');
return {
account: account,
@ -325,6 +331,8 @@ export const makeTestUser = async (
if (!user) {
throw new Error('Unexpected null');
}
// sort_criteriaテーブルにデータを追加
await createSortCriteria(datasource, user.id, 'FILE_LENGTH', 'ASC');
return user;
};
@ -434,6 +442,33 @@ export const getTasks = async (
return tasks;
};
// job_numberテーブルにレコードを作成する
export const createJobNumber = async (
datasource: DataSource,
accountId: number,
jobNumber: string,
): Promise<void> => {
await datasource.getRepository(JobNumber).insert({
account_id: accountId,
job_number: jobNumber,
});
};
// job_numberテーブルのレコードを更新する
export const updateJobNumber = async (
datasource: DataSource,
accountId: number,
jobNumber: string,
): Promise<void> => {
await datasource.getRepository(JobNumber).update(
{ account_id: accountId },
{
job_number: jobNumber,
},
);
};
// job_numberを取得する
export const getJobNumber = async (
datasource: DataSource,
@ -446,3 +481,46 @@ export const getJobNumber = async (
});
return jobNumber;
};
// sort_criteriaを作成する
export const createSortCriteria = async (
datasource: DataSource,
userId: number,
parameter: string,
direction: string,
): Promise<void> => {
await datasource.getRepository(SortCriteria).insert({
user_id: userId,
parameter: parameter,
direction: direction,
});
};
// 指定したユーザーのsort_criteriaを更新する
export const updateSortCriteria = async (
datasource: DataSource,
userId: number,
parameter: string,
direction: string,
): Promise<void> => {
await datasource.getRepository(SortCriteria).update(
{ user_id: userId },
{
parameter: parameter,
direction: direction,
},
);
};
// 指定したユーザーのsort_criteriaを取得する
export const getSortCriteria = async (
datasource: DataSource,
userId: number,
): Promise<SortCriteria | null> => {
const sortCriteria = await datasource.getRepository(SortCriteria).findOne({
where: {
user_id: userId,
},
});
return sortCriteria;
};

View File

@ -21,7 +21,7 @@ import {
createWorktype,
getLicenseOrders,
getOptionItems,
getSortCriteria,
getSortCriteriaList,
getTypistGroup,
getTypistGroupMember,
getTypistGroupMembers,
@ -42,6 +42,8 @@ import {
getUserArchive,
getAccountArchive,
getTasks,
getSortCriteria,
getJobNumber,
} from '../../common/test/utility';
import { AccountsService } from './accounts.service';
import { Context, makeContext } from '../../common/log';
@ -92,10 +94,7 @@ import {
} from '../workflows/test/utility';
import { UsersService } from '../users/users.service';
import { truncateAllTable } from '../../common/test/init';
import {
createTask,
getCheckoutPermissions,
} from '../tasks/test/utility';
import { createTask, getCheckoutPermissions } from '../tasks/test/utility';
import { createCheckoutPermissions } from '../tasks/test/utility';
import { TestLogger } from '../../common/test/logger';
import { Account } from '../../repositories/accounts/entity/account.entity';
@ -418,7 +417,7 @@ describe('createAccount', () => {
expect(accounts.length).toBe(0);
const users = await getUsers(source);
expect(users.length).toBe(0);
const sortCriteria = await getSortCriteria(source);
const sortCriteria = await getSortCriteriaList(source);
expect(sortCriteria.length).toBe(0);
// ADB2Cユーザー削除メソッドが呼ばれているか確認
expect(b2cService.deleteUser).toBeCalledWith(
@ -486,7 +485,7 @@ describe('createAccount', () => {
expect(accounts.length).toBe(0);
const users = await getUsers(source);
expect(users.length).toBe(0);
const sortCriteria = await getSortCriteria(source);
const sortCriteria = await getSortCriteriaList(source);
expect(sortCriteria.length).toBe(0);
// ADB2Cユーザー削除メソッドが呼ばれているか確認
expect(b2cService.deleteUser).toBeCalledWith(
@ -557,7 +556,7 @@ describe('createAccount', () => {
expect(accounts.length).toBe(0);
const users = await getUsers(source);
expect(users.length).toBe(0);
const sortCriteria = await getSortCriteria(source);
const sortCriteria = await getSortCriteriaList(source);
expect(sortCriteria.length).toBe(0);
// ADB2Cユーザー削除メソッドが呼ばれているか確認
expect(b2cService.deleteUser).toBeCalledWith(
@ -630,7 +629,7 @@ describe('createAccount', () => {
expect(accounts.length).toBe(1);
const users = await getUsers(source);
expect(users.length).toBe(1);
const sortCriteria = await getSortCriteria(source);
const sortCriteria = await getSortCriteriaList(source);
expect(sortCriteria.length).toBe(1);
// ADB2Cユーザー削除メソッドが呼ばれているか確認
expect(b2cService.deleteUser).toBeCalledWith(
@ -715,7 +714,7 @@ describe('createAccount', () => {
expect(accounts.length).toBe(0);
const users = await getUsers(source);
expect(users.length).toBe(0);
const sortCriteria = await getSortCriteria(source);
const sortCriteria = await getSortCriteriaList(source);
expect(sortCriteria.length).toBe(0);
// ADB2Cユーザー削除メソッドが呼ばれているか確認
expect(b2cService.deleteUser).toBeCalledWith(
@ -803,7 +802,7 @@ describe('createAccount', () => {
expect(accounts.length).toBe(1);
const users = await getUsers(source);
expect(users.length).toBe(1);
const sortCriteria = await getSortCriteria(source);
const sortCriteria = await getSortCriteriaList(source);
expect(sortCriteria.length).toBe(1);
// ADB2Cユーザー削除メソッドが呼ばれているか確認
expect(b2cService.deleteUser).toBeCalledWith(
@ -7227,6 +7226,27 @@ describe('deleteAccountAndData', () => {
);
expect(LicenseAllocationHistoryRecordA.length).toBe(0);
// 第五階層のアカウントAの管理者ユーザーが持つsortCriteriaが削除されていること
const sortCriteriaAccuntAAdmin = await getSortCriteria(
source,
tier5AccountsA.admin.id,
);
expect(sortCriteriaAccuntAAdmin).toBe(null);
// 第五階層のアカウントAの一般ユーザーが持つsortCriteriaが削除されていること
const sortCriteriaAccuntAUser = await getSortCriteria(
source,
userA?.id ?? 0,
);
expect(sortCriteriaAccuntAUser).toBe(null);
// 第五階層のアカウントAのJobNumberが削除されていること
const jobNumberAccuntA = await getJobNumber(
source,
tier5AccountsA.account.id,
);
expect(jobNumberAccuntA).toBe(null);
// 第五階層のアカウントBは削除されていないこと
const accountRecordB = await getAccount(source, tier5AccountsB.account.id);
expect(accountRecordB?.id).not.toBeNull();
@ -7266,6 +7286,31 @@ describe('deleteAccountAndData', () => {
await getLicenseAllocationHistoryArchive(source);
expect(LicenseAllocationHistoryArchive.length).toBe(1);
// 第五階層のアカウントBの管理者ユーザーが持つsortCriteriaが削除されていないこと
const sortCriteriaAccuntBAdmin = await getSortCriteria(
source,
tier5AccountsB.admin.id,
);
expect(sortCriteriaAccuntBAdmin?.user_id).toBe(tier5AccountsB.admin.id);
expect(sortCriteriaAccuntBAdmin?.direction).toBe('ASC');
expect(sortCriteriaAccuntBAdmin?.parameter).toBe('JOB_NUMBER');
// 第五階層のアカウントBの一般ユーザーが持つsortCriteriaが削除されていないこと
const sortCriteriaAccuntBUser = await getSortCriteria(
source,
userB?.id ?? 0,
);
expect(sortCriteriaAccuntBUser?.user_id).toBe(userB?.id ?? 0);
expect(sortCriteriaAccuntBUser?.direction).toBe('ASC');
expect(sortCriteriaAccuntBUser?.parameter).toBe('FILE_LENGTH');
// 第五階層のアカウントBのJobNumberが削除されていないこと
const jobNumberAccuntB = await getJobNumber(
source,
tier5AccountsB.account.id,
);
expect(jobNumberAccuntB?.account_id).toBe(tier5AccountsB.account.id);
expect(jobNumberAccuntB?.job_number).toBe('00000000');
expect(_subject).toBe('Account Deleted Notification [U-111]');
expect(_url).toBe('http://localhost:8081/');
});
@ -8524,6 +8569,21 @@ describe('deletePartnerAccount', () => {
tier4Account.id,
);
expect(templateFileRecord.length).toBe(1);
const tier4AccountJobNumber = await getJobNumber(source, tier4Account.id);
expect(tier4AccountJobNumber?.job_number).toBe('00000000');
expect(tier4AccountJobNumber?.account_id).toBe(tier4Account.id);
const tier4AccountAdminSortCriteria = await getSortCriteria(
source,
tier4Admin?.id ?? 0,
);
expect(tier4AccountAdminSortCriteria?.direction).toBe('ASC');
expect(tier4AccountAdminSortCriteria?.parameter).toBe('JOB_NUMBER');
const tier4AccountTypistSortCriteria = await getSortCriteria(
source,
typist.id,
);
expect(tier4AccountTypistSortCriteria?.direction).toBe('ASC');
expect(tier4AccountTypistSortCriteria?.parameter).toBe('FILE_LENGTH');
}
// パートナーアカウント情報の削除
@ -8539,6 +8599,25 @@ describe('deletePartnerAccount', () => {
expect(account4Record).toBe(null);
const userRecordA = await getUser(source, tier4Admin?.id ?? 0);
expect(userRecordA).toBe(null);
// パートナーアカウントのユーザーが削除されていること
const userRecord = await getUsers(source);
expect(
userRecord.filter((x) => x.account_id === tier4Account.id).length,
).toBe(0);
// パートナーアカウントのJobNumberが削除されていること
const tier4AccountJobNumber = await getJobNumber(source, tier4Account.id);
expect(tier4AccountJobNumber).toBe(null);
// パートナーアカウントのソート条件が削除されていること
const tier4AccountAdminSortCriteria = await getSortCriteria(
source,
tier4Admin?.id ?? 0,
);
expect(tier4AccountAdminSortCriteria).toBe(null);
const tier4AccountTypistSortCriteria = await getSortCriteria(
source,
typist.id,
);
expect(tier4AccountTypistSortCriteria).toBe(null);
// パートナーアカウントのライセンスが削除されていること
const licenseRecord = await source.manager.find(License, {
@ -8716,6 +8795,21 @@ describe('deletePartnerAccount', () => {
tier4Account.id,
);
expect(templateFileRecord.length).toBe(1);
const tier4AccountJobNumber = await getJobNumber(source, tier4Account.id);
expect(tier4AccountJobNumber?.job_number).toBe('00000000');
expect(tier4AccountJobNumber?.account_id).toBe(tier4Account.id);
const tier4AccountAdminSortCriteria = await getSortCriteria(
source,
tier4Admin?.id ?? 0,
);
expect(tier4AccountAdminSortCriteria?.direction).toBe('ASC');
expect(tier4AccountAdminSortCriteria?.parameter).toBe('JOB_NUMBER');
const tier4AccountTypistSortCriteria = await getSortCriteria(
source,
typist.id,
);
expect(tier4AccountTypistSortCriteria?.direction).toBe('ASC');
expect(tier4AccountTypistSortCriteria?.parameter).toBe('FILE_LENGTH');
}
try {
@ -8865,6 +8959,21 @@ describe('deletePartnerAccount', () => {
tier4Account.id,
);
expect(templateFileRecord.length).toBe(1);
const tier4AccountJobNumber = await getJobNumber(source, tier4Account.id);
expect(tier4AccountJobNumber?.job_number).toBe('00000000');
expect(tier4AccountJobNumber?.account_id).toBe(tier4Account.id);
const tier4AccountAdminSortCriteria = await getSortCriteria(
source,
tier4Admin?.id ?? 0,
);
expect(tier4AccountAdminSortCriteria?.direction).toBe('ASC');
expect(tier4AccountAdminSortCriteria?.parameter).toBe('JOB_NUMBER');
const tier4AccountTypistSortCriteria = await getSortCriteria(
source,
typist.id,
);
expect(tier4AccountTypistSortCriteria?.direction).toBe('ASC');
expect(tier4AccountTypistSortCriteria?.parameter).toBe('FILE_LENGTH');
}
try {
@ -9028,6 +9137,21 @@ describe('deletePartnerAccount', () => {
tier4Account.id,
);
expect(templateFileRecord.length).toBe(1);
const tier4AccountJobNumber = await getJobNumber(source, tier4Account.id);
expect(tier4AccountJobNumber?.job_number).toBe('00000000');
expect(tier4AccountJobNumber?.account_id).toBe(tier4Account.id);
const tier4AccountAdminSortCriteria = await getSortCriteria(
source,
tier4Admin?.id ?? 0,
);
expect(tier4AccountAdminSortCriteria?.direction).toBe('ASC');
expect(tier4AccountAdminSortCriteria?.parameter).toBe('JOB_NUMBER');
const tier4AccountTypistSortCriteria = await getSortCriteria(
source,
typist.id,
);
expect(tier4AccountTypistSortCriteria?.direction).toBe('ASC');
expect(tier4AccountTypistSortCriteria?.parameter).toBe('FILE_LENGTH');
}
// パートナーアカウント情報の削除
@ -9047,6 +9171,25 @@ describe('deletePartnerAccount', () => {
expect(account4Record).toBe(null);
const userRecordA = await getUser(source, tier4Admin?.id ?? 0);
expect(userRecordA).toBe(null);
// パートナーアカウントのユーザーが削除されていること
const userRecord = await getUsers(source);
expect(
userRecord.filter((x) => x.account_id === tier4Account.id).length,
).toBe(0);
// パートナーアカウントのJobNumberが削除されていること
const tier4AccountJobNumber = await getJobNumber(source, tier4Account.id);
expect(tier4AccountJobNumber).toBe(null);
// パートナーアカウントのソート条件が削除されていること
const tier4AccountAdminSortCriteria = await getSortCriteria(
source,
tier4Admin?.id ?? 0,
);
expect(tier4AccountAdminSortCriteria).toBe(null);
const tier4AccountTypistSortCriteria = await getSortCriteria(
source,
typist.id,
);
expect(tier4AccountTypistSortCriteria).toBe(null);
// パートナーアカウントのライセンスが削除されていること
const licenseRecord = await source.manager.find(License, {
@ -9234,6 +9377,21 @@ describe('deletePartnerAccount', () => {
tier4Account.id,
);
expect(templateFileRecord.length).toBe(1);
const tier4AccountJobNumber = await getJobNumber(source, tier4Account.id);
expect(tier4AccountJobNumber?.job_number).toBe('00000000');
expect(tier4AccountJobNumber?.account_id).toBe(tier4Account.id);
const tier4AccountAdminSortCriteria = await getSortCriteria(
source,
tier4Admin?.id ?? 0,
);
expect(tier4AccountAdminSortCriteria?.direction).toBe('ASC');
expect(tier4AccountAdminSortCriteria?.parameter).toBe('JOB_NUMBER');
const tier4AccountTypistSortCriteria = await getSortCriteria(
source,
typist.id,
);
expect(tier4AccountTypistSortCriteria?.direction).toBe('ASC');
expect(tier4AccountTypistSortCriteria?.parameter).toBe('FILE_LENGTH');
}
// パートナーアカウント情報の削除
@ -9253,6 +9411,25 @@ describe('deletePartnerAccount', () => {
expect(account4Record).toBe(null);
const userRecordA = await getUser(source, tier4Admin?.id ?? 0);
expect(userRecordA).toBe(null);
// パートナーアカウントのユーザーが削除されていること
const userRecord = await getUsers(source);
expect(
userRecord.filter((x) => x.account_id === tier4Account.id).length,
).toBe(0);
// パートナーアカウントのJobNumberが削除されていること
const tier4AccountJobNumber = await getJobNumber(source, tier4Account.id);
expect(tier4AccountJobNumber).toBe(null);
// パートナーアカウントのソート条件が削除されていること
const tier4AccountAdminSortCriteria = await getSortCriteria(
source,
tier4Admin?.id ?? 0,
);
expect(tier4AccountAdminSortCriteria).toBe(null);
const tier4AccountTypistSortCriteria = await getSortCriteria(
source,
typist.id,
);
expect(tier4AccountTypistSortCriteria).toBe(null);
// パートナーアカウントのライセンスが削除されていること
const licenseRecord = await source.manager.find(License, {
@ -9426,6 +9603,21 @@ describe('deletePartnerAccount', () => {
tier4Account.id,
);
expect(templateFileRecord.length).toBe(1);
const tier4AccountJobNumber = await getJobNumber(source, tier4Account.id);
expect(tier4AccountJobNumber?.job_number).toBe('00000000');
expect(tier4AccountJobNumber?.account_id).toBe(tier4Account.id);
const tier4AccountAdminSortCriteria = await getSortCriteria(
source,
tier4Admin?.id ?? 0,
);
expect(tier4AccountAdminSortCriteria?.direction).toBe('ASC');
expect(tier4AccountAdminSortCriteria?.parameter).toBe('JOB_NUMBER');
const tier4AccountTypistSortCriteria = await getSortCriteria(
source,
typist.id,
);
expect(tier4AccountTypistSortCriteria?.direction).toBe('ASC');
expect(tier4AccountTypistSortCriteria?.parameter).toBe('FILE_LENGTH');
}
// パートナーアカウント情報の削除
@ -9441,6 +9633,25 @@ describe('deletePartnerAccount', () => {
expect(account4Record).toBe(null);
const userRecordA = await getUser(source, tier4Admin?.id ?? 0);
expect(userRecordA).toBe(null);
// パートナーアカウントのユーザーが削除されていること
const userRecord = await getUsers(source);
expect(
userRecord.filter((x) => x.account_id === tier4Account.id).length,
).toBe(0);
// パートナーアカウントのJobNumberが削除されていること
const tier4AccountJobNumber = await getJobNumber(source, tier4Account.id);
expect(tier4AccountJobNumber).toBe(null);
// パートナーアカウントのソート条件が削除されていること
const tier4AccountAdminSortCriteria = await getSortCriteria(
source,
tier4Admin?.id ?? 0,
);
expect(tier4AccountAdminSortCriteria).toBe(null);
const tier4AccountTypistSortCriteria = await getSortCriteria(
source,
typist.id,
);
expect(tier4AccountTypistSortCriteria).toBe(null);
// パートナーアカウントのライセンスが削除されていること
const licenseRecord = await source.manager.find(License, {

View File

@ -2359,7 +2359,7 @@ export class AccountsService {
country = targetAccount.country;
} catch (e) {
// アカウントの削除に失敗した場合はエラーを返す
this.logger.log(`[${context.getTrackingId()}] ${e}`);
this.logger.log(`[${context.getTrackingId()}] error=${e}`);
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.deleteAccountAndData.name}`,
);
@ -2382,7 +2382,7 @@ export class AccountsService {
);
} catch (e) {
// ADB2Cユーザーの削除失敗時は、MANUAL_RECOVERY_REQUIREDを出して処理続行
this.logger.log(`[${context.getTrackingId()}] ${e}`);
this.logger.log(`[${context.getTrackingId()}] error=${e}`);
this.logger.log(
`${MANUAL_RECOVERY_REQUIRED} [${context.getTrackingId()}] Failed to delete ADB2C users: ${accountId}, users_id: ${dbUsers.map(
(x) => x.external_id,
@ -2398,7 +2398,7 @@ export class AccountsService {
);
} catch (e) {
// blobstorageコンテナを削除で失敗した場合は、MANUAL_RECOVERY_REQUIRED出して正常終了
this.logger.log(`[${context.getTrackingId()}] ${e}`);
this.logger.log(`[${context.getTrackingId()}] error=${e}`);
this.logger.log(
`${MANUAL_RECOVERY_REQUIRED}[${context.getTrackingId()}] Failed to delete blob container: ${accountId}, country: ${country}`,
);

View File

@ -17,7 +17,7 @@ import { AudioFile } from '../../../repositories/audio_files/entity/audio_file.e
* @param dataSource
* @returns
*/
export const getSortCriteria = async (dataSource: DataSource) => {
export const getSortCriteriaList = async (dataSource: DataSource) => {
return await dataSource.getRepository(SortCriteria).find();
};

View File

@ -2,6 +2,7 @@ import { DataSource } from 'typeorm';
import { Term } from '../../../repositories/terms/entity/term.entity';
import { Account } from '../../../repositories/accounts/entity/account.entity';
import { User } from '../../../repositories/users/entity/user.entity';
import { JobNumber } from '../../../repositories/job_number/entity/job_number.entity';
export const createTermInfo = async (
datasource: DataSource,
@ -34,5 +35,6 @@ export const deleteAccount = async (
id: number,
): Promise<void> => {
await dataSource.getRepository(User).delete({ account_id: id });
await dataSource.getRepository(JobNumber).delete({ account_id: id });
await dataSource.getRepository(Account).delete({ id: id });
};

View File

@ -3,7 +3,6 @@ import { makeErrorResponse } from '../../common/error/makeErrorResponse';
import { makeBlobstorageServiceMockValue } from './test/files.service.mock';
import { DataSource } from 'typeorm';
import {
createJobNumber,
createLicense,
createTask,
createUserGroupAndMember,
@ -14,12 +13,14 @@ import {
import { FilesService } from './files.service';
import { makeContext } from '../../common/log';
import {
createJobNumber,
getJobNumber,
getTasks,
makeHierarchicalAccounts,
makeTestAccount,
makeTestSimpleAccount,
makeTestUser,
updateJobNumber,
} from '../../common/test/utility';
import { makeTestingModule } from '../../common/test/modules';
import {
@ -858,8 +859,8 @@ describe('タスク作成から自動ルーティング(DB使用)', () => {
);
}
// 最新のジョブナンバーでjob_numberテーブルを作成
await createJobNumber(source, accountId, '00000003');
// 最新のジョブナンバーでjob_numberテーブルを更新
await updateJobNumber(source, accountId, '00000003');
const service = module.get<FilesService>(FilesService);
const spy = jest
@ -944,8 +945,8 @@ describe('タスク作成から自動ルーティング(DB使用)', () => {
);
}
// 最新のジョブナンバーでjob_numberテーブルを作成
await createJobNumber(source, accountId, '00000003');
// 最新のジョブナンバーでjob_numberテーブルを更新
await updateJobNumber(source, accountId, '00000003');
const service = module.get<FilesService>(FilesService);
// メール送信関数が呼ばれたかどうかで判定を行う。実際のメール送信は行わない。
@ -1033,8 +1034,8 @@ describe('タスク作成から自動ルーティング(DB使用)', () => {
);
}
// 最新のジョブナンバーでjob_numberテーブルを作成
await createJobNumber(source, accountId, '00000004');
// 最新のジョブナンバーでjob_numberテーブルを更新
await updateJobNumber(source, accountId, '00000004');
const service = module.get<FilesService>(FilesService);
// メール送信関数が呼ばれたかどうかで判定を行う。実際のメール送信は行わない。
@ -1127,8 +1128,8 @@ describe('タスク作成から自動ルーティング(DB使用)', () => {
);
}
// 最新のジョブナンバーでjob_numberテーブルを作成
await createJobNumber(source, accountId, '00000004');
// 最新のジョブナンバーでjob_numberテーブルを更新
await updateJobNumber(source, accountId, '00000004');
const service = module.get<FilesService>(FilesService);
// メール送信関数が呼ばれたかどうかで判定を行う。実際のメール送信は行わない。
@ -2335,8 +2336,6 @@ describe('タスク作成から自動ルーティング(DB使用)', () => {
expect(jobNumber?.job_number).toEqual('99999999');
}
const module = await makeTestingModuleWithBlobAndNotification(
source,
blobParam,

View File

@ -110,18 +110,6 @@ export const createTask = async (
return { audioFileId: audioFile.id, taskId: task.id };
};
// job_numberテーブルにレコードを作成する
export const createJobNumber = async (
datasource: DataSource,
accountId: number,
jobNumber: string,
): Promise<void> => {
await datasource.getRepository(JobNumber).insert({
account_id: accountId,
job_number: jobNumber,
});
};
export const getTaskFromJobNumber = async (
datasource: DataSource,
jobNumber: string,

View File

@ -24,9 +24,11 @@ import {
import { Adb2cTooManyRequestsError } from '../../gateways/adb2c/adb2c.service';
import { makeContext } from '../../common/log';
import {
createSortCriteria,
makeTestAccount,
makeTestSimpleAccount,
makeTestUser,
updateSortCriteria,
} from '../../common/test/utility';
import {
ADMIN_ROLES,
@ -36,7 +38,6 @@ import {
USER_ROLES,
} from '../../constants';
import { makeTestingModule } from '../../common/test/modules';
import { createSortCriteria } from '../users/test/utility';
import { createWorktype } from '../accounts/test/utility';
import {
createWorkflow,
@ -3863,7 +3864,7 @@ describe('getNextTask', () => {
role: USER_ROLES.TYPIST,
});
await createSortCriteria(source, typistUserId, 'JOB_NUMBER', 'ASC');
await updateSortCriteria(source, typistUserId, 'JOB_NUMBER', 'ASC');
const { taskId: taskId1 } = await createTask(
source,
@ -4007,7 +4008,7 @@ describe('getNextTask', () => {
role: USER_ROLES.TYPIST,
});
await createSortCriteria(source, typistUserId, 'JOB_NUMBER', 'ASC');
await updateSortCriteria(source, typistUserId, 'JOB_NUMBER', 'ASC');
const { taskId: taskId1, audioFileId: audioFileId1 } = await createTask(
source,

View File

@ -263,7 +263,6 @@ export const getTask = async (
return task;
};
export const getCheckoutPermissions = async (
datasource: DataSource,
task_id: number,

View File

@ -6,7 +6,11 @@ import {
getTemplateFiles,
updateTaskTemplateFile,
} from './test/utility';
import { getTasks, makeTestAccount, makeTestUser } from '../../common/test/utility';
import {
getTasks,
makeTestAccount,
makeTestUser,
} from '../../common/test/utility';
import { makeContext } from '../../common/log';
import { TemplateFilesRepositoryService } from '../../repositories/template_files/template_files.repository.service';
import { HttpException, HttpStatus } from '@nestjs/common';

View File

@ -165,16 +165,3 @@ export const makeTestingModuleWithAdb2c = async (
console.log(e);
}
};
export const createSortCriteria = async (
datasource: DataSource,
userId: number,
parameter: string,
direction: string,
): Promise<void> => {
await datasource.getRepository(SortCriteria).insert({
user_id: userId,
parameter: parameter,
direction: direction,
});
};

View File

@ -67,6 +67,7 @@ import {
PartnerLicenseInfoForRepository,
} from '../../features/accounts/types/types';
import { AccountArchive } from './entity/account_archive.entity';
import { JobNumber } from '../job_number/entity/job_number.entity';
@Injectable()
export class AccountsRepositoryService {
@ -1245,6 +1246,15 @@ export class AccountsRepositoryService {
context,
);
// jobNumberのテーブルのレコードを削除する
const jobNumberRepo = entityManager.getRepository(JobNumber);
await deleteEntity(
jobNumberRepo,
{ account_id: accountId },
this.isCommentOut,
context,
);
// アカウントを削除
await deleteEntity(
accountRepo,
@ -1624,6 +1634,15 @@ export class AccountsRepositoryService {
context,
);
// JobNumberのテーブルのレコードを削除する
const jobNumberRepo = entityManager.getRepository(JobNumber);
await deleteEntity(
jobNumberRepo,
{ account_id: targetAccountId },
this.isCommentOut,
context,
);
// アカウントを削除
await deleteEntity(
accountRepo,