Add in a few null checks

These were discovered by using a project that was messed up with the moving
folder bug where the folder ended up without an id, docs or fileRefs array
This commit is contained in:
James Allen 2016-03-23 10:54:36 +00:00
parent 9706585d21
commit 3d8ac9f292
3 changed files with 13 additions and 11 deletions

View file

@ -46,12 +46,12 @@ module.exports = ProjectEditorHandler =
signUpDate : user.signUpDate
buildFolderModelView: (folder) ->
fileRefs = _.filter folder.fileRefs, (file)-> file?
fileRefs = _.filter (folder.fileRefs or []), (file)-> file?
_id : folder._id
name : folder.name
folders : @buildFolderModelView childFolder for childFolder in folder.folders
folders : @buildFolderModelView childFolder for childFolder in (folder.folders or [])
fileRefs : @buildFileModelView file for file in fileRefs
docs : @buildDocModelView doc for doc in folder.docs
docs : @buildDocModelView doc for doc in (folder.docs or [])
buildFileModelView: (file) ->
_id : file._id

View file

@ -22,7 +22,9 @@ module.exports = ProjectEntityHandler =
folders = {}
processFolder = (basePath, folder) ->
folders[basePath] = folder
processFolder path.join(basePath, childFolder.name), childFolder for childFolder in folder.folders
for childFolder in (folder.folders or [])
if childFolder.name?
processFolder path.join(basePath, childFolder.name), childFolder
ProjectGetter.getProjectWithoutDocLines project_id, (err, project) ->
return callback(err) if err?
@ -43,11 +45,11 @@ module.exports = ProjectEntityHandler =
for docContent in docContentsArray
docContents[docContent._id] = docContent
ProjectEntityHandler.getAllFolders project_id, (error, folders) ->
ProjectEntityHandler.getAllFolders project_id, (error, folders = {}) ->
return callback(error) if error?
docs = {}
for folderPath, folder of folders
for doc in folder.docs
for doc in (folder.docs or [])
content = docContents[doc._id.toString()]
if content?
docs[path.join(folderPath, doc.name)] = {
@ -61,11 +63,11 @@ module.exports = ProjectEntityHandler =
getAllFiles: (project_id, callback) ->
logger.log project_id:project_id, "getting all files for project"
@getAllFolders project_id, (err, folders) ->
@getAllFolders project_id, (err, folders = {}) ->
return callback(err) if err?
files = {}
for folderPath, folder of folders
for file in folder.fileRefs
for file in (folder.fileRefs or [])
if file?
files[path.join(folderPath, file.name)] = file
callback null, files

View file

@ -20,13 +20,13 @@ module.exports = ReferencesHandler =
ids = []
_process = (folder) ->
folder.docs.forEach (doc) ->
(folder.docs or []).forEach (doc) ->
if doc?.name?.match(/^.*\.bib$/)
ids.push(doc._id)
folder.folders.forEach (folder) ->
(folder.folders or []).forEach (folder) ->
_process(folder)
project.rootFolder.forEach (rootFolder) ->
(project.rootFolder or []).forEach (rootFolder) ->
_process(rootFolder)
return ids