## 概要 [Task2498: API実装(ライセンス発行キャンセルAPI)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2498) - 元PBI or タスクへのリンク(内容・目的などはそちらにあるはず) - 何をどう変更したか、追加したライブラリなど ライセンス発行をキャンセルするAPIを実装 下位のアカウント情報と、上位のアカウント情報をセットすると、パートナー関係であるかを返す関数を追加 既存のユニットテストのライセンス作成箇所で、注文ID、削除日時、削除注文IDを指定できるように修正 - このPull Requestでの対象/対象外 - 影響範囲(他の機能にも影響があるか) 既存ユニットテストのライセンス作成部分 ## レビューポイント - 特にレビューしてほしい箇所 パートナー関係かどうかを返す箇所、共通的に使いやすいかどうか 14日より経過していた場合の箇所、ライセンスの有効期限の定数を使っているが分けたほうが良いか ## UIの変更 - Before/Afterのスクショなど - スクショ置き場 ## 動作確認状況 - ローカルで確認 ■正常系 ライセンス発行のキャンセルが完了できる(第一階層で実行) ライセンス発行のキャンセルが完了できる(第二階層で実行) キャンセルした発行の注文状態が発行待ちに戻る 発行されたライセンスは物理削除される 論理削除されていたライセンスは未割当で、削除前の状態に戻る ■異常系 第一、第二階層以外で実行した場合はエラー キャンセル対象の発行が存在しない場合エラー キャンセル対象の発行が14日より経過していた場合はエラー キャンセル対象の発行のライセンスが使われていた場合はエラー 自身のパートナー以外の発行をキャンセルしようとした場合、エラー ## 補足 - 相談、参考資料などがあれば
169 lines
4.7 KiB
TypeScript
169 lines
4.7 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/option_items/entity/option_item.entity';
|
|
|
|
/**
|
|
* テスト ユーティリティ: すべてのソート条件を取得する
|
|
* @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 getOptionItems = async (
|
|
datasource: DataSource,
|
|
worktypeId?: number,
|
|
): Promise<OptionItem[]> => {
|
|
return worktypeId
|
|
? await datasource.getRepository(OptionItem).find({
|
|
where: {
|
|
worktype_id: worktypeId,
|
|
},
|
|
})
|
|
: await datasource.getRepository(OptionItem).find();
|
|
};
|