Refactor: Delegate notification store updates to calling components after API responses.

This commit is contained in:
pa
2026-03-04 21:48:28 +09:00
parent c522ab21f1
commit 905999b9ae
5 changed files with 116 additions and 128 deletions

View File

@@ -1,17 +1,5 @@
import { useGalleryStore, useNotificationStore } from '../stores';
import { notificationRequest } from '.';
import { request } from '../service/request';
/**
* @returns {any}
*/
function getGalleryStore() {
return useGalleryStore();
}
function getNotificationStore() {
return useNotificationStore();
}
import { useGalleryStore } from '../stores';
const notificationReq = {
/** @typedef {{
@@ -120,7 +108,7 @@ const notificationReq = {
return request(`invite/${receiverUserId}/photo`, {
uploadImageLegacy: true,
postData: JSON.stringify(params),
imageData: getGalleryStore().uploadImage
imageData: useGalleryStore().uploadImage
}).then((json) => {
const args = {
json,
@@ -149,7 +137,7 @@ const notificationReq = {
return request(`requestInvite/${receiverUserId}/photo`, {
uploadImageLegacy: true,
postData: JSON.stringify(params),
imageData: getGalleryStore().uploadImage
imageData: useGalleryStore().uploadImage
}).then((json) => {
const args = {
json,
@@ -178,7 +166,7 @@ const notificationReq = {
return request(`invite/${inviteId}/response/photo`, {
uploadImageLegacy: true,
postData: JSON.stringify(params),
imageData: getGalleryStore().uploadImage,
imageData: useGalleryStore().uploadImage,
inviteId
}).then((json) => {
const args = {
@@ -200,27 +188,13 @@ const notificationReq = {
{
method: 'PUT'
}
)
.then((json) => {
const args = {
json,
params
};
getNotificationStore().handleNotificationAccept(args);
return args;
})
.catch((err) => {
// if friend request could not be found, delete it
if (err && err.message && err.message.includes('404')) {
getNotificationStore().handleNotificationHide(
params.notificationId
);
}
return {
json: null,
params
};
});
).then((json) => {
const args = {
json,
params
};
return args;
});
},
/**
@@ -238,9 +212,6 @@ const notificationReq = {
json,
params
};
getNotificationStore().handleNotificationHide(
params.notificationId
);
return args;
});
},
@@ -289,24 +260,13 @@ const notificationReq = {
return request(`notifications/${params.notificationId}/respond`, {
method: 'POST',
params
})
.then((json) => {
const args = {
json,
params
};
return args;
})
.catch(() => {
getNotificationStore().handleNotificationV2Hide(
params.notificationId
);
notificationRequest.hideNotificationV2(params.notificationId);
return {
json: null,
params
};
});
}).then((json) => {
const args = {
json,
params
};
return args;
});
},
hideNotificationV2(notificationId) {
@@ -322,35 +282,6 @@ const notificationReq = {
return args;
});
}
// sendInviteGalleryPhoto(params, receiverUserId) {
// return request(`invite/${receiverUserId}/photo`, {
// method: 'POST',
// params
// }).then((json) => {
// const args = {
// json,
// params,
// receiverUserId
// };
// API.$emit('NOTIFICATION:INVITE:GALLERYPHOTO:SEND', args);
// return args;
// });
// },
// API.clearNotifications = function () {
// return request('auth/user/notifications/clear', {
// method: 'PUT'
// }).then((json) => {
// var args = {
// json
// };
// // FIXME: NOTIFICATION:CLEAR 핸들링
// this.$emit('NOTIFICATION:CLEAR', args);
// return args;
// });
// };
};
// #endregion
export default notificationReq;