Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.post('/add', async (req, res) => {
- try {
- const allPic = [];
- const Allfile = req.files.file;
- Allfile.forEach(async file=>
- {
- allPic.push(file.name);
- console.log(file.name);
- })
- Allfile.forEach(async file=>
- {
- await file.mv(`${__dirname.replace('routeHandler','')}images/${file.name}`);
- })
- //await file.mv(`${__dirname.replace('routeHandler','')}images/${file.name}`);
- req.body.pic= allPic;
- console.log(allPic)
- // return res.status(200).json({
- // insertCount: true,
- // message: "Successfully Inserted",
- // });
- console.log(req.body);
- req.body.category = {
- id : req.body.categoryId,
- title: req.body.categoryTitle
- }
- console.log(req.body);
- const newProduct = new Product(req.body);
- const product = await newProduct.save()
- await Category.updateOne({
- _id : req.body.category.id
- },
- {
- $push : {
- products : product.id
- }
- })
- return res.status(200).json({
- insertCount: true,
- message: "Successfully Inserted",
- }
- )
- }
- catch (err) {
- res.status(500).json({
- insertCount: false,
- error: 'There was a server site error',
- })
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement