'data'
This commit is contained in:
@@ -21,7 +21,11 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
|
||||
try {
|
||||
const { status, data } = await getSalonApi(request, `/api/salon/join/by-wechat?wechat_id=${encodeURIComponent(wechatId)}`);
|
||||
const { status, data } = await getSalonApi(
|
||||
request,
|
||||
`/api/salon/join/by-wechat?wechat_id=${encodeURIComponent(wechatId)}`,
|
||||
{ timeoutMs: 8000 }
|
||||
);
|
||||
if (status === 200 && data && typeof data === "object") {
|
||||
return NextResponse.json(data);
|
||||
}
|
||||
@@ -40,13 +44,16 @@ export async function GET(request: NextRequest) {
|
||||
const filter = encodeURIComponent(`wechatId = "${escaped}"`);
|
||||
|
||||
try {
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), 8000);
|
||||
const res = await fetch(
|
||||
`${base}/api/collections/${pb.joinCollection}/records?filter=${filter}&sort=-created&perPage=1`,
|
||||
{
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
cache: "no-store",
|
||||
signal: controller.signal,
|
||||
}
|
||||
);
|
||||
).finally(() => clearTimeout(timeoutId));
|
||||
if (!res.ok) return NextResponse.json(empty);
|
||||
const data = await res.json();
|
||||
const items = Array.isArray(data?.items) ? data.items : [];
|
||||
|
||||
@@ -46,6 +46,7 @@ export async function POST(request: NextRequest) {
|
||||
const region = String(formData.region || "").trim();
|
||||
const availableTime = String(formData.available_time || "").trim();
|
||||
const isVolunteer = !!formData.is_volunteer;
|
||||
const qualify = !!formData.qualify; // 女性且小红书帖子>10 时自动通过审核
|
||||
/** reason 仅存自我介绍,不合并其他字段 */
|
||||
const contact = wechatOrPhone || wechat || phone;
|
||||
if (!nickname || !session || !agreeRules) {
|
||||
@@ -85,6 +86,7 @@ export async function POST(request: NextRequest) {
|
||||
age_range: ageRangeForRecord,
|
||||
first_time: firstTime,
|
||||
is_volunteer: isVolunteer,
|
||||
qualify,
|
||||
};
|
||||
if (phone.trim()) {
|
||||
record.phone = phone.trim();
|
||||
@@ -133,6 +135,7 @@ async function tryPocketBaseDirect(
|
||||
const base = pb.url.replace(/\/$/, "");
|
||||
const url = `${base}/api/collections/${pb.joinCollection}/records`;
|
||||
|
||||
const qualify = !!(record.qualify ?? false);
|
||||
const body: Record<string, unknown> = {
|
||||
user_id: record.user_id,
|
||||
nickname: record.nickname,
|
||||
@@ -149,6 +152,7 @@ async function tryPocketBaseDirect(
|
||||
amount: record.amount ?? 0,
|
||||
xiaohongshu_url: record.xiaohongshu_url ?? "",
|
||||
is_volunteer: record.is_volunteer ?? false,
|
||||
is_approved: qualify,
|
||||
age_range: record.age_range ?? "",
|
||||
first_time: record.first_time ?? "",
|
||||
};
|
||||
|
||||
@@ -1,19 +1,33 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getAdminToken } from "@/app/lib/pocketbase/admin";
|
||||
import { getPocketBaseConfig } from "@/config/services.config";
|
||||
import { getSalonApi } from "@/app/lib/salonApi";
|
||||
|
||||
/** 获取志愿者列表 - 优先 salonapi,回退直连 PocketBase */
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { status, data } = await getSalonApi(request, "/api/salon/join/volunteers", {
|
||||
timeoutMs: 8000,
|
||||
});
|
||||
if (status === 200 && data && typeof data === "object") {
|
||||
const v = (data as { volunteer?: unknown }).volunteer;
|
||||
const payload = v && typeof v === "object" ? { volunteer: v } : { volunteer: null };
|
||||
return NextResponse.json(payload);
|
||||
}
|
||||
} catch {
|
||||
// salonapi 不可用,回退直连 PocketBase
|
||||
}
|
||||
|
||||
/** 获取志愿者列表 - solanRed 中 is_volunteer=true 的记录 */
|
||||
export async function GET() {
|
||||
const token = await getAdminToken();
|
||||
if (!token) {
|
||||
return NextResponse.json({ ok: true, volunteers: [] }, { status: 200 });
|
||||
return NextResponse.json({ ok: true, volunteer: null }, { status: 200 });
|
||||
}
|
||||
|
||||
const pb = getPocketBaseConfig();
|
||||
const base = pb.url.replace(/\/$/, "");
|
||||
|
||||
try {
|
||||
const filter = encodeURIComponent('is_volunteer=true && is_approved=true');
|
||||
const filter = encodeURIComponent("is_volunteer = true && is_approved = true");
|
||||
const res = await fetch(
|
||||
`${base}/api/collections/${pb.joinCollection}/records?filter=${filter}&sort=-created&perPage=20`,
|
||||
{
|
||||
@@ -22,19 +36,20 @@ export async function GET() {
|
||||
}
|
||||
);
|
||||
if (!res.ok) {
|
||||
return NextResponse.json({ ok: true, volunteers: [] }, { status: 200 });
|
||||
return NextResponse.json({ ok: true, volunteer: null }, { status: 200 });
|
||||
}
|
||||
const data = await res.json();
|
||||
const items = Array.isArray(data?.items) ? data.items : [];
|
||||
const volunteers = items.map(
|
||||
(r: { nickname?: string; xiaohongshu_nickname?: string; media?: string; xiaohongshu_url?: string }) => ({
|
||||
nickname: String(r?.xiaohongshu_nickname || r?.nickname || "").trim() || "志愿者",
|
||||
avatar: String(r?.media || "").trim() || undefined,
|
||||
xiaohongshu_url: String(r?.xiaohongshu_url || "").trim() || undefined,
|
||||
})
|
||||
);
|
||||
return NextResponse.json({ ok: true, volunteers });
|
||||
const rec = items[0] ?? null;
|
||||
const volunteer = rec
|
||||
? {
|
||||
nickname: String(rec?.xiaohongshu_nickname || rec?.nickname || "").trim() || "志愿者",
|
||||
avatar: String(rec?.media || "").trim() || undefined,
|
||||
xiaohongshu_url: String(rec?.xiaohongshu_url || "").trim() || undefined,
|
||||
}
|
||||
: null;
|
||||
return NextResponse.json({ ok: true, volunteer });
|
||||
} catch {
|
||||
return NextResponse.json({ ok: true, volunteers: [] }, { status: 200 });
|
||||
return NextResponse.json({ ok: true, volunteer: null }, { status: 200 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user