優化應用 APP 新增、編輯邏輯

This commit is contained in:
2025-08-06 16:33:11 +08:00
parent dc4594a4cd
commit af88c0f037
100 changed files with 5592 additions and 7160 deletions

View File

@@ -27,7 +27,7 @@ export async function GET(
const sql = `
SELECT
a.*,
u.name as creator_name,
u.name as user_creator_name,
u.email as creator_email,
u.department as creator_department,
u.role as creator_role,
@@ -67,17 +67,20 @@ export async function GET(
githubUrl: app.github_url,
docsUrl: app.docs_url,
version: app.version,
icon: app.icon,
iconColor: app.icon_color,
likesCount: app.likes_count,
viewsCount: app.views_count,
rating: app.rating,
createdAt: app.created_at,
updatedAt: app.updated_at,
lastUpdated: app.last_updated,
department: app.department,
creator: {
id: app.creator_id,
name: app.creator_name,
name: app.creator_name || app.user_creator_name,
email: app.creator_email,
department: app.creator_department,
department: app.department || app.creator_department,
role: app.creator_role
},
team: app.team_id ? {
@@ -139,7 +142,9 @@ export async function PUT(
demoUrl,
githubUrl,
docsUrl,
version
version,
icon,
iconColor
}: AppUpdateRequest = body;
// 檢查應用程式是否存在
@@ -183,7 +188,12 @@ export async function PUT(
}
if (type !== undefined) {
const validTypes = ['web_app', 'mobile_app', 'desktop_app', 'api_service', 'ai_model', 'data_analysis', 'automation', 'other'];
const validTypes = [
'productivity', 'ai_model', 'automation', 'data_analysis', 'educational',
'healthcare', 'finance', 'iot_device', 'blockchain', 'ar_vr',
'machine_learning', 'computer_vision', 'nlp', 'robotics', 'cybersecurity',
'cloud_service', 'other'
];
if (!validTypes.includes(type)) {
return NextResponse.json(
{ error: '無效的應用程式類型' },
@@ -250,6 +260,14 @@ export async function PUT(
updateData.version = version;
}
if (icon !== undefined) {
updateData.icon = icon;
}
if (iconColor !== undefined) {
updateData.icon_color = iconColor;
}
// 更新應用程式
if (Object.keys(updateData).length > 0) {
await db.update('apps', updateData, { id });

View File

@@ -113,9 +113,9 @@ export async function GET(request: NextRequest) {
const sql = `
SELECT
a.*,
u.name as creator_name,
u.email as creator_email,
u.department as creator_department,
u.name as user_creator_name,
u.email as user_creator_email,
u.department as user_creator_department,
u.role as creator_role
FROM apps a
LEFT JOIN users u ON a.creator_id = u.id
@@ -143,17 +143,20 @@ export async function GET(request: NextRequest) {
githubUrl: app.github_url,
docsUrl: app.docs_url,
version: app.version,
icon: app.icon,
iconColor: app.icon_color,
likesCount: app.likes_count,
viewsCount: app.views_count,
rating: app.rating,
createdAt: app.created_at,
updatedAt: app.updated_at,
lastUpdated: app.last_updated,
department: app.department,
creator: {
id: app.creator_id,
name: app.creator_name,
email: app.creator_email,
department: app.creator_department,
name: app.creator_name || app.user_creator_name,
email: app.user_creator_email,
department: app.department || app.user_creator_department,
role: app.creator_role
},
team: app.team_id ? {
@@ -217,7 +220,11 @@ export async function POST(request: NextRequest) {
demoUrl,
githubUrl,
docsUrl,
version = '1.0.0'
version = '1.0.0',
creator,
department,
icon = 'Bot',
iconColor = 'from-blue-500 to-purple-500'
}: AppCreateRequest = body;
// 驗證必填欄位
@@ -246,10 +253,10 @@ export async function POST(request: NextRequest) {
// 驗證類型
const validTypes = [
'web_app', 'mobile_app', 'desktop_app', 'api_service', 'ai_model',
'data_analysis', 'automation', 'productivity', 'educational', 'healthcare',
'finance', 'iot_device', 'blockchain', 'ar_vr', 'machine_learning',
'computer_vision', 'nlp', 'robotics', 'cybersecurity', 'cloud_service', 'other'
'productivity', 'ai_model', 'automation', 'data_analysis', 'educational',
'healthcare', 'finance', 'iot_device', 'blockchain', 'ar_vr',
'machine_learning', 'computer_vision', 'nlp', 'robotics', 'cybersecurity',
'cloud_service', 'other'
];
if (!validTypes.includes(type)) {
return NextResponse.json(
@@ -290,7 +297,12 @@ export async function POST(request: NextRequest) {
github_url: githubUrl || null,
docs_url: docsUrl || null,
version,
status: 'draft'
status: 'draft',
icon: icon || 'Bot',
icon_color: iconColor || 'from-blue-500 to-purple-500',
department: department || user.department || 'HQBU',
creator_name: creator || user.name || '',
creator_email: user.email || ''
};
// 插入應用程式