51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { deny } from "@/lib/policy/assert"
|
|
import { useAuthStore } from "@/store/auth"
|
|
import { useDisputeStore } from "@/store/disputes"
|
|
|
|
export function listDisputes() {
|
|
return useDisputeStore.getState().disputes
|
|
}
|
|
|
|
export function getDisputeByOrderId(orderId: string) {
|
|
return useDisputeStore.getState().disputes.find((dispute) => dispute.orderId === orderId)
|
|
}
|
|
|
|
export function submitDispute(input: { orderId: string; reason: string; evidence: string[] }) {
|
|
const user = useAuthStore.getState().user
|
|
if (!user?.id || !user.nickname) {
|
|
return { decision: deny("AUTH_REQUIRED", "请先登录") }
|
|
}
|
|
|
|
return useDisputeStore.getState().submitDispute({
|
|
orderId: input.orderId,
|
|
initiatorId: user.id,
|
|
initiatorName: user.nickname,
|
|
reason: input.reason,
|
|
evidence: input.evidence,
|
|
})
|
|
}
|
|
|
|
export function submitDisputeResponse(input: {
|
|
disputeId: string
|
|
reason: string
|
|
evidence: string[]
|
|
}) {
|
|
const userId = useAuthStore.getState().user?.id
|
|
if (!userId) {
|
|
return deny("AUTH_REQUIRED", "请先登录")
|
|
}
|
|
|
|
return useDisputeStore
|
|
.getState()
|
|
.submitResponse(input.disputeId, userId, input.reason, input.evidence)
|
|
}
|
|
|
|
export function submitDisputeAppeal(input: { disputeId: string; reason: string }) {
|
|
const userId = useAuthStore.getState().user?.id
|
|
if (!userId) {
|
|
return deny("AUTH_REQUIRED", "请先登录")
|
|
}
|
|
|
|
return useDisputeStore.getState().submitAppeal(input.disputeId, userId, input.reason)
|
|
}
|