check for duplicates in addFolder

This commit is contained in:
Brian Gough 2018-01-19 12:02:04 +00:00
parent b537747ccd
commit c6cca79737

View file

@ -341,7 +341,7 @@ module.exports = ProjectEntityHandler =
callback(null, folders, lastFolder)
addFolder: (project_id, parentFolder_id, folderName, callback) ->
ProjectGetter.getProjectWithOnlyFolders project_id, (err, project)=>
ProjectGetter.getProject project_id, {}, (err, project)=>
if err?
logger.err project_id:project_id, err:err, "error getting project for add folder"
return callback(err)
@ -459,11 +459,14 @@ module.exports = ProjectEntityHandler =
return callback(error) if error?
projectLocator.findElement {project:project, element_id:entity_id, type:entityType}, (error, entity, entPath)=>
return callback(error) if error?
ProjectEntityHandler.checkElementName entity, newName, (err) =>
return callback(err) if err?
endPath = path.join(path.dirname(entPath.fileSystem), newName)
conditions = {_id:project_id}
update = "$set":{}
namePath = entPath.mongo+".name"
update["$set"][namePath] = newName
# FIXME check if this would create a duplicate file!
tpdsUpdateSender.moveEntity({project_id:project_id, startPath:entPath.fileSystem, endPath:endPath, project_name:project.name, rev:entity.rev})
Project.findOneAndUpdate conditions, update, { "new": true}, (error, newProject) ->
return callback(error) if error?