forked from FoundKeyGang/FoundKey
/drive/files/update - return collectly value
This commit is contained in:
parent
d5cc4cc9c2
commit
3be69a8cb7
1 changed files with 9 additions and 8 deletions
|
@ -31,12 +31,10 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
return rej('file-not-found');
|
return rej('file-not-found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateQuery: any = {};
|
|
||||||
|
|
||||||
// Get 'name' parameter
|
// Get 'name' parameter
|
||||||
const [name, nameErr] = $(params.name).optional.string().pipe(validateFileName).$;
|
const [name, nameErr] = $(params.name).optional.string().pipe(validateFileName).$;
|
||||||
if (nameErr) return rej('invalid name param');
|
if (nameErr) return rej('invalid name param');
|
||||||
if (name) updateQuery['metadata.name'] = name;
|
if (name) file.metadata.name = name;
|
||||||
|
|
||||||
// Get 'folder_id' parameter
|
// Get 'folder_id' parameter
|
||||||
const [folderId, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
const [folderId, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
||||||
|
@ -44,7 +42,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
if (folderId !== undefined) {
|
if (folderId !== undefined) {
|
||||||
if (folderId === null) {
|
if (folderId === null) {
|
||||||
updateQuery['metadata.folder_id'] = null;
|
file.metadata.folder_id = null;
|
||||||
} else {
|
} else {
|
||||||
// Fetch folder
|
// Fetch folder
|
||||||
const folder = await DriveFolder
|
const folder = await DriveFolder
|
||||||
|
@ -57,16 +55,19 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
return rej('folder-not-found');
|
return rej('folder-not-found');
|
||||||
}
|
}
|
||||||
|
|
||||||
updateQuery['metadata.folder_id'] = folder._id;
|
file.metadata.folder_id = folder._id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const updated = await DriveFile.update(file._id, {
|
await DriveFile.update(file._id, {
|
||||||
$set: { updateQuery }
|
$set: {
|
||||||
|
'metadata.name': file.metadata.name,
|
||||||
|
'metadata.folder_id': file.metadata.folder_id
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
const fileObj = await serialize(updated);
|
const fileObj = await serialize(file);
|
||||||
|
|
||||||
// Response
|
// Response
|
||||||
res(fileObj);
|
res(fileObj);
|
||||||
|
|
Loading…
Reference in a new issue