feat(purchase): 소모품 사진 기능 — 검색 썸네일 + 신규/기존 품목 마스터 사진 등록
- 모바일 검색 결과에 품목 사진 썸네일 표시 (photo_path 있으면 이미지, 없으면 아이콘) - 데스크탑 검색 드롭다운에도 사진 썸네일 추가 - 신규 품목 등록 시 사진 촬영 → consumable_items.photo_path에 저장 (bulk API) - 기존 품목에 사진 없을 때 장바구니에서 "품목 사진 등록" → PUT /consumable-items/:id/photo - imageUploadService에 consumables 디렉토리 추가 - HEIC 변환 + 폴백 지원 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -225,9 +225,14 @@ const PurchaseRequestController = {
|
||||
if (existing.length > 0) {
|
||||
itemId = existing[0].item_id;
|
||||
} else {
|
||||
// 신규 품목 사진 저장 (마스터에)
|
||||
let itemPhotoPath = null;
|
||||
if (item.item_photo) {
|
||||
itemPhotoPath = await saveBase64Image(item.item_photo, 'item', 'consumables');
|
||||
}
|
||||
const [ins] = await conn.query(
|
||||
`INSERT INTO consumable_items (item_name, spec, maker, category, is_active) VALUES (?, ?, ?, ?, 1)`,
|
||||
[item.item_name.trim(), item.spec || null, item.maker || null, item.category || 'consumable']
|
||||
`INSERT INTO consumable_items (item_name, spec, maker, category, photo_path, is_active) VALUES (?, ?, ?, ?, ?, 1)`,
|
||||
[item.item_name.trim(), item.spec || null, item.maker || null, item.category || 'consumable', itemPhotoPath]
|
||||
);
|
||||
itemId = ins.insertId;
|
||||
newItemRegistered = true;
|
||||
@@ -261,6 +266,25 @@ const PurchaseRequestController = {
|
||||
}
|
||||
},
|
||||
|
||||
// 품목 마스터 사진 등록/업데이트
|
||||
updateItemPhoto: async (req, res) => {
|
||||
try {
|
||||
const { photo } = req.body;
|
||||
if (!photo) return res.status(400).json({ success: false, message: '사진을 첨부해주세요.' });
|
||||
const itemPhotoPath = await saveBase64Image(photo, 'item', 'consumables');
|
||||
if (!itemPhotoPath) return res.status(500).json({ success: false, message: '사진 저장에 실패했습니다.' });
|
||||
|
||||
const { getDb } = require('../dbPool');
|
||||
const db = await getDb();
|
||||
await db.query('UPDATE consumable_items SET photo_path = ? WHERE item_id = ?', [itemPhotoPath, req.params.id]);
|
||||
koreanSearch.clearCache();
|
||||
res.json({ success: true, data: { photo_path: itemPhotoPath }, message: '품목 사진이 등록되었습니다.' });
|
||||
} catch (err) {
|
||||
logger.error('updateItemPhoto error:', err);
|
||||
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
|
||||
}
|
||||
},
|
||||
|
||||
// 스마트 검색 (초성 + 별칭 + substring)
|
||||
search: async (req, res) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user