41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { AxiosInstance } from 'axios';
|
|
import { HttpInstanceFactory } from '@/utils/HttpInstanceFactory';
|
|
import { IPlayer } from '@/interfaces/player.type';
|
|
import { IExchangeRequest } from '@/api/exchange-request.api';
|
|
|
|
export interface IArchiveRequest {
|
|
id: number;
|
|
attributes: {
|
|
player: IPlayer;
|
|
exchange_requests: { data: IExchangeRequest[] };
|
|
rejected_requests: { data: IExchangeRequest[] };
|
|
};
|
|
}
|
|
|
|
export class ArchiveRequestApi {
|
|
private static instance: ArchiveRequestApi | null = null;
|
|
private httpInstance: AxiosInstance;
|
|
|
|
private constructor(token: string) {
|
|
this.httpInstance = HttpInstanceFactory.updateAuthorizedInstance(token);
|
|
}
|
|
|
|
public static getInstance(token: string): ArchiveRequestApi {
|
|
if (this.instance) return this.instance;
|
|
this.instance = new ArchiveRequestApi(token);
|
|
return this.instance;
|
|
}
|
|
|
|
async createArchiveRequest(playerId: number): Promise<IArchiveRequest> {
|
|
return (
|
|
await this.httpInstance.post<IArchiveRequest>(`/archive-requests`, {
|
|
data: {
|
|
player: {
|
|
connect: [{ id: playerId }],
|
|
},
|
|
},
|
|
})
|
|
).data;
|
|
}
|
|
}
|