123 lines
3.5 KiB
TypeScript
123 lines
3.5 KiB
TypeScript
import { apiClient } from './client'
|
|
|
|
export interface Listing {
|
|
id: number
|
|
account_id: number
|
|
owner_id: number
|
|
owner_phone?: string
|
|
owner_nickname?: string
|
|
title: string
|
|
description: string
|
|
game_name: string
|
|
server_region: string
|
|
login_platform: string
|
|
rank_level: string
|
|
haf_coin_amount: number
|
|
price_hourly: number
|
|
price_daily: number
|
|
price_weekly: number
|
|
deposit_amount: number
|
|
min_rent_hours: number
|
|
max_rent_hours: number
|
|
status: string
|
|
review_status: string
|
|
review_reason: string
|
|
published_at?: string
|
|
created_at: string
|
|
updated_at: string
|
|
}
|
|
|
|
export interface ListingPayload {
|
|
title: string
|
|
description: string
|
|
server_region: string
|
|
login_platform: string
|
|
rank_level: string
|
|
haf_coin_amount: number
|
|
price_hourly: number
|
|
price_daily: number
|
|
price_weekly: number
|
|
deposit_amount: number
|
|
min_rent_hours: number
|
|
max_rent_hours: number
|
|
}
|
|
|
|
interface ApiResponse<T> {
|
|
code: string
|
|
message: string
|
|
data: T
|
|
}
|
|
|
|
export async function fetchListings() {
|
|
const { data } = await apiClient.get<ApiResponse<{ items: Listing[] }>>('/listings')
|
|
return data.data.items
|
|
}
|
|
|
|
export async function fetchListing(id: string | number) {
|
|
const { data } = await apiClient.get<ApiResponse<Listing>>(`/listings/${id}`)
|
|
return data.data
|
|
}
|
|
|
|
export async function fetchSellerListings() {
|
|
const { data } = await apiClient.get<ApiResponse<{ items: Listing[] }>>('/seller/listings')
|
|
return data.data.items
|
|
}
|
|
|
|
export async function createListing(payload: ListingPayload) {
|
|
const { data } = await apiClient.post<ApiResponse<Listing>>('/listings', payload)
|
|
return data.data
|
|
}
|
|
|
|
export async function submitListingReview(id: number) {
|
|
const { data } = await apiClient.post<ApiResponse<Listing>>(`/listings/${id}/submit-review`)
|
|
return data.data
|
|
}
|
|
|
|
export async function offlineListing(id: number) {
|
|
const { data } = await apiClient.delete<ApiResponse<{ offline: boolean }>>(`/listings/${id}`)
|
|
return data.data
|
|
}
|
|
|
|
export async function fetchPendingReviewListings() {
|
|
const { data } = await apiClient.get<ApiResponse<{ items: Listing[] }>>('/admin/listings/pending')
|
|
return data.data.items
|
|
}
|
|
|
|
export interface AdminListingQuery {
|
|
owner_id?: string
|
|
status?: string
|
|
review_status?: string
|
|
limit?: number
|
|
}
|
|
|
|
export async function fetchAdminListings(query: AdminListingQuery = {}) {
|
|
const params = Object.fromEntries(Object.entries(query).filter(([, value]) => value !== '' && value !== undefined))
|
|
const { data } = await apiClient.get<ApiResponse<{ items: Listing[] }>>('/admin/listings', { params })
|
|
return data.data.items
|
|
}
|
|
|
|
export async function fetchAdminListing(id: string | number) {
|
|
const { data } = await apiClient.get<ApiResponse<Listing>>(`/admin/listings/${id}`)
|
|
return data.data
|
|
}
|
|
|
|
export async function adminOfflineListing(id: number, reason: string) {
|
|
const { data } = await apiClient.post<ApiResponse<Listing>>(`/admin/listings/${id}/offline`, { reason })
|
|
return data.data
|
|
}
|
|
|
|
export async function adminMarkListingAbnormal(id: number, reason: string) {
|
|
const { data } = await apiClient.post<ApiResponse<Listing>>(`/admin/listings/${id}/mark-abnormal`, { reason })
|
|
return data.data
|
|
}
|
|
|
|
export async function approveListing(id: number) {
|
|
const { data } = await apiClient.post<ApiResponse<Listing>>(`/admin/listings/${id}/approve`)
|
|
return data.data
|
|
}
|
|
|
|
export async function rejectListing(id: number, reason: string) {
|
|
const { data } = await apiClient.post<ApiResponse<Listing>>(`/admin/listings/${id}/reject`, { reason })
|
|
return data.data
|
|
}
|