(request)
| 2 | import clientPromise from "@/lib/mongodb" |
| 3 | |
| 4 | export async function POST(request) { |
| 5 | |
| 6 | const body = await request.json() |
| 7 | const client = await clientPromise; |
| 8 | const db = client.db("bitlinks") |
| 9 | const collection = db.collection("url") |
| 10 | |
| 11 | // Check if the short url exists |
| 12 | const doc = await collection.findOne({shorturl: body.shorturl}) |
| 13 | if(doc){ |
| 14 | return Response.json({success: false, error: true, message: 'URL already exists!' }) |
| 15 | } |
| 16 | |
| 17 | const result = await collection.insertOne({ |
| 18 | url: body.url, |
| 19 | shorturl: body.shorturl |
| 20 | }) |
| 21 | |
| 22 | return Response.json({success: true, error: false, message: 'URL Generated Successfully' }) |
| 23 | } |
nothing calls this directly
no outgoing calls
no test coverage detected