approve add

This commit is contained in:
pawan-dot 2022-07-15 16:45:57 +05:30
parent 4dda59034a
commit 4057f8b6a0
429 changed files with 54 additions and 9 deletions

2
app.js
View File

@ -16,8 +16,6 @@ app.use(cookieParser());
app.use(cors()) app.use(cors())
app.use(express.json()) app.use(express.json())
app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.urlencoded({ extended: true }));
//express file upload
app.use(fileUpload({ app.use(fileUpload({
useTempFiles: true useTempFiles: true
})); }));

View File

@ -11,14 +11,14 @@ export const createRequirement = async (req, res) => {
// console.log(typeof Allfiles.tempFilePath) // console.log(typeof Allfiles.tempFilePath)
if (typeof Allfiles.tempFilePath === "string") { if (typeof Allfiles.tempFilePath === "string") {
let filepath = Allfiles.tempFilePath; let filepath = Allfiles.tempFilePath;
// console.log(filepath)
images.push(filepath) images.push(filepath)
} else { } else {
Allfiles.map(item => { Allfiles.map(item => {
images.push(item.tempFilePath); images.push(item.tempFilePath);
}) })
} }
// console.log(images.length)
const imagesLinks = []; const imagesLinks = [];
for (let i = 0; i < images.length; i++) { for (let i = 0; i < images.length; i++) {
const result = await cloudinary.v2.uploader.upload(images[i], { const result = await cloudinary.v2.uploader.upload(images[i], {
@ -35,6 +35,16 @@ export const createRequirement = async (req, res) => {
req.body.image = imagesLinks; req.body.image = imagesLinks;
req.body.addedBy = req.user.id; req.body.addedBy = req.user.id;
// if (req.user.role === "admin"){
// req.body.approved=true
// }
// else{
// req.body.approved = false
// }
req.body.approved = (req.user.role === "admin" ? true : false);
const Requirement = await RequirementModel.create(req.body); const Requirement = await RequirementModel.create(req.body);
res.status(201).json({ res.status(201).json({
success: true, success: true,
@ -42,6 +52,7 @@ export const createRequirement = async (req, res) => {
Requirement, Requirement,
}); });
} catch (error) { } catch (error) {
// console.log(error)
res.status(500).json({ res.status(500).json({
success: false, success: false,
msg: "Failled to create !!" msg: "Failled to create !!"
@ -189,3 +200,34 @@ export const deleteOneRequirement = async (req, res) => {
} }
}; };
//
//Approved(admin)
export const Approved = async (req, res) => {
try {
const Requirement = await RequirementModel.findById(req.params.id);
if (Requirement.approved === false) {
Requirement.approved = true
Requirement.save()
} else {
res.status(500).json({
success: false,
msg: " already Approved",
});
}
res.status(200).json({
success: true,
msg: " Approved Successfully!!",
Requirement,
});
} catch (error) {
console.log(error)
res.status(500).json({
success: false,
msg: "Failled to Approved !!"
});
}
};

View File

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

View File

@ -56,7 +56,7 @@ export const createDirectory = async (req, res) => {
data, data,
}); });
} catch (error) { } catch (error) {
//console.log(error) console.log(error)
res.status(500).json({ res.status(500).json({
success: false, success: false,
msg: "Failled to create !!" msg: "Failled to create !!"

View File

@ -33,6 +33,10 @@ const RequirementSchema = new mongoose.Schema(
ref: "User", ref: "User",
required: true, required: true,
}, },
approved: {
type: Boolean,
default: false,
},
}, { timestamps: true } }, { timestamps: true }
); );

View File

@ -12,7 +12,6 @@ const directorySchema = new mongoose.Schema(
email: { email: {
type: String, type: String,
required: true, required: true,
// unique: true
}, },
image: image:
{ {

View File

@ -4,7 +4,8 @@ import {
getAllRequirement, getAllRequirement,
getOneRequirement, getOneRequirement,
updateRequirement, updateRequirement,
deleteOneRequirement deleteOneRequirement,
Approved
} from "../controllers/RequirementController.js" } from "../controllers/RequirementController.js"
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js" import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
const router = express.Router(); const router = express.Router();
@ -14,4 +15,7 @@ router.route("/requirement/getAll/").get(isAuthenticatedUser, getAllRequirement)
router.route("/requirement/getOne/:id").get(isAuthenticatedUser, getOneRequirement) router.route("/requirement/getOne/:id").get(isAuthenticatedUser, getOneRequirement)
router.route("/requirement/update/:id").put(isAuthenticatedUser, updateRequirement); router.route("/requirement/update/:id").put(isAuthenticatedUser, updateRequirement);
router.route("/requirement/delete/:id").delete(isAuthenticatedUser, deleteOneRequirement); router.route("/requirement/delete/:id").delete(isAuthenticatedUser, deleteOneRequirement);
//admin
router.route("/admin/requirement/approve/:id").get(isAuthenticatedUser, authorizeRoles("admin"), Approved);
export default router; export default router;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 620 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 290 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 290 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 620 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 620 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 620 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 318 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

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