Browse Source

feat(profile): persist discover visibility and location fields

Made-with: Cursor
main
npmrun 10 hours ago
parent
commit
0bb2a56f15
  1. 3
      server/api/me/profile.get.ts
  2. 6
      server/api/me/profile.put.ts
  3. 20
      server/service/profile/index.ts

3
server/api/me/profile.get.ts

@ -18,6 +18,9 @@ export default defineWrappedResponseHandler(async (event) => {
bioVisibility: row.bioVisibility, bioVisibility: row.bioVisibility,
socialLinks: parseSocialLinksJson(row.socialLinksJson), socialLinks: parseSocialLinksJson(row.socialLinksJson),
publicSlug: row.publicSlug, publicSlug: row.publicSlug,
discoverVisible: Boolean(row.discoverVisible),
discoverLocation: row.discoverLocation ?? null,
discoverShowLocation: Boolean(row.discoverShowLocation),
role: row.role, role: row.role,
status: row.status, status: row.status,
}, },

6
server/api/me/profile.put.ts

@ -12,6 +12,9 @@ export default defineWrappedResponseHandler(async (event) => {
bioVisibility?: string; bioVisibility?: string;
socialLinks?: { label: string; url: string; visibility: string; icon?: string }[]; socialLinks?: { label: string; url: string; visibility: string; icon?: string }[];
publicSlug?: string | null; publicSlug?: string | null;
discoverVisible?: boolean;
discoverLocation?: string | null;
discoverShowLocation?: boolean;
}>(event); }>(event);
try { try {
@ -25,6 +28,9 @@ export default defineWrappedResponseHandler(async (event) => {
body.bioVisibility !== undefined ? visibilitySchema.parse(body.bioVisibility) : undefined, body.bioVisibility !== undefined ? visibilitySchema.parse(body.bioVisibility) : undefined,
socialLinks: body.socialLinks, socialLinks: body.socialLinks,
publicSlug: body.publicSlug, publicSlug: body.publicSlug,
discoverVisible: body.discoverVisible,
discoverLocation: body.discoverLocation,
discoverShowLocation: body.discoverShowLocation,
}); });
if (!row) { if (!row) {
throw createError({ statusCode: 404, statusMessage: "未找到" }); throw createError({ statusCode: 404, statusMessage: "未找到" });

20
server/service/profile/index.ts

@ -34,6 +34,14 @@ const linkItemSchema = z.object({
icon: socialLinkIconSchema.optional(), icon: socialLinkIconSchema.optional(),
}); });
const discoverLocationPatchSchema = z.union([
z.null(),
z.string().max(200).transform((s) => {
const t = s.trim();
return t.length > 0 ? t : null;
}),
]);
export type SocialLinkItem = z.infer<typeof linkItemSchema>; export type SocialLinkItem = z.infer<typeof linkItemSchema>;
export async function getProfileRow(userId: number) { export async function getProfileRow(userId: number) {
@ -51,6 +59,9 @@ export async function updateProfile(
bioVisibility?: Visibility; bioVisibility?: Visibility;
socialLinks?: SocialLinkItem[]; socialLinks?: SocialLinkItem[];
publicSlug?: string | null; publicSlug?: string | null;
discoverVisible?: boolean;
discoverLocation?: string | null;
discoverShowLocation?: boolean;
}, },
) { ) {
const updates: Record<string, unknown> = {}; const updates: Record<string, unknown> = {};
@ -81,6 +92,15 @@ export async function updateProfile(
updates.publicSlug = publicSlugValue.parse(patch.publicSlug.trim().toLowerCase()); updates.publicSlug = publicSlugValue.parse(patch.publicSlug.trim().toLowerCase());
} }
} }
if (patch.discoverVisible !== undefined) {
updates.discoverVisible = patch.discoverVisible;
}
if (patch.discoverLocation !== undefined) {
updates.discoverLocation = discoverLocationPatchSchema.parse(patch.discoverLocation);
}
if (patch.discoverShowLocation !== undefined) {
updates.discoverShowLocation = patch.discoverShowLocation;
}
if (Object.keys(updates).length === 0) { if (Object.keys(updates).length === 0) {
return getProfileRow(userId); return getProfileRow(userId);

Loading…
Cancel
Save