+31
-8
@@ -506,7 +506,7 @@ async function feedbackComments(request, env, url) {
|
||||
}
|
||||
|
||||
async function feedbackDetail(request, env, url) {
|
||||
if (request.method !== 'GET') return json({ error: 'method_not_allowed' }, 405, { allow: 'GET' });
|
||||
if (!['GET', 'PATCH', 'DELETE'].includes(request.method)) return json({ error: 'method_not_allowed' }, 405, { allow: 'GET, PATCH, DELETE' });
|
||||
const user = await getSession(request, env);
|
||||
if (!user) return json({ error: 'unauthenticated' }, 401);
|
||||
if (!env.ABC_API_KEY) return json({ error: 'feedback_api_not_configured' }, 503);
|
||||
@@ -520,16 +520,37 @@ async function feedbackDetail(request, env, url) {
|
||||
if (!requesterId || !requesterTenantId) return json({ error: 'requester_identity_missing' }, 422);
|
||||
const apiBaseUrl = String(env.ABC_API_BASE_URL || 'https://feedback.hmac.kr').replace(/\/$/, '');
|
||||
const endpoint = `${apiBaseUrl}/api/projects/${encodeURIComponent(env.ABC_PROJECT_ID)}/channels/${encodeURIComponent(env.ABC_CHANNEL_ID)}/feedbacks/${encodeURIComponent(feedbackId)}`;
|
||||
const headers = {
|
||||
accept: 'application/json',
|
||||
'x-api-key': env.ABC_API_KEY,
|
||||
'x-requester-id': requesterId,
|
||||
'x-requester-tenant-id': requesterTenantId
|
||||
};
|
||||
let body;
|
||||
if (request.method === 'PATCH') {
|
||||
let input;
|
||||
try {
|
||||
input = await request.json();
|
||||
} catch (error) {
|
||||
return json({ error: 'invalid_json' }, 400);
|
||||
}
|
||||
if (!input || typeof input !== 'object' || Array.isArray(input)) return json({ error: 'invalid_json' }, 400);
|
||||
const payload = {};
|
||||
if (input.title != null) payload.title = String(input.title).trim();
|
||||
if (input.contents != null) payload.contents = String(input.contents).trim();
|
||||
if (input.Category != null) payload.Category = String(input.Category).trim();
|
||||
if (input.is_secret != null) payload.is_secret = input.is_secret === true || input.is_secret === 'true' || input.is_secret === 1 || input.is_secret === '1' ? 'true' : 'false';
|
||||
if (payload.title === '' || payload.contents === '' || payload.Category === '') return json({ error: 'invalid_feedback_update' }, 400);
|
||||
if (!Object.keys(payload).length) return json({ error: 'feedback_update_required' }, 400);
|
||||
headers['content-type'] = 'application/json';
|
||||
body = JSON.stringify(payload);
|
||||
}
|
||||
let response;
|
||||
try {
|
||||
response = await fetch(endpoint, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
accept: 'application/json',
|
||||
'x-api-key': env.ABC_API_KEY,
|
||||
'x-requester-id': requesterId,
|
||||
'x-requester-tenant-id': requesterTenantId
|
||||
}
|
||||
method: request.method,
|
||||
headers,
|
||||
body
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('feedback_detail_api_request_failed', error instanceof Error ? error.message : 'unknown');
|
||||
@@ -540,6 +561,8 @@ async function feedbackDetail(request, env, url) {
|
||||
const upstreamMessage = String(result.message || result.error || result.code || '').slice(0, 240);
|
||||
return json({ error: 'feedback_api_rejected', message: upstreamMessage || '문의 상세 조회에 실패했습니다.', status: response.status }, response.status >= 500 ? 502 : response.status);
|
||||
}
|
||||
if (request.method === 'DELETE') return json({ ok: true, id: feedbackId });
|
||||
if (request.method === 'PATCH') return json({ feedback: result.feedback || result.data || result });
|
||||
return json({ feedback: result.feedback || result.data || result });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user