Open AnshulMalik opened 1 year ago
I would like to work on it. Could you please assign it?
Hello @AnshulMalik! I have worked on an API that uses express.js and connects to a MongoDB database (that can be changed whenever required according to the database of Doc-Generator). For a demo, all the parts are in a single file. I will divide it into Model, Controller, and Router structures, once verified. Could you please review if the following is the required deliverable for this issue or if I have understood it wrong?
const express = require('express');
const router = express.Router();
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/BatchDB', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
const BatchSchema = new mongoose.Schema({
id: { type: Number, required: true },
name: { type: String, required: true },
});
const Batch = mongoose.model('Batch', BatchSchema);
router.post('/post/batches', async (req, res) => {
try {
const batchData = req.body;
const { error } = validateBatchRequest(batchData);
if (error) {
res.status(400).json({ error: error.details[0].message });
return;
}
const newBatch = new Batch(batchData);
await newBatch.save();
const response = {
message: 'Batch submitted successfully',
};
res.status(200).json(response);
}
catch (error) {
console.error('Error submitting batch:', error);
res.status(500).json({ error: 'Internal Server Error' });
}
});
const validateBatchRequest = (batchData) => {
const schema = Joi.object({
id: Joi.number().integer().positive().required(),
name: Joi.string().required(),
});
return schema.validate(batchData);
};
module.exports = router;
Hey @Swatishree-Mahapatra you're on right track , we need to do something similar. Some points:
Batch
inside of prisma service.post
in url, just /batches
will work.Also, it's better if we have a PR, we can discuss there, as it's more suitable place for these discussions :)
We need a
POST
/batches
API for creating batch jobs.Here is the spec for it: https://gist.github.com/AnshulMalik/513723d253ea5ef4ff37795da1dde4f1