requirement add

This commit is contained in:
pawan-dot 2022-07-13 14:37:34 +05:30
parent 00dbd1b168
commit 4dda59034a
170 changed files with 254 additions and 2 deletions

4
app.js
View File

@ -49,4 +49,8 @@ app.use("/api", cmpRistriction);
//feedback //feedback
import feedback from "./routes/feedbackRoute.js" import feedback from "./routes/feedbackRoute.js"
app.use("/api", feedback); app.use("/api", feedback);
//feedback
import requirement from "./routes/RequirementRoute.js"
app.use("/api", requirement);
export default app; export default app;

View File

@ -8,7 +8,7 @@ export const createNews = async (req, res) => {
try { try {
const files = req.files.image; const files = req.files.image;
// console.log(files) console.log(files.tempFilePath)
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, { const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
folder: "cmp/News", folder: "cmp/News",
}, },

View File

@ -0,0 +1,191 @@
import RequirementModel from "../models/RequirementModel.js"
import cloudinary from "cloudinary";
// import cloudinary from "../Utils/cloudinary.js"
//import { v2 as cloudinary } from 'cloudinary'
export const createRequirement = async (req, res) => {
try {
let images = [];
let Allfiles = req.files.image;
// console.log(typeof Allfiles.tempFilePath)
if (typeof Allfiles.tempFilePath === "string") {
let filepath = Allfiles.tempFilePath;
// console.log(filepath)
images.push(filepath)
} else {
Allfiles.map(item => {
images.push(item.tempFilePath);
})
}
// console.log(images.length)
const imagesLinks = [];
for (let i = 0; i < images.length; i++) {
const result = await cloudinary.v2.uploader.upload(images[i], {
folder: "cmp",
});
imagesLinks.push({
public_id: result.public_id,
url: result.secure_url,
});
}
req.body.image = imagesLinks;
req.body.addedBy = req.user.id;
const Requirement = await RequirementModel.create(req.body);
res.status(201).json({
success: true,
msg: " create Requirement Successfully!!",
Requirement,
});
} catch (error) {
res.status(500).json({
success: false,
msg: "Failled to create !!"
});
}
};
//get All Requirement
export const getAllRequirement = async (req, res) => {
try {
const Requirement = await RequirementModel.find();
// console.log(news)
res.status(200).json({
success: true,
msg: " fetch Successfully!!",
Requirement,
});
} catch (error) {
res.status(500).json({
success: false,
msg: "Failled to fetch !!"
});
}
};
//get One Requirement
export const getOneRequirement = async (req, res) => {
try {
const Requirement = await RequirementModel.findById(req.params.id);
// console.log(news)
res.status(200).json({
success: true,
msg: " fetch Successfully!!",
Requirement,
});
} catch (error) {
// console.log(error)
res.status(500).json({
success: false,
msg: "Failled to fetch !!"
});
}
};
// 3.update Requirement
export const updateRequirement = async (req, res) => {
try {
const Requirement = await RequirementModel.findById(req.params.id);
if (!Requirement) {
return res.status(400).json({ message: 'Requirement Not Found' });
}
//handle image------------------------------------------------------------
let images = [];
let Allfiles = req.files.image;
// console.log(typeof Allfiles.tempFilePath)
if (typeof Allfiles.tempFilePath === "string") {
let filepath = Allfiles.tempFilePath;
// console.log(filepath)
images.push(filepath)
} else {
Allfiles.map(item => {
images.push(item.tempFilePath);
})
}
if (images !== undefined) {
// Deleting Images From Cloudinary
for (let i = 0; i < Requirement.image.length; i++) {
await cloudinary.v2.uploader.destroy(Requirement.image[i].public_id);
}
const imagesLinks = [];
for (let i = 0; i < images.length; i++) {
const result = await cloudinary.v2.uploader.upload(images[i], {
folder: "cmp",
});
imagesLinks.push({
public_id: result.public_id,
url: result.secure_url,
});
}
req.body.image = imagesLinks;
}
// ------------------------------------------------------------------------
const ModifyRequirement = await RequirementModel.findByIdAndUpdate(req.params.id, req.body,
{
new: true,
runValidators: true,
useFindAndModify: false
}
);
res.status(200).json({
success: true,
ModifyRequirement
});
} catch (error) {
// console.log(error)
res.status(500).json({
success: false,
msg: "Failled to UpDate !!"
});
}
};
//delete one Requirement
export const deleteOneRequirement = async (req, res) => {
try {
const findRequirement = await RequirementModel.findById(req.params.id);
if (!findRequirement) {
return res.status(400).json({ message: 'Requirement Not Found' });
}
// Deleting Images From Cloudinary
for (let i = 0; i < findRequirement.image.length; i++) {
await cloudinary.v2.uploader.destroy(findRequirement.image[i].public_id);
}
await findRequirement.remove();
res.status(200).json({
success: true,
msg: "Requirement Deleted Successfully!!",
// news,
});
} catch (error) {
res.status(500).json({
success: false,
msg: "Failled to Delete !!"
});
}
};

View File

@ -0,0 +1,40 @@
import mongoose from "mongoose"
const RequirementSchema = new mongoose.Schema(
{
title: {
type: String,
required: true
},
areaOfInterest: {
type: String,
required: true
},
image: [
{
public_id: {
type: String,
required: true,
},
url: {
type: String,
required: true,
},
},
],
description: {
type: String,
required: true
},
addedBy: {
type: mongoose.Schema.ObjectId,
ref: "User",
required: true,
},
}, { timestamps: true }
);
const RequirementModel = mongoose.model("Requirement", RequirementSchema);
export default RequirementModel;

View File

@ -0,0 +1,17 @@
import express from "express";
import {
createRequirement,
getAllRequirement,
getOneRequirement,
updateRequirement,
deleteOneRequirement
} from "../controllers/RequirementController.js"
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
const router = express.Router();
router.route("/requirement/create/").post(isAuthenticatedUser, createRequirement)
router.route("/requirement/getAll/").get(isAuthenticatedUser, getAllRequirement)
router.route("/requirement/getOne/:id").get(isAuthenticatedUser, getOneRequirement)
router.route("/requirement/update/:id").put(isAuthenticatedUser, updateRequirement);
router.route("/requirement/delete/:id").delete(isAuthenticatedUser, deleteOneRequirement);
export default router;

View File

@ -4,7 +4,7 @@ dotenv.config()
import app from "./app.js" import app from "./app.js"
import connectDatabase from "./database/db.js"; import connectDatabase from "./database/db.js";
import cloudinary from "cloudinary" import cloudinary from "cloudinary"
// const PORT = 5000;
// Connecting to database // Connecting to database
connectDatabase(); connectDatabase();

BIN
tmp/tmp-1-1657691541934 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657691823983 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657691932400 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657691961961 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657692044911 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657692073291 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657692156393 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657692270744 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657692521378 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

BIN
tmp/tmp-1-1657693506068 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657693804951 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657693969464 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657693993416 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657694204918 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657694244500 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657694320050 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657694351787 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657694406205 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657694710102 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657694808176 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657694874791 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657694912620 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657694941061 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657694991436 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657695033209 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657695228328 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657695348961 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657695478465 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
tmp/tmp-1-1657695634319 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
tmp/tmp-1-1657695672740 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
tmp/tmp-1-1657695842122 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
tmp/tmp-1-1657696047964 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657696083335 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657696141057 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657696164150 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657696330842 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657696420907 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657696477532 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657696567793 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657696610955 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657696751615 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657696838738 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657696859057 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657696892113 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657696962305 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657696998330 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697040619 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697066325 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697089774 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697108436 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697151150 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697202911 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697285947 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697368226 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697388226 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697426168 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697467436 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697504819 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697560611 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697838044 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697897004 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697940618 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657697985619 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657698155777 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657698193872 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657698618005 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657698675708 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657698708070 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657698860687 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657698924545 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657699013432 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657699115862 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657699252595 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1657699605267 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657699660055 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657699689974 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657699773929 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657700999405 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1657702223617 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
tmp/tmp-10-1657691629579 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-11-1657691629586 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
tmp/tmp-2-1657691541944 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
tmp/tmp-2-1657691823999 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
tmp/tmp-2-1657691932416 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
tmp/tmp-2-1657691961973 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
tmp/tmp-2-1657692044925 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
tmp/tmp-2-1657692073317 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
tmp/tmp-2-1657692156426 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
tmp/tmp-2-1657692270759 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
tmp/tmp-2-1657692577479 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-2-1657693506077 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-2-1657693804954 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
tmp/tmp-2-1657693969470 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
tmp/tmp-2-1657693993419 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Some files were not shown because too many files have changed in this diff Show More