いい感じにした

This commit is contained in:
syuilo 2017-02-13 01:49:17 +09:00
parent 30ad071575
commit 15fff96224
8 changed files with 32 additions and 23 deletions

View file

@ -41,7 +41,7 @@ module.exports = (params, user, app) =>
// Get 'folder_id' parameter
let folder = params.folder_id;
if (folder === undefined || folder === null || folder === 'null') {
if (folder === undefined || folder === null) {
folder = null;
} else {
folder = new mongo.ObjectID(folder);

View file

@ -46,7 +46,7 @@ module.exports = (file, params, user) =>
// Get 'folder_id' parameter
let folder = params.folder_id;
if (folder === undefined || folder === null || folder === 'null') {
if (folder === undefined || folder === null) {
folder = null;
} else {
folder = new mongo.ObjectID(folder);

View file

@ -25,7 +25,7 @@ module.exports = (params, user) =>
// Get 'folder_id' parameter
let folder = params.folder_id;
if (folder === undefined || folder === null || folder === 'null') {
if (folder === undefined || folder === null) {
folder = null;
} else {
folder = new mongo.ObjectID(folder);

View file

@ -58,16 +58,18 @@ module.exports = (params, user) =>
// Get 'folder_id' parameter
let folderId = params.folder_id;
if (folderId !== undefined && folderId !== 'null') {
folderId = new mongo.ObjectID(folderId);
}
let folder = null;
if (folderId !== undefined && folderId !== null) {
if (folderId === 'null') {
if (folderId !== undefined) {
if (folderId === null) {
file.folder_id = null;
} else {
folder = await DriveFolder
// Validate id
if (!mongo.ObjectID.isValid(folderId)) {
return rej('incorrect folder_id');
}
folderId = new mongo.ObjectID(folderId);
const folder = await DriveFolder
.findOne({
_id: folderId,
user_id: user._id

View file

@ -41,7 +41,7 @@ module.exports = (params, user, app) =>
// Get 'folder_id' parameter
let folder = params.folder_id;
if (folder === undefined || folder === null || folder === 'null') {
if (folder === undefined || folder === null) {
folder = null;
} else {
folder = new mongo.ObjectID(folder);

View file

@ -25,7 +25,7 @@ module.exports = (params, user) =>
// Get 'parent_id' parameter
let parentId = params.parent_id;
if (parentId === undefined || parentId === null || parentId === 'null') {
if (parentId === undefined || parentId === null) {
parentId = null;
} else {
parentId = new mongo.ObjectID(parentId);

View file

@ -25,6 +25,11 @@ module.exports = (params, user) =>
return rej('folder_id is required');
}
// Validate id
if (!mongo.ObjectID.isValid(folderId)) {
return rej('incorrect folder_id');
}
// Fetch folder
const folder = await DriveFolder
.findOne({
@ -49,17 +54,19 @@ module.exports = (params, user) =>
// Get 'parent_id' parameter
let parentId = params.parent_id;
if (parentId !== undefined && parentId !== 'null') {
parentId = new mongo.ObjectID(parentId);
}
let parent = null;
if (parentId !== undefined && parentId !== null) {
if (parentId === 'null') {
if (parentId !== undefined) {
if (parentId === null) {
folder.parent_id = null;
} else {
// Validate id
if (!mongo.ObjectID.isValid(parentId)) {
return rej('incorrect parent_id');
}
parentId = new mongo.ObjectID(parentId);
// Get parent folder
parent = await DriveFolder
const parent = await DriveFolder
.findOne({
_id: parentId,
user_id: user._id

View file

@ -407,7 +407,7 @@
@remove-file file
@api \drive/files/update do
file_id: file
folder_id: if @folder? then @folder.id else \null
folder_id: if @folder? then @folder.id else null
.then ~>
# something
.catch (err, text-status) ~>
@ -424,7 +424,7 @@
@remove-folder folder
@api \drive/folders/update do
folder_id: folder
parent_id: if @folder? then @folder.id else \null
parent_id: if @folder? then @folder.id else null
.then ~>
# something
.catch (err) ~>