website refactor
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { DomainError } from '@/lib/contracts/services/Service';
|
||||
|
||||
/**
|
||||
* Sponsor Service - DTO Only
|
||||
*
|
||||
@@ -7,7 +10,102 @@
|
||||
export class SponsorService {
|
||||
constructor(private readonly apiClient: any) {}
|
||||
|
||||
async getSponsorById(sponsorId: string): Promise<any> {
|
||||
return { id: sponsorId, name: 'Sponsor' };
|
||||
async getSponsorById(sponsorId: string): Promise<Result<any, DomainError>> {
|
||||
try {
|
||||
const result = await this.apiClient.getSponsor(sponsorId);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'notImplemented', message: 'getSponsorById' });
|
||||
}
|
||||
}
|
||||
|
||||
async getSponsorDashboard(sponsorId: string): Promise<Result<any, DomainError>> {
|
||||
try {
|
||||
const result = await this.apiClient.getDashboard(sponsorId);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'notImplemented', message: 'getSponsorDashboard' });
|
||||
}
|
||||
}
|
||||
|
||||
async getSponsorSponsorships(sponsorId: string): Promise<Result<any, DomainError>> {
|
||||
try {
|
||||
const result = await this.apiClient.getSponsorships(sponsorId);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'notImplemented', message: 'getSponsorSponsorships' });
|
||||
}
|
||||
}
|
||||
|
||||
async getBilling(sponsorId: string): Promise<Result<any, DomainError>> {
|
||||
try {
|
||||
const result = await this.apiClient.getBilling(sponsorId);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'notImplemented', message: 'getBilling' });
|
||||
}
|
||||
}
|
||||
|
||||
async getAvailableLeagues(): Promise<Result<any, DomainError>> {
|
||||
try {
|
||||
const result = await this.apiClient.getAvailableLeagues();
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'notImplemented', message: 'getAvailableLeagues' });
|
||||
}
|
||||
}
|
||||
|
||||
async getLeagueDetail(leagueId: string): Promise<Result<any, DomainError>> {
|
||||
try {
|
||||
const result = await this.apiClient.getLeagueDetail(leagueId);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'notImplemented', message: 'getLeagueDetail' });
|
||||
}
|
||||
}
|
||||
|
||||
async getSettings(sponsorId: string): Promise<Result<any, DomainError>> {
|
||||
try {
|
||||
const result = await this.apiClient.getSettings(sponsorId);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'notImplemented', message: 'getSettings' });
|
||||
}
|
||||
}
|
||||
|
||||
async updateSettings(sponsorId: string, input: any): Promise<Result<void, DomainError>> {
|
||||
try {
|
||||
await this.apiClient.updateSettings(sponsorId, input);
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'notImplemented', message: 'updateSettings' });
|
||||
}
|
||||
}
|
||||
|
||||
async acceptSponsorshipRequest(requestId: string, sponsorId: string): Promise<Result<void, DomainError>> {
|
||||
try {
|
||||
await this.apiClient.acceptSponsorshipRequest(requestId, sponsorId);
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'notImplemented', message: 'acceptSponsorshipRequest' });
|
||||
}
|
||||
}
|
||||
|
||||
async rejectSponsorshipRequest(requestId: string, sponsorId: string, reason?: string): Promise<Result<void, DomainError>> {
|
||||
try {
|
||||
await this.apiClient.rejectSponsorshipRequest(requestId, sponsorId, reason);
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'notImplemented', message: 'rejectSponsorshipRequest' });
|
||||
}
|
||||
}
|
||||
|
||||
async getPendingSponsorshipRequests(input: any): Promise<Result<any, DomainError>> {
|
||||
try {
|
||||
const result = await this.apiClient.getPendingSponsorshipRequests(input);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'notImplemented', message: 'getPendingSponsorshipRequests' });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,24 +5,15 @@ import { Result } from '@/lib/contracts/Result';
|
||||
import type { Service } from '@/lib/contracts/services/Service';
|
||||
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import type { GetPendingSponsorshipRequestsOutputDTO } from '@/lib/types/generated/GetPendingSponsorshipRequestsOutputDTO';
|
||||
import type { AcceptSponsorshipRequestInputDTO } from '@/lib/types/generated/AcceptSponsorshipRequestInputDTO';
|
||||
import type { RejectSponsorshipRequestInputDTO } from '@/lib/types/generated/RejectSponsorshipRequestInputDTO';
|
||||
|
||||
export interface AcceptSponsorshipRequestCommand {
|
||||
requestId: string;
|
||||
actorDriverId: string;
|
||||
interface GetPendingRequestsInput {
|
||||
entityType: string;
|
||||
entityId: string;
|
||||
}
|
||||
|
||||
export interface RejectSponsorshipRequestCommand {
|
||||
requestId: string;
|
||||
actorDriverId: string;
|
||||
reason: string | null;
|
||||
}
|
||||
|
||||
export type AcceptSponsorshipRequestServiceError =
|
||||
| 'ACCEPT_SPONSORSHIP_REQUEST_FAILED';
|
||||
|
||||
export type RejectSponsorshipRequestServiceError =
|
||||
| 'REJECT_SPONSORSHIP_REQUEST_FAILED';
|
||||
|
||||
export class SponsorshipRequestsService implements Service {
|
||||
private readonly client: SponsorsApiClient;
|
||||
|
||||
@@ -38,13 +29,29 @@ export class SponsorshipRequestsService implements Service {
|
||||
this.client = new SponsorsApiClient(baseUrl, errorReporter, logger);
|
||||
}
|
||||
|
||||
async acceptRequest(
|
||||
command: AcceptSponsorshipRequestCommand,
|
||||
): Promise<Result<void, AcceptSponsorshipRequestServiceError>> {
|
||||
async getPendingRequests(
|
||||
input: GetPendingRequestsInput,
|
||||
): Promise<Result<GetPendingSponsorshipRequestsOutputDTO, 'GET_PENDING_REQUESTS_FAILED'>> {
|
||||
try {
|
||||
await this.client.acceptSponsorshipRequest(command.requestId, {
|
||||
actorDriverId: command.actorDriverId,
|
||||
} as any);
|
||||
const result = await this.client.getPendingSponsorshipRequests({
|
||||
entityType: input.entityType,
|
||||
entityId: input.entityId,
|
||||
});
|
||||
|
||||
return Result.ok(result);
|
||||
} catch {
|
||||
return Result.err('GET_PENDING_REQUESTS_FAILED');
|
||||
}
|
||||
}
|
||||
|
||||
async acceptRequest(
|
||||
command: { requestId: string; actorDriverId: string },
|
||||
): Promise<Result<void, 'ACCEPT_SPONSORSHIP_REQUEST_FAILED'>> {
|
||||
try {
|
||||
const input: AcceptSponsorshipRequestInputDTO = {
|
||||
respondedBy: command.actorDriverId,
|
||||
};
|
||||
await this.client.acceptSponsorshipRequest(command.requestId, input);
|
||||
|
||||
return Result.ok(undefined);
|
||||
} catch {
|
||||
@@ -53,13 +60,14 @@ export class SponsorshipRequestsService implements Service {
|
||||
}
|
||||
|
||||
async rejectRequest(
|
||||
command: RejectSponsorshipRequestCommand,
|
||||
): Promise<Result<void, RejectSponsorshipRequestServiceError>> {
|
||||
command: { requestId: string; actorDriverId: string; reason: string | null },
|
||||
): Promise<Result<void, 'REJECT_SPONSORSHIP_REQUEST_FAILED'>> {
|
||||
try {
|
||||
await this.client.rejectSponsorshipRequest(command.requestId, {
|
||||
actorDriverId: command.actorDriverId,
|
||||
reason: command.reason ?? undefined,
|
||||
} as any);
|
||||
const input: RejectSponsorshipRequestInputDTO = {
|
||||
respondedBy: command.actorDriverId,
|
||||
reason: command.reason || undefined,
|
||||
};
|
||||
await this.client.rejectSponsorshipRequest(command.requestId, input);
|
||||
|
||||
return Result.ok(undefined);
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user