diff --git a/composables/api/usePublicAPI.ts b/composables/api/usePublicAPI.ts index dd8473c..13b23f1 100644 --- a/composables/api/usePublicAPI.ts +++ b/composables/api/usePublicAPI.ts @@ -1,5 +1,5 @@ import type { FetchOptions } from 'ofetch'; -import type { ArticlesStats } from '~/types/responses'; +import type { ArticlesStats, UpdateArticleStatsResponse } from '~/types/responses'; interface FetchArticleStatsOptions extends FetchOptions { params: { @@ -19,10 +19,10 @@ export default function usePublicAPI() { $fetch('/api/public/article/stats', { ...options, method: 'GET' }); const updateArticleRate = (options: FetchArticleStatsRateOptions) => - $fetch('/api/public/article/stats/rate', { ...options, method: 'PUT' }); + $fetch('/api/public/article/stats/rate', { ...options, method: 'PUT' }); const updateArticleViews = (options: FetchArticleStatsOptions) => - $fetch('/api/public/article/stats/views', { ...options, method: 'PUT' }); + $fetch('/api/public/article/stats/views', { ...options, method: 'PUT' }); return { fetchArticleStats, updateArticleRate, updateArticleViews }; } diff --git a/composables/api/useUserAPI.ts b/composables/api/useUserAPI.ts index 4064862..ab97d21 100644 --- a/composables/api/useUserAPI.ts +++ b/composables/api/useUserAPI.ts @@ -1,5 +1,5 @@ import type { FetchOptions } from 'ofetch'; -import type { WhoamiResponse } from '~/types/responses'; +import type { DeleteUserFavouriteResponse, UpdateUserAvatarResponse, WhoamiResponse } from '~/types/responses'; import type { FavouriteArticle, Profile } from '~/types/user'; interface UpdateProfileOptions extends FetchOptions { @@ -62,10 +62,18 @@ export default function useUserAPI() { $fetch(`/api/user/${id}/profile`, { ...defaultOptions, ...options, method: 'PUT' }); const updateProfileAvatar = (id: string, options: UpdateProfileAvatarOptions) => - $fetch(`/api/user/${id}/profile/avatar`, { ...defaultOptions, ...options, method: 'PUT' }); + $fetch(`/api/user/${id}/profile/avatar`, { + ...defaultOptions, + ...options, + method: 'PUT', + }); const removeFavouriteArticle = (id: string, options: RemoveFavouriteArticleOptions) => - $fetch(`/api/user/${id}/favourites`, { ...defaultOptions, ...options, method: 'DELETE' }); + $fetch(`/api/user/${id}/favourites`, { + ...defaultOptions, + ...options, + method: 'DELETE', + }); const addFavouriteArticle = (id: string, options: AddFavouriteArticleOptions) => $fetch(`/api/user/${id}/favourites`, { ...defaultOptions, ...options, method: 'PUT' }); diff --git a/pages/profile/index.vue b/pages/profile/index.vue index b4ec547..9c76e16 100644 --- a/pages/profile/index.vue +++ b/pages/profile/index.vue @@ -222,7 +222,8 @@ const saveChanges = async () => { if (avatar.value) { const avatarBody = new FormData(); avatarBody.append('avatar', avatar.value); - uploadedAvatar = await updateProfileAvatar(user.value.profile.id as string, { body: avatarBody }); + const res = await updateProfileAvatar(user.value.profile.id as string, { body: avatarBody }); + uploadedAvatar = res.path; } const profileBody = { diff --git a/server/api/public/article/stats/rate.put.ts b/server/api/public/article/stats/rate.put.ts index 4b666a3..cda310f 100644 --- a/server/api/public/article/stats/rate.put.ts +++ b/server/api/public/article/stats/rate.put.ts @@ -30,5 +30,5 @@ export default defineEventHandler(async (event) => { await stats.updateOne({ ratings, rate }); - return true; + return { updated: true }; }); diff --git a/server/api/public/article/stats/views.put.ts b/server/api/public/article/stats/views.put.ts index 064770d..88bb614 100644 --- a/server/api/public/article/stats/views.put.ts +++ b/server/api/public/article/stats/views.put.ts @@ -18,5 +18,5 @@ export default defineEventHandler(async (event) => { await ArticleStats.create({ topic, title, views: 1 }); } - return true; + return { updated: true }; }); diff --git a/server/api/user/[id]/favourites/index.delete.ts b/server/api/user/[id]/favourites/index.delete.ts index f6a1dbd..507a100 100644 --- a/server/api/user/[id]/favourites/index.delete.ts +++ b/server/api/user/[id]/favourites/index.delete.ts @@ -23,7 +23,7 @@ export default defineEventHandler(async (event) => { throw new MongooseError('User with provided ID is not found'); } - return true; + return { deleted: true }; } catch (error) { return sendError( event, diff --git a/server/api/user/[id]/profile/avatar/index.put.ts b/server/api/user/[id]/profile/avatar/index.put.ts index e6d2c9e..529d337 100644 --- a/server/api/user/[id]/profile/avatar/index.put.ts +++ b/server/api/user/[id]/profile/avatar/index.put.ts @@ -61,7 +61,7 @@ export default defineEventHandler(async (event) => { transformation: { format: 'webp' }, }); - return `/storage/${img.public_id}`; + return { path: `/storage/${img.public_id}` }; } catch (error) { const errorInput = isCloudinarUploadApiError(error) ? { statusCode: error.http_code, statusMessage: error.message } diff --git a/types/responses.ts b/types/responses.ts index 5c234f6..bfd10ea 100644 --- a/types/responses.ts +++ b/types/responses.ts @@ -36,3 +36,15 @@ export interface ArticlesStats { topic?: string; title?: string; } + +export interface UpdateArticleStatsResponse { + updated: boolean; +} + +export interface DeleteUserFavouriteResponse { + deleted: boolean; +} + +export interface UpdateUserAvatarResponse { + path: string; +}