1. Use Case: Product schema Code: const mongoose = require('mongoose'); const…
- User
User: 1. Use Case: Product schema Code: const mongoose = require('mongoose');
const productSchema = new mongoose.Schema({ name: { type: String, required: true, }, description: { type: String, required: true, }, price: { type: Number, required: true, min: 0, }, sizes: { type: [String], enum: ['S', 'M', 'L'], default: ['M'], }, colors: { type: [String], enum: ['red', 'blue'], }, images: { type: [String], default: [], }, stock: { type: Number, required: true, min: 0, }, rating: { type: Number, min: 0, max: 5, default: 0, } });
const Product = mongoose.model('Product', productSchema);
module.exports = Product; User: Description: develope a product insert api, accetp alll theses values from user, { "name": "string", "description": "string", "price": "number", "sizes": ["S", "M", "L"], "colors": ["red", "blue"], "images": ["url1", "url2"], "stock": "number", "rating": "number" } api functions name createProduct response with created product details and total product count insert product in to Product model
Generate source code based on the description above and respond in the following JSON format ONLY: { "name": "prompt_name", "schema": { "type": "string", "code": "Generated code" } } IMPORTANT: - Ensure the JSON response is error-free. - Include no additional text or explanations. Respond with the JSON object only.Assistant:
- Assistant
{ "name": "createProduct", "schema": { "type": "string", "code": "const express = require('express');\nconst router = express.Router();\nconst Product = require('./path/to/your/ProductModel'); // Update the path as needed\n\n// Create Product API\nrouter.post('/products', async (req, res) => {\n const { name, description, price, sizes, colors, images, stock, rating } = req.body;\n\n try {\n const product = new Product({\n name,\n description,\n price,\n sizes,\n colors,\n images,\n stock,\n rating\n });\n\n await product.save();\n const totalProducts = await Product.countDocuments();\n res.status(201).json({ product, totalProducts });\n } catch (error) {\n res.status(400).json({ message: error.message });\n }\n});\n\nmodule.exports = router;" } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.