Skip to content

Commit

Permalink
url with no parameters in user group, remove all console logs, moving…
Browse files Browse the repository at this point in the history
… the user group component to the user action engine #383
  • Loading branch information
Omnia Kahla authored and Omnia Kahla committed Sep 17, 2020
1 parent 687a85e commit 4ec5445
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 137 deletions.
76 changes: 23 additions & 53 deletions backend/routes/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@ if(arrayOfItems.length ==0){
}

for (let i = 0; i < arrayOfItems.length; i++) {
console.log(arrayOfItems[i]._id);
console.log(itemToSearch._id);

if (arrayOfItems[i]._id.toString() == itemToSearch._id.toString()) {
console.log(i);

return i;
}
}
Expand All @@ -148,18 +147,18 @@ function addFiles(req, res,oldHostUrl, newHostUrl) {
let filesJsonExported = JSON.parse(JSON.parse(JSON.stringify(req.body.filesJson.split(oldHostUrl).join(newHostUrl))));

let projectFiles = req.body.projectFiles;
console.log('req.body.projectFiles');
//console.log('req.body.projectFiles');
//console.log(req.body.projectFiles);

let newFiles = filesJsonExported.slice();
console.log(newFiles);
///console.log(newFiles);
let filesIndices = [];
if (projectFiles.length != 0 || filesJsonExported) {
filesJsonExported.forEach(file => {
filesIndices.push(file._id);
});
Files.find({_id: {$in: filesIndices}}).then(foundFiles => {
console.log("foundFiles " + foundFiles);
//console.log("foundFiles " + foundFiles);
foundFiles.forEach(item => {
let index = searchItemInArray(item, newFiles);
if (index != -1) {
Expand All @@ -168,12 +167,12 @@ function addFiles(req, res,oldHostUrl, newHostUrl) {
});
if (newFiles.length != 0) {
Files.insertMany(newFiles, {ordered: false}).then(filesInserted => {
console.log("files inserted");
console.log(filesInserted);
// console.log("files inserted");
// console.log(filesInserted);
let counter = projectFiles.length;
projectFiles.forEach(file => {
let path = 'backend/files/' + file.fileName;
console.log(path);
//console.log(path);
//console.log(file.fileContent);
//const data = new Uint8Array(Buffer.from(file.fileContent));
var buf = new Buffer(file.fileContent, 'binary'); //base64
Expand All @@ -185,7 +184,7 @@ function addFiles(req, res,oldHostUrl, newHostUrl) {
error: err
});
}
console.log(file.fileName + "has been added to the server");
// console.log(file.fileName + "has been added to the server");
counter--;
});
});
Expand Down Expand Up @@ -213,34 +212,23 @@ function addFiles(req, res,oldHostUrl, newHostUrl) {
}

function addFolders(req, res,oldHostUrl,newHostUrl) {
console.log("add Folders started");
if(req.body.foldersJson) {


let foldersJsonExported = JSON.parse(JSON.parse(JSON.stringify(req.body.foldersJson)));
let newFolders = foldersJsonExported.slice();
console.log("newFolders");
console.log(newFolders);
let folderIndices = [];
if (foldersJsonExported) {
foldersJsonExported.forEach(folder => {
folderIndices.push(folder._id);
});
Folder.find({_id: {$in: folderIndices}}).then(foundFolders => {
console.log("foundFolders");
console.log(foundFolders);
foundFolders.forEach(item => {
let index = searchItemInArray(item, newFolders);
if (index != -1) {
newFolders.splice(index, 1);
}
});
if (newFolders && newFolders.length > 0) {
console.log("newFolders");
console.log(newFolders);
Folder.insertMany(newFolders, {ordered: false}).then(foldersResults => {
console.log("folders inserted");
console.log(foldersResults);
addFiles(req, res, oldHostUrl, newHostUrl);
}).catch(foundFoldersError => {
res.status(500).json({
Expand All @@ -253,7 +241,6 @@ function addFolders(req, res,oldHostUrl,newHostUrl) {
}

}).catch(foldersError => {
// tempError=true;
res.status(500).json({
message: 'Something happened while Searching for the Folders',
error: foldersError
Expand All @@ -262,19 +249,16 @@ function addFolders(req, res,oldHostUrl,newHostUrl) {
}
}
else{
console.log( "The project has no Folders");
addFiles(req, res, oldHostUrl, newHostUrl);
}

}

function addMyOwnJsons(req, res, oldHostUrl, newHostUrl) {
console.log("start addMyOwnJson");
if(req.body.jsonQueries) {


let myOwnJsonExported = JSON.parse(JSON.parse(JSON.stringify(req.body.jsonQueries.split(oldHostUrl).join(newHostUrl))));
console.log(myOwnJsonExported);
let newMyOwnJsons = myOwnJsonExported.slice();
let myOwnJsonIndices = [];
if (myOwnJsonExported) {
Expand All @@ -287,14 +271,11 @@ if(req.body.jsonQueries) {
let index = searchItemInArray(item, newMyOwnJsons);
if (index != -1) {
newMyOwnJsons.splice(index, 1);
console.log(newMyOwnJsons);
}
});
if (newMyOwnJsons && newMyOwnJsons.length > 0) {
console.log("start inserting myOwnJsons");
console.log(newMyOwnJsons);

MyOwnJSON.insertMany(newMyOwnJsons, {ordered: false}).then(jsonsInserted => {
console.log("my Json inserted successfully ");

addFolders(req, res, oldHostUrl, newHostUrl);
}).catch(jsonsInserted => {
Expand All @@ -304,7 +285,6 @@ if(req.body.jsonQueries) {
});
});
} else {
console.log("else in addMyOwnJson");
addFolders(req, res, oldHostUrl, newHostUrl);
}
}).catch(jsonsSearchError => {
Expand All @@ -315,13 +295,11 @@ if(req.body.jsonQueries) {
});
}
else{
console.log( "The project has no Jsons");
addFolders(req, res, oldHostUrl, newHostUrl);
}
}

function addQueries( req, res, oldHostUrl,newHostUrl) {
console.log("start adding the queries");
if(req.body.queries){
let queriesExported = JSON.parse(JSON.parse(JSON.stringify(req.body.queries.split(oldHostUrl).join(newHostUrl))));
let queriesIndices=[];
Expand All @@ -339,10 +317,7 @@ function addQueries( req, res, oldHostUrl,newHostUrl) {
}
});
if(newQueries && newQueries.length>0){
console.log("newQueries is not empty, insert them ");
console.log(newQueries);
Query.insertMany(newQueries, {ordered: false}).then(queriesInserted => {
console.log(queriesInserted);
addMyOwnJsons(req, res, oldHostUrl,newHostUrl);
}).catch(queriesInsertedError => {
res.status(500).json({
Expand All @@ -363,7 +338,6 @@ function addQueries( req, res, oldHostUrl,newHostUrl) {
});
}
else{
console.log( "The project has no queries");
addMyOwnJsons(req, res, oldHostUrl,newHostUrl);
}

Expand All @@ -372,7 +346,6 @@ function addQueries( req, res, oldHostUrl,newHostUrl) {
function addPages( req, res, oldHostUrl, newHostUrl) {
let pagesExported = JSON.parse(JSON.parse(JSON.stringify(req.body.pages.split(oldHostUrl).join(newHostUrl))));
Page.insertMany(pagesExported).then(pagesInserted => {
//console.log(pagesInserted);
addQueries(req, res, oldHostUrl, newHostUrl);
return res.status(201).json({
message: 'Project created successfully',
Expand All @@ -386,9 +359,8 @@ function addPages( req, res, oldHostUrl, newHostUrl) {
}

function addComments(req, res, oldHostUrl, newHostUrl) {
console.log("I am here in add comments");

if(req.body.comments){
//console.log(req.body.comments);
let commentsExported= JSON.parse(JSON.parse(JSON.stringify(req.body.comments.split(oldHostUrl).join(newHostUrl))));
let newComments = commentsExported.slice();
let commentsIndices=[];
Expand Down Expand Up @@ -422,17 +394,16 @@ function addComments(req, res, oldHostUrl, newHostUrl) {
}
}
else{
console.log("No Comments were found, start adding the pages");
addPages( req, res, oldHostUrl, newHostUrl);
}

}

router.post('/createProject/', checkAuth, (req, res, next) => {
//console.log(req.body);

let oldHostUrl = req.body.oldHostUrl;
let newHostUrl = req.protocol + "://" + req.get("host");
console.log(req.body.action);

let actionExported = new Action(JSON.parse(JSON.parse(JSON.stringify(req.body.action.split(oldHostUrl).join(newHostUrl)))));
let pageSetExported = new PageSet(JSON.parse(JSON.parse(JSON.stringify(req.body.pageSet.split(oldHostUrl).join(newHostUrl)))));
actionExported.save()
Expand Down Expand Up @@ -462,7 +433,7 @@ router.post('/createProject/', checkAuth, (req, res, next) => {
});

router.post('/reloadProject/', checkAuth, (req, res, next) => {
console.log(req.body.pageSetId);

let pageSet_id = req.body.pageSetId;
const newAction = new Action({
title: '',
Expand All @@ -473,41 +444,41 @@ router.post('/reloadProject/', checkAuth, (req, res, next) => {
deleted: false
});
PageSet.find({_id: pageSet_id}).then(pageSet => {
console.log(pageSet);

Page.findOne({_id: pageSet[0].hasPages[0]}).then(mainPage => {
console.log(mainPage);

newAction.title = mainPage.title;
newAction.description = mainPage.description;
newAction.hasPageSet = pageSet[0]._id;
newAction.hasPage = mainPage._id;
Page.find({_id: {$in: pageSet[0].hasPages}}).then(allPages => {
let queries = [];
if (allPages) {
console.log(allPages);

for (let i = 0; i < allPages.length; i++) {
allPages[i].queries.forEach(query => {
queries.push(query);
});
}
console.log(queries);

if (queries.length != 0) {
Query.find({_id: {$in: queries}}, {creator: 1}).then(creatorResults => {
console.log(creatorResults);

newAction.creator = creatorResults[0].creator;
newAction.save().then(newActionCreated => {
res.status(201).json({
message: 'Action created successfully',
action: newActionCreated
});
}).catch(newActionError => {
console.log(newActionError);

res.status(500).json({
message: 'Error while saving new Action',
error: newActionError
});
})
}).catch(creatorError => {
console.log(creatorError);

res.status(500).json({
message: 'Error retrieving Creator',
error: creatorError
Expand All @@ -516,21 +487,20 @@ router.post('/reloadProject/', checkAuth, (req, res, next) => {
}
}
}).catch(allPagesError => {
console.log(allPagesError);

res.status(500).json({
message: 'Error retrieving All Pages',
error: allPagesError
});
});
}).catch(mainPageError => {
console.log(mainPageError);
res.status(500).json({
message: 'Error retrieving main Page',
error: mainPageError
});
});
}).catch(pageSetErr => {
console.log(pageSetErr);

res.status(500).json({
message: 'Error retrieving PageSet',
error: pageSetErr
Expand Down
17 changes: 5 additions & 12 deletions backend/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,12 @@ router.get('/:email/reset-password', (req, res, next) => {
router.get('/:email/getUserByEmail', (req, res, next) => {
User.findOne({email: req.params.email})
.then(result => {
console.log(result);
res.status(201).json({
message: 'User Successfully found ',
user: result
});
})
.catch(err => {
console.log(err);
return res.status(401).json({
message: 'Did not find user'
});
Expand Down Expand Up @@ -497,9 +495,6 @@ router.get('/:id/queries', checkAuth, (req, res, next) => {
router.post('/signup/:newsLetter', multer({storage: storage}).single("file"), (req, res, next) => {
// Tests if email address is invalid
const emailPattern = /^\S+[@]\S+[.]\S+$/;
console.log(req.body);
console.log(req.param);
console.log(req);
if (!emailPattern.test(req.body.email)) {
return res.status(400).json({
message: 'Your email address is invalid!'
Expand All @@ -522,10 +517,9 @@ router.post('/signup/:newsLetter', multer({storage: storage}).single("file"), (r
.then(hashPwd => {
let filePath = req.body.usrProfileFilePath;
if (req.file) {
console.log("uploaded a file ");
console.log((req.file.filename));

filePath = req.body.host + "/assets/img/team/" + req.file.filename;
console.log(filePath);

}
const user = new User({
email: req.body.email,
Expand All @@ -537,7 +531,7 @@ router.post('/signup/:newsLetter', multer({storage: storage}).single("file"), (r
});
user.save()
.then(result => {
console.log(result);

res.status(201).json({
message: 'User was created',
result: result
Expand All @@ -559,7 +553,7 @@ router.post('/signup/:newsLetter', multer({storage: storage}).single("file"), (r

router.post('/login', (req, res, next) => {
let fetchedUser;
console.log('Login');

User.findOne({email: req.body.email})
.then(user => {
if (!user) {
Expand Down Expand Up @@ -598,7 +592,7 @@ router.post('/login', (req, res, next) => {
});
})
.catch(err => {
console.log(err);

return res.status(401).json({
message: 'Auth failed'
});
Expand All @@ -607,7 +601,6 @@ router.post('/login', (req, res, next) => {

router.post('/updateUsrProfilePic/:email', multer({storage: storage}).single("file"), (req, res, next) => {
let filePath = "";
console.log(" final file Path is " + filePath);
User.findOne({email: req.params.email}).then(userFound => {
if (req.file) {
filePath = req.body.hostname + "/assets/img/team/" + req.file.filename;
Expand Down
12 changes: 9 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4ec5445

Please sign in to comment.