fix(settings): final code quality fixes for My Profile tab

- add try/except to sync_identity endpoint
- strip id field from mission_preferences save body
- fix NDA v-for key to use company string (not index), add dedup guard
- move imports out of save_user_profile function body
This commit is contained in:
pyr0ball 2026-03-21 02:53:29 -07:00
parent 2937c1b0fa
commit c4a58c7e27
4 changed files with 17 additions and 18 deletions

View file

@ -983,13 +983,16 @@ class IdentitySyncPayload(BaseModel):
@app.post("/api/settings/resume/sync-identity") @app.post("/api/settings/resume/sync-identity")
def sync_identity(payload: IdentitySyncPayload): def sync_identity(payload: IdentitySyncPayload):
"""Sync identity fields from profile store back to user.yaml.""" """Sync identity fields from profile store back to user.yaml."""
data = load_user_profile(_user_yaml_path()) try:
data["name"] = payload.name data = load_user_profile(_user_yaml_path())
data["email"] = payload.email data["name"] = payload.name
data["phone"] = payload.phone data["email"] = payload.email
data["linkedin"] = payload.linkedin_url # yaml key is 'linkedin', not 'linkedin_url' data["phone"] = payload.phone
save_user_profile(_user_yaml_path(), data) data["linkedin"] = payload.linkedin_url # yaml key is 'linkedin', not 'linkedin_url'
return {"ok": True} save_user_profile(_user_yaml_path(), data)
return {"ok": True}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@app.put("/api/settings/profile") @app.put("/api/settings/profile")

View file

@ -7,6 +7,8 @@ here so port/host/SSL changes propagate everywhere automatically.
""" """
from __future__ import annotations from __future__ import annotations
from pathlib import Path from pathlib import Path
import os
import tempfile
import yaml import yaml
_DEFAULTS = { _DEFAULTS = {
@ -136,8 +138,6 @@ class UserProfile:
def load_user_profile(config_path: str) -> dict: def load_user_profile(config_path: str) -> dict:
"""Load user.yaml and return as a plain dict with safe defaults.""" """Load user.yaml and return as a plain dict with safe defaults."""
import yaml
from pathlib import Path
path = Path(config_path) path = Path(config_path)
if not path.exists(): if not path.exists():
return {} return {}
@ -148,10 +148,6 @@ def load_user_profile(config_path: str) -> dict:
def save_user_profile(config_path: str, data: dict) -> None: def save_user_profile(config_path: str, data: dict) -> None:
"""Atomically write the user profile dict to user.yaml.""" """Atomically write the user profile dict to user.yaml."""
import yaml
import os
import tempfile
from pathlib import Path
path = Path(config_path) path = Path(config_path)
path.parent.mkdir(parents=True, exist_ok=True) path.parent.mkdir(parents=True, exist_ok=True)
# Write to temp file then rename for atomicity # Write to temp file then rename for atomicity

View file

@ -57,7 +57,7 @@ export const useProfileStore = defineStore('settings/profile', () => {
career_summary: career_summary.value, career_summary: career_summary.value,
candidate_voice: candidate_voice.value, candidate_voice: candidate_voice.value,
inference_profile: inference_profile.value, inference_profile: inference_profile.value,
mission_preferences: mission_preferences.value, mission_preferences: mission_preferences.value.map(({ industry, note }) => ({ industry, note })),
nda_companies: nda_companies.value, nda_companies: nda_companies.value,
accessibility_focus: accessibility_focus.value, accessibility_focus: accessibility_focus.value,
lgbtq_focus: lgbtq_focus.value, lgbtq_focus: lgbtq_focus.value,

View file

@ -138,7 +138,7 @@
<div class="tag-list"> <div class="tag-list">
<span <span
v-for="(company, idx) in store.nda_companies" v-for="(company, idx) in store.nda_companies"
:key="idx" :key="company"
class="tag" class="tag"
> >
{{ company }} {{ company }}
@ -224,9 +224,9 @@ function removeMission(idx: number) {
// NDA helpers (autosave on add/remove) // NDA helpers (autosave on add/remove)
function addNda() { function addNda() {
const val = newNdaCompany.value.trim() const trimmed = newNdaCompany.value.trim()
if (!val) return if (!trimmed || store.nda_companies.includes(trimmed)) return
store.nda_companies = [...store.nda_companies, val] store.nda_companies = [...store.nda_companies, trimmed]
newNdaCompany.value = '' newNdaCompany.value = ''
store.save() store.save()
} }