makabe.t d48afdbffd Merged PR 468: API実装(ワークフロー削除API)
## 概要
[Task2785: API実装(ワークフロー削除API)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2785)

- ワークフロー削除APIとテストを実装しました。

## レビューポイント
- リポジトリの削除ロジックは適切か
- テストケースは適切か

## UIの変更
- なし

## 動作確認状況
- ローカルで確認
2023-10-11 09:14:41 +00:00

102 lines
2.7 KiB
TypeScript

import { DataSource } from 'typeorm';
import { Workflow } from '../../../repositories/workflows/entity/workflow.entity';
import { WorkflowTypist } from '../../../repositories/workflows/entity/workflow_typists.entity';
// Workflowを作成する
export const createWorkflow = async (
datasource: DataSource,
accountId: number,
authorId: number,
worktypeId?: number | undefined,
templateId?: number | undefined,
): Promise<Workflow> => {
const { identifiers } = await datasource.getRepository(Workflow).insert({
account_id: accountId,
author_id: authorId,
worktype_id: worktypeId ?? undefined,
template_id: templateId ?? undefined,
created_by: 'test_runner',
created_at: new Date(),
updated_by: 'updater',
updated_at: new Date(),
});
const workflow = identifiers.pop() as Workflow;
return workflow;
};
// Workflow一覧を取得する
export const getWorkflows = async (
datasource: DataSource,
accountId: number,
): Promise<Workflow[]> => {
return await datasource.getRepository(Workflow).find({
where: {
account_id: accountId,
},
});
};
// Workflow一覧全体を取得する
export const getAllWorkflows = async (
datasource: DataSource,
): Promise<Workflow[]> => {
return await datasource.getRepository(Workflow).find();
};
// Workflowを取得する
export const getWorkflow = async (
datasource: DataSource,
accountId: number,
id: number,
): Promise<Workflow> => {
return await datasource.getRepository(Workflow).findOne({
where: {
account_id: accountId,
id: id,
},
});
};
// Workflowを作成する
export const createWorkflowTypist = async (
datasource: DataSource,
workflowId: number,
typistUserId?: number | undefined,
typistGroupId?: number | undefined,
): Promise<Workflow> => {
const { identifiers } = await datasource
.getRepository(WorkflowTypist)
.insert({
workflow_id: workflowId,
typist_id: typistUserId ?? undefined,
typist_group_id: typistGroupId ?? undefined,
created_by: 'test_runner',
created_at: new Date(),
updated_by: 'updater',
updated_at: new Date(),
});
const workflow = identifiers.pop() as Workflow;
return workflow;
};
// WorkflowTypist一覧を取得する
export const getWorkflowTypists = async (
datasource: DataSource,
workflowId: number,
): Promise<WorkflowTypist[]> => {
return await datasource.getRepository(WorkflowTypist).find({
where: {
workflow_id: workflowId,
},
});
};
// WorkflowTypist一覧全件を取得する
export const getAllWorkflowTypists = async (
datasource: DataSource,
): Promise<WorkflowTypist[]> => {
return await datasource.getRepository(WorkflowTypist).find();
};