Files
dating-app-frontend/src/composables/useProfile.ts
Oscar 10d696f4ca refactor(composables): migrate stores →
composables, align with updated API

  - Replace deleted Pinia stores with
  module-level singleton composables
    (useAuth, useChat, useFeed, useUi) — all
  return reactive({...}) so
    Refs auto-unwrap in both templates and
  script code

  - Align entire codebase with new
  swagger-generated api.ts types:
    · TagDto.value  (was .name) — FeedCard,
  FeedFilters, ProfileEditor,
      ProfileSetupView, MyProfileView,
  ProfileDetailView, useUi
    · MediaItemDto[] / .path  (was mediaUrls[],
  avatarUrl) — FeedCard,
      FeedView, MyProfileView,
  ProfileDetailView
    · ChatDto.status 'active'|'closed'  (was
  isActive: boolean) —
      ChatRoomView, ChatsListView
    · MessageDto.profileId  (was senderId) —
  ChatRoomView, ChatBubble
    · MeResponseDto → fetchMe now calls /me +
  /profiles/my in parallel
    · Token refresh: res.data.data.accessToken
  (nested wrapper) —
      router/index.ts aligned with client.ts
  interceptor

  - Fix FeedCard, ChatBubble imports pointing
  to deleted store files
  - Fix ProfileSetupView form type to avoid
  string|undefined on v-model
  - Fix history.back() → window.history.back()
  via goBack() helper
  - Fix chat.unreadCount possibly-undefined
  guard in ChatsListView
  - Fix MapPicker Leaflet icon cast (as unknown
  as Record<string, unknown>)
2026-06-08 15:01:54 +03:00

40 lines
1.2 KiB
TypeScript

import { ref } from 'vue';
import { apiClient } from '@/api/client';
import type { CreateProfileDto, UpdateProfileDto } from '@/api/api';
import type { UserProfile } from './useAuth';
const currentProfile = ref<UserProfile | null>(null);
const loading = ref(false);
async function fetchProfile(profileId: string) {
loading.value = true;
try {
const res = await apiClient.api.profilesControllerFindOne(profileId) as unknown as UserProfile;
currentProfile.value = res;
return res;
} finally {
loading.value = false;
}
}
async function createProfile(dto: CreateProfileDto) {
const res = await apiClient.api.profilesControllerCreate(dto) as unknown as UserProfile;
currentProfile.value = res;
return res;
}
async function updateProfile(profileId: string, dto: UpdateProfileDto) {
const res = await apiClient.api.profilesControllerUpdate(profileId, dto) as unknown as UserProfile;
currentProfile.value = res;
return res;
}
async function deleteProfile(profileId: string) {
await apiClient.api.profilesControllerDelete(profileId);
currentProfile.value = null;
}
export function useProfile() {
return { currentProfile, loading, fetchProfile, createProfile, updateProfile, deleteProfile };
}