forked from nisshchayarathi/gitverse-nextjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch_create.ts
More file actions
92 lines (80 loc) · 2.35 KB
/
batch_create.ts
File metadata and controls
92 lines (80 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// This file contains route templates
const routes = {
"app/api/ai/suggest-commit/route.ts": `import { NextRequest, NextResponse } from 'next/server'
import { requireAuth } from '@/lib/middleware'
import { geminiService } from '@/lib/services/geminiService'
export async function POST(request: NextRequest) {
try {
requireAuth(request)
const body = await request.json()
const { added, modified, deleted, diff } = body
const suggestions = await geminiService.suggestCommitMessage({
added: added || [],
modified: modified || [],
deleted: deleted || [],
diff,
})
return NextResponse.json({ suggestions })
} catch (error: any) {
console.error('Commit suggestion error:', error)
return NextResponse.json(
{ error: 'Failed to generate suggestions', details: error.message },
{ status: 500 }
)
}
}`,
"app/api/users/profile/route.ts": `import { NextRequest, NextResponse } from 'next/server'
import prisma from '@/lib/prisma'
import { requireAuth } from '@/lib/middleware'
export async function PUT(request: NextRequest) {
try {
const user = requireAuth(request)
const body = await request.json()
const { name, email, avatar } = body
if (!name || !email) {
return NextResponse.json(
{ message: 'Name and email are required' },
{ status: 400 }
)
}
const existingUser = await prisma.user.findFirst({
where: {
email,
id: { not: user.userId },
},
})
if (existingUser) {
return NextResponse.json(
{ message: 'Email is already in use' },
{ status: 400 }
)
}
const updateData: any = { name, email }
if (avatar && (avatar.startsWith('data:') || avatar.startsWith('http'))) {
updateData.image = avatar
}
const updatedUser = await prisma.user.update({
where: { id: user.userId },
data: updateData,
select: {
id: true,
name: true,
email: true,
image: true,
createdAt: true,
},
})
return NextResponse.json({
...updatedUser,
avatarUrl: (updatedUser as any).image,
})
} catch (error: any) {
console.error('Error updating profile:', error)
return NextResponse.json(
{ message: 'Failed to update profile' },
{ status: 500 }
)
}
}`,
};
console.log(JSON.stringify(routes, null, 2));