いい感じにした

This commit is contained in:
syuilo 2017-02-13 01:49:17 +09:00
parent 3601494b9a
commit adb9e1c1c3
8 changed files with 32 additions and 23 deletions

View file

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

View file

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

View file

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

View file

@ -58,16 +58,18 @@ module.exports = (params, user) =>
// Get 'folder_id' parameter // Get 'folder_id' parameter
let folderId = params.folder_id; let folderId = params.folder_id;
if (folderId !== undefined && folderId !== 'null') { if (folderId !== undefined) {
folderId = new mongo.ObjectID(folderId); if (folderId === null) {
}
let folder = null;
if (folderId !== undefined && folderId !== null) {
if (folderId === 'null') {
file.folder_id = null; file.folder_id = null;
} else { } 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({ .findOne({
_id: folderId, _id: folderId,
user_id: user._id user_id: user._id

View file

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

View file

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

View file

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

View file

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