## 概要 [Task2592: API実装(オプションアイテム取得)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2592) - オプションアイテム取得APIとテストを実装しました。 ## レビューポイント - リポジトリの取得ロジックは想定通りか - テストケースは適切か ## UIの変更 - なし ## 動作確認状況 - ローカルで確認
199 lines
5.4 KiB
TypeScript
199 lines
5.4 KiB
TypeScript
import { DataSource } from 'typeorm';
|
|
import {
|
|
License,
|
|
LicenseOrder,
|
|
} from '../../../repositories/licenses/entity/license.entity';
|
|
import { SortCriteria } from '../../../repositories/sort_criteria/entity/sort_criteria.entity';
|
|
import { UserGroup } from '../../../repositories/user_groups/entity/user_group.entity';
|
|
import { UserGroupMember } from '../../../repositories/user_groups/entity/user_group_member.entity';
|
|
import { Worktype } from '../../../repositories/worktypes/entity/worktype.entity';
|
|
import { OptionItem } from '../../../repositories/worktypes/entity/option_item.entity';
|
|
import { OPTION_ITEM_VALUE_TYPE } from '../../../constants';
|
|
|
|
/**
|
|
* テスト ユーティリティ: すべてのソート条件を取得する
|
|
* @param dataSource データソース
|
|
* @returns 該当ソート条件一覧
|
|
*/
|
|
export const getSortCriteria = async (dataSource: DataSource) => {
|
|
return await dataSource.getRepository(SortCriteria).find();
|
|
};
|
|
|
|
export const createLicense = async (
|
|
datasource: DataSource,
|
|
licenseId: number,
|
|
expiry_date: Date,
|
|
accountId: number,
|
|
type: string,
|
|
status: string,
|
|
allocated_user_id: number,
|
|
order_id: number,
|
|
deleted_at: Date,
|
|
delete_order_id: number,
|
|
): Promise<void> => {
|
|
const { identifiers } = await datasource.getRepository(License).insert({
|
|
id: licenseId,
|
|
expiry_date: expiry_date,
|
|
account_id: accountId,
|
|
type: type,
|
|
status: status,
|
|
allocated_user_id: allocated_user_id,
|
|
order_id: order_id,
|
|
deleted_at: deleted_at,
|
|
delete_order_id: delete_order_id,
|
|
created_by: 'test_runner',
|
|
created_at: new Date(),
|
|
updated_by: 'updater',
|
|
updated_at: new Date(),
|
|
});
|
|
identifiers.pop() as License;
|
|
};
|
|
|
|
// 有効期限・ステータス付きのライセンスを作成
|
|
export const createLicenseSetExpiryDateAndStatus = async (
|
|
datasource: DataSource,
|
|
accountId: number,
|
|
expiryDate: Date,
|
|
status: string,
|
|
): Promise<void> => {
|
|
const { identifiers } = await datasource.getRepository(License).insert({
|
|
expiry_date: expiryDate,
|
|
account_id: accountId,
|
|
type: 'NORMAL',
|
|
status: status,
|
|
allocated_user_id: null,
|
|
order_id: null,
|
|
deleted_at: null,
|
|
delete_order_id: null,
|
|
created_by: 'test_runner',
|
|
created_at: new Date(),
|
|
updated_by: 'updater',
|
|
updated_at: new Date(),
|
|
});
|
|
identifiers.pop() as License;
|
|
};
|
|
|
|
export const createLicenseOrder = async (
|
|
datasource: DataSource,
|
|
fromAccountId: number,
|
|
toAccountId: number,
|
|
quantity: number,
|
|
po_number = 'TEST123',
|
|
ordered_at = new Date(),
|
|
): Promise<void> => {
|
|
const { identifiers } = await datasource.getRepository(LicenseOrder).insert({
|
|
po_number: po_number,
|
|
from_account_id: fromAccountId,
|
|
to_account_id: toAccountId,
|
|
ordered_at: ordered_at,
|
|
issued_at: null,
|
|
quantity: quantity,
|
|
status: 'Issue Requesting',
|
|
canceled_at: null,
|
|
created_by: 'test_runner',
|
|
created_at: new Date(),
|
|
updated_by: 'updater',
|
|
updated_at: new Date(),
|
|
});
|
|
identifiers.pop() as License;
|
|
};
|
|
|
|
// タイピストグループを取得する
|
|
export const getTypistGroup = async (
|
|
datasource: DataSource,
|
|
accountId: number,
|
|
): Promise<UserGroup[]> => {
|
|
return await datasource.getRepository(UserGroup).find({
|
|
where: {
|
|
account_id: accountId,
|
|
},
|
|
});
|
|
};
|
|
// タイピストグループメンバーを取得する
|
|
export const getTypistGroupMember = async (
|
|
datasource: DataSource,
|
|
userGroupId: number,
|
|
): Promise<UserGroupMember[]> => {
|
|
return await datasource.getRepository(UserGroupMember).find({
|
|
where: {
|
|
user_group_id: userGroupId,
|
|
},
|
|
});
|
|
};
|
|
|
|
// Worktypeを作成する
|
|
export const createWorktype = async (
|
|
datasource: DataSource,
|
|
accountId: number,
|
|
worktypeId: string,
|
|
description?: string,
|
|
): Promise<Worktype> => {
|
|
const { identifiers } = await datasource.getRepository(Worktype).insert({
|
|
account_id: accountId,
|
|
custom_worktype_id: worktypeId,
|
|
description: description ?? null,
|
|
deleted_at: null,
|
|
created_by: 'test_runner',
|
|
created_at: new Date(),
|
|
updated_by: 'updater',
|
|
updated_at: new Date(),
|
|
});
|
|
const worktype = identifiers.pop() as Worktype;
|
|
return worktype;
|
|
};
|
|
|
|
// Worktypeを取得する
|
|
export const getWorktypes = async (
|
|
datasource: DataSource,
|
|
accountId: number,
|
|
): Promise<Worktype[]> => {
|
|
return await datasource.getRepository(Worktype).find({
|
|
where: {
|
|
account_id: accountId,
|
|
},
|
|
});
|
|
};
|
|
|
|
// オプションアイテムを作成する
|
|
export const createOptionItems = async (
|
|
datasource: DataSource,
|
|
worktypeId: number,
|
|
): Promise<OptionItem[]> => {
|
|
const optionItems = [];
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
optionItems.push({
|
|
worktype_id: worktypeId,
|
|
item_label: '',
|
|
default_value_type: OPTION_ITEM_VALUE_TYPE.DEFAULT,
|
|
initial_value: '',
|
|
created_by: 'test_runner',
|
|
created_at: new Date(),
|
|
updated_by: 'updater',
|
|
updated_at: new Date(),
|
|
});
|
|
}
|
|
|
|
await datasource.getRepository(OptionItem).insert(optionItems);
|
|
|
|
const items = datasource
|
|
.getRepository(OptionItem)
|
|
.find({ where: { worktype_id: worktypeId } });
|
|
|
|
return items;
|
|
};
|
|
|
|
// オプションアイテムを取得する
|
|
export const getOptionItems = async (
|
|
datasource: DataSource,
|
|
worktypeId?: number,
|
|
): Promise<OptionItem[]> => {
|
|
return worktypeId
|
|
? await datasource.getRepository(OptionItem).find({
|
|
where: {
|
|
worktype_id: worktypeId,
|
|
},
|
|
})
|
|
: await datasource.getRepository(OptionItem).find();
|
|
};
|