's'
This commit is contained in:
@@ -45,6 +45,7 @@ export async function POST(request: NextRequest) {
|
||||
const whyJoin = String(formData.why_join || "").trim();
|
||||
const region = String(formData.region || "").trim();
|
||||
const availableTime = String(formData.available_time || "").trim();
|
||||
const isVolunteer = !!formData.is_volunteer;
|
||||
if (!intro && (status || activityType || whyJoin || region || availableTime)) {
|
||||
const extra = [status && `状态:${status}`, activityType && `活动偏好:${activityType}`, whyJoin && `原因:${whyJoin}`, region && `区域:${region}`, availableTime && `时间:${availableTime}`].filter(Boolean).join(" | ");
|
||||
intro = extra;
|
||||
@@ -52,39 +53,22 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
const isDigitalNomad = session === "digital-nomad";
|
||||
const contact = wechatOrPhone || wechat || phone;
|
||||
if (!nickname || !intro || !session || !agreeRules || !xiaohongshuUrl) {
|
||||
if (!nickname || !session || !agreeRules) {
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: "请填写必填项(含小红书主页地址、自我介绍)" },
|
||||
{ ok: false, error: "请填写必填项" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
if (!contact) {
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: "请填写微信号或手机号" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
if (isDigitalNomad && (!education || !graduationYear)) {
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: "请选择学历和毕业时间" },
|
||||
{ ok: false, error: "请填写微信号" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const userId = getUserIdFromCookie(request) || generateAnonId();
|
||||
|
||||
const EDUCATION_GRAD_AGE: Record<string, number> = {
|
||||
"高中及以下": 18,
|
||||
大专: 21,
|
||||
本科: 22,
|
||||
硕士: 25,
|
||||
博士: 28,
|
||||
};
|
||||
const gradAge = EDUCATION_GRAD_AGE[education] ?? 22;
|
||||
const estimatedAge = new Date().getFullYear() - parseInt(graduationYear, 10) + gradAge;
|
||||
const ageRangeForRecord = isDigitalNomad && education && graduationYear
|
||||
? `推算约${estimatedAge}岁(学历${education}+${graduationYear}毕业)`
|
||||
: ageRange;
|
||||
const ageRangeForRecord = ageRange || "";
|
||||
|
||||
const record = {
|
||||
user_id: userId,
|
||||
@@ -104,6 +88,7 @@ export async function POST(request: NextRequest) {
|
||||
amount: 0,
|
||||
age_range: ageRangeForRecord,
|
||||
first_time: firstTime,
|
||||
is_volunteer: isVolunteer,
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -167,6 +152,8 @@ async function tryPocketBaseDirect(
|
||||
type: record.type ?? "",
|
||||
order_id: record.order_id ?? "",
|
||||
amount: record.amount ?? 0,
|
||||
is_volunteer: record.is_volunteer ?? false,
|
||||
xiaohongshu_url: record.xiaohongshu_url ?? "",
|
||||
};
|
||||
|
||||
try {
|
||||
|
||||
@@ -37,9 +37,9 @@ export async function GET(request: NextRequest) {
|
||||
const total = typeof data?.totalItems === "number" ? data.totalItems : items.length;
|
||||
stats[s.id] = {
|
||||
count: total,
|
||||
joiners: items.slice(0, 6).map((r: { nickname?: string; xiaohongshu_nickname?: string; xiaohongshu_avatar?: string; xiaohongshu_url?: string }) => ({
|
||||
joiners: items.slice(0, 6).map((r: { nickname?: string; xiaohongshu_nickname?: string; xiaohongshu_avatar?: string; xiaohongshu_url?: string; media?: string }) => ({
|
||||
nickname: String(r?.xiaohongshu_nickname || r?.nickname || "").trim() || "匿名",
|
||||
avatar: String(r?.xiaohongshu_avatar || "").trim() || undefined,
|
||||
avatar: String(r?.xiaohongshu_avatar || r?.media || "").trim() || undefined,
|
||||
xiaohongshu_url: String(r?.xiaohongshu_url || "").trim() || undefined,
|
||||
})),
|
||||
};
|
||||
|
||||
40
app/api/join/volunteers/route.ts
Normal file
40
app/api/join/volunteers/route.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getAdminToken } from "@/app/lib/pocketbase/admin";
|
||||
import { getPocketBaseConfig } from "@/config/services.config";
|
||||
|
||||
/** 获取志愿者列表 - solanRed 中 is_volunteer=true 的记录 */
|
||||
export async function GET() {
|
||||
const token = await getAdminToken();
|
||||
if (!token) {
|
||||
return NextResponse.json({ ok: true, volunteers: [] }, { status: 200 });
|
||||
}
|
||||
|
||||
const pb = getPocketBaseConfig();
|
||||
const base = pb.url.replace(/\/$/, "");
|
||||
|
||||
try {
|
||||
const filter = encodeURIComponent('is_volunteer=true');
|
||||
const res = await fetch(
|
||||
`${base}/api/collections/${pb.joinCollection}/records?filter=${filter}&sort=-created&perPage=20`,
|
||||
{
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
cache: "no-store",
|
||||
}
|
||||
);
|
||||
if (!res.ok) {
|
||||
return NextResponse.json({ ok: true, volunteers: [] }, { 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 });
|
||||
} catch {
|
||||
return NextResponse.json({ ok: true, volunteers: [] }, { status: 200 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user