approve add
2
app.js
@ -16,8 +16,6 @@ app.use(cookieParser());
|
||||
app.use(cors())
|
||||
app.use(express.json())
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
//express file upload
|
||||
app.use(fileUpload({
|
||||
useTempFiles: true
|
||||
}));
|
||||
|
@ -11,14 +11,14 @@ export const createRequirement = async (req, res) => {
|
||||
// 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], {
|
||||
@ -35,6 +35,16 @@ export const createRequirement = async (req, res) => {
|
||||
req.body.image = imagesLinks;
|
||||
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);
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
@ -42,6 +52,7 @@ export const createRequirement = async (req, res) => {
|
||||
Requirement,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
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 !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
@ -7,8 +7,6 @@ export const createBanner = async (req, res) => {
|
||||
|
||||
try {
|
||||
const files = req.files.image;
|
||||
|
||||
|
||||
// console.log(files)
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "cmp/image",
|
||||
|
@ -56,7 +56,7 @@ export const createDirectory = async (req, res) => {
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
//console.log(error)
|
||||
console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to create !!"
|
||||
|
@ -33,6 +33,10 @@ const RequirementSchema = new mongoose.Schema(
|
||||
ref: "User",
|
||||
required: true,
|
||||
},
|
||||
approved: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
|
||||
}, { timestamps: true }
|
||||
);
|
||||
|
@ -12,7 +12,6 @@ const directorySchema = new mongoose.Schema(
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
// unique: true
|
||||
},
|
||||
image:
|
||||
{
|
||||
|
@ -4,7 +4,8 @@ import {
|
||||
getAllRequirement,
|
||||
getOneRequirement,
|
||||
updateRequirement,
|
||||
deleteOneRequirement
|
||||
deleteOneRequirement,
|
||||
Approved
|
||||
} from "../controllers/RequirementController.js"
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
|
||||
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/update/:id").put(isAuthenticatedUser, updateRequirement);
|
||||
router.route("/requirement/delete/:id").delete(isAuthenticatedUser, deleteOneRequirement);
|
||||
|
||||
//admin
|
||||
router.route("/admin/requirement/approve/:id").get(isAuthenticatedUser, authorizeRoles("admin"), Approved);
|
||||
export default router;
|
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 290 KiB |
Before Width: | Height: | Size: 290 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 318 KiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 1.1 MiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |