Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/application/exceptions/ApplicationExceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ export class MemberNotFoundFromDiscordAccountIdException extends ApplicationExce
}
}

export class KarteNotFoundException extends ApplicationException {
constructor(karteId: string) {
const message = `カルテが見つかりません: ${karteId}`;
super(message);
this.name = "KarteNotFoundException";
}
}

export class DiscordAccountNotConnectedException extends ApplicationException {
constructor(userId: string, discordUserId: string) {
const message = `ユーザー: ${userId} のDiscordアカウントは紐づいていません: ${discordUserId}`;
Expand Down
1 change: 1 addition & 0 deletions src/application/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./usecase/member";
export * from "./usecase/event";
export * from "./usecase/eventParticipation";
export * from "./usecase/karte";
export * from "./exceptions";
59 changes: 59 additions & 0 deletions src/application/usecase/karte/CorrectKarte.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { KarteNotFoundException } from "#application/exceptions";
import { IUseCase } from "#application/usecase/base";
import type { Client } from "#domain/aggregates/karte/Client";
import type { Consent } from "#domain/aggregates/karte/Consent";
import type { ConsultationCategory } from "#domain/aggregates/karte/ConsultationCategory";
import type { FollowUp } from "#domain/aggregates/karte/FollowUp";
import type { Karte } from "#domain/aggregates/karte/Karte";
import type { KarteId } from "#domain/aggregates/karte/KarteId";
import type { KarteRepository } from "#domain/aggregates/karte/KarteRepository";
import type { WorkDuration } from "#domain/aggregates/karte/WorkDuration";
import type { MemberId } from "#domain/aggregates/member/MemberId";
import type { NonEmptyArray } from "#domain/base/NonEmptyArray";

/** 訂正時の解決ステータス */
type CorrectResolution =
| { readonly type: "resolved" }
| { readonly type: "unresolved"; readonly followUp: FollowUp };

export type CorrectKarteInput = {
readonly karteId: KarteId;
readonly consultedAt: Date;
readonly client: Client;
readonly consent: Consent;
readonly consultation: {
readonly categories: NonEmptyArray<ConsultationCategory>;
readonly targetDevice: string;
readonly troubleDetails: string;
};
readonly supportRecord: {
readonly assignedMemberIds: NonEmptyArray<MemberId>;
readonly content: string;
readonly resolution: CorrectResolution;
readonly workDuration: WorkDuration;
};
};

export type CorrectKarteOutput = {
readonly karte: Karte;
};

export class CorrectKarteUseCase extends IUseCase<
CorrectKarteInput,
CorrectKarteOutput
> {
constructor(private readonly karteRepository: KarteRepository) {
super();
}

async execute(input: CorrectKarteInput): Promise<CorrectKarteOutput> {
const existing = await this.karteRepository.findById(input.karteId);
if (!existing) {
throw new KarteNotFoundException(input.karteId);
}

const corrected = existing.correct(input);
await this.karteRepository.save(corrected);
return { karte: corrected };
}
}
53 changes: 53 additions & 0 deletions src/application/usecase/karte/CreateKarte.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { IUseCase } from "#application/usecase/base";
import type { Client } from "#domain/aggregates/karte/Client";
import type { Consent } from "#domain/aggregates/karte/Consent";
import type { ConsultationCategory } from "#domain/aggregates/karte/ConsultationCategory";
import type { FollowUp } from "#domain/aggregates/karte/FollowUp";
import { Karte } from "#domain/aggregates/karte/Karte";
import type { KarteId } from "#domain/aggregates/karte/KarteId";
import type { KarteRepository } from "#domain/aggregates/karte/KarteRepository";
import type { WorkDuration } from "#domain/aggregates/karte/WorkDuration";
import type { MemberId } from "#domain/aggregates/member/MemberId";
import type { NonEmptyArray } from "#domain/base/NonEmptyArray";

/** 新規カルテ作成時の解決ステータス */
type CreateResolution =
| { readonly type: "resolved" }
| { readonly type: "unresolved"; readonly followUp: FollowUp };

export type CreateKarteInput = {
readonly id: KarteId;
readonly consultedAt: Date;
readonly client: Client;
readonly consent: Consent;
readonly consultation: {
readonly categories: NonEmptyArray<ConsultationCategory>;
readonly targetDevice: string;
readonly troubleDetails: string;
};
readonly supportRecord: {
readonly assignedMemberIds: NonEmptyArray<MemberId>;
readonly content: string;
readonly resolution: CreateResolution;
readonly workDuration: WorkDuration;
};
};

export type CreateKarteOutput = {
readonly karte: Karte;
};

export class CreateKarteUseCase extends IUseCase<
CreateKarteInput,
CreateKarteOutput
> {
constructor(private readonly karteRepository: KarteRepository) {
super();
}

async execute(input: CreateKarteInput): Promise<CreateKarteOutput> {
const karte = Karte.create(input);
await this.karteRepository.save(karte);
return { karte };
}
}
27 changes: 27 additions & 0 deletions src/application/usecase/karte/GetKarte.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { KarteNotFoundException } from "#application/exceptions";
import { IUseCase } from "#application/usecase/base";
import type { Karte } from "#domain/aggregates/karte/Karte";
import type { KarteId } from "#domain/aggregates/karte/KarteId";
import type { KarteRepository } from "#domain/aggregates/karte/KarteRepository";

export type GetKarteInput = {
readonly karteId: KarteId;
};

export type GetKarteOutput = {
readonly karte: Karte;
};

export class GetKarteUseCase extends IUseCase<GetKarteInput, GetKarteOutput> {
constructor(private readonly karteRepository: KarteRepository) {
super();
}

async execute(input: GetKarteInput): Promise<GetKarteOutput> {
const karte = await this.karteRepository.findById(input.karteId);
if (!karte) {
throw new KarteNotFoundException(input.karteId);
}
return { karte };
}
}
6 changes: 6 additions & 0 deletions src/application/usecase/karte/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { CreateKarteUseCase } from "./CreateKarte";
export type { CreateKarteInput, CreateKarteOutput } from "./CreateKarte";
export { CorrectKarteUseCase } from "./CorrectKarte";
export type { CorrectKarteInput, CorrectKarteOutput } from "./CorrectKarte";
export { GetKarteUseCase } from "./GetKarte";
export type { GetKarteInput, GetKarteOutput } from "./GetKarte";