Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new-features #6

Open
wants to merge 27 commits into
base: correct
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .env

This file was deleted.

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
.env
node_modules

Empty file removed Client/file
Empty file.
171 changes: 160 additions & 11 deletions Controllers/AdminController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,58 @@ const path = require('path')
const stream = require('stream')
const fs = require('fs')


exports.updateUserBySuperAdmin = async (req, res, next) => {
const { id } = req.params

const {is_admin}=req.body
const queryObject = {
text: queries.updateIsAdminType,
values: [is_admin, id]
}

try {
const { rowCount } = await db.query(queryObject)
if (rowCount === 0) {
return res.status(400).json({
status: 'failure',
code: 400,
message: "user id not found"
})
}
if (rowCount > 0) {
return res.status(200).json({
status: 'success',
code: 200,
message: "user admin type updated successfully"
})
}
} catch (error) {
res.status(400).json({
status: 'failure',
code: 400,
message: error.message
})
}
}


exports.createApplicationAdmin = async (req, res) => {
const date = new Date();
const created_at = moment(date).format('YYYY-MM-DD HH:mm:ss');
const { link, application_closure_date, batch_id, instructions } = req.body
const files = req.files.file_upload
console.log(req.files)
fileName = files.name
files.mv('uploadfile/' + fileName, (err) => {
if (err) {
console.log('Could Not Upload Image');
}
else {
console.log(fileName)
}
console.log()
files.mv('uploadingfile/' + fileName, (error) => {
if (error) {
res.status(500).json({
status: 'error',
code: 99,
message: "Request Processing Error",
error: error.message
}) }
})
if (!link || !application_closure_date || !batch_id || !instructions) {
return res.status(400).json({
Expand All @@ -43,10 +82,16 @@ exports.createApplicationAdmin = async (req, res) => {
res.status(201).json({ message: "Application submitted ", dbresponse })
}
} catch (error) {
console.log(error)
}
res.status(500).json({
status: 'error',
code: 99,
message: "Request Processing Error",
error: error.message
}) }
}



exports.updateUserToAdmin = async (req, res)=>{
const {id} =req.params
const {is_admin}= req.body;
Expand Down Expand Up @@ -87,10 +132,114 @@ exports.updateUserToAdmin = async (req, res)=>{
});

} catch (error) {
console.log(error);

res.status(500).json({
status: 'error',
code: 99,
message: "Request Processing Error",
error: error.message
})
}

}

exports.composeAssessmentAdmin = async (req, res) => {

const{ batch_id} = req.body
const date = new Date();
const created_at = moment(date).format('YYYY-MM-DD');
const y = req.body.question;
console.log("here: "+y)
const ray=JSON.parse(y);
console.log("ray here: "+ray)

for (let prop in ray) {
queryObject = {
text: queries.composeAssessmentQuery,
values: [ray[prop].question, ray[prop].option_a, ray[prop].option_b, ray[prop].option_c, ray[prop].option_d, ray[prop].correct_answer,created_at, batch_id]
};
try {
const{rowCount,rows}= await db.query(queryObject)
result = rows[0]
res.status(201).json({
status: 'success',
code: 201,
message: "assessment Created Successfully",
result
})
} catch (error) {
res.status(500).json({
status: 'error',
code: 99,
message: "Request Processing Error",
error: error.message
})
}
}
}

exports.getAllAssessmentUser = async (req, res) => {
const queryObject = {
text: queries.getAllAssessment
}
try {
const { rows, rowCount } = await db.query(queryObject)
if (rowCount > 0) {
return res.status(200).json({ data: rows })
}
if (rowCount === 0) {
return res.status(400).json({ message: "Assessment" })
}
}
catch (error) {
res.status(500).json({
status: 'error',
code: 99,
message: "Request Processing Error",
error: error.message
})
}
}

exports.uploadfileSetTime = async (req, res)=>{
const files = req.files.file_upload
fileName = files.name
files.mv('uploadFile/' + fileName, (error) => {
if (error) {
res.status(500).json({
status: 'error',
code: 99,
message: "Request Processing Error",
error: error.message
}) }

})
const {set_time }= req.body
const queryObject={
text: queries.uploadtime,
values:[
file_upload,
set_time
]
}

try {
const { rowCount, rows } = await db.query(queryObject)
const dbresponse = rows[0]
if (rowCount === 0) {
res.status(400).json({ message: "Time and file not uploaded" })
}
if (rowCount > 0) {
res.status(201).json({ message: "success uploading file ", dbresponse })
}
} catch (error) {
res.status(500).json({
status: 'error',
code: 99,
message: "Request Processing Error",
error: error.message
}) }

}



Loading