ドライブのファイルの削除を実装

This commit is contained in:
syuilo 2018-06-15 09:53:30 +09:00
parent ad8aa1c179
commit bd827f946a
8 changed files with 98 additions and 39 deletions

View file

@ -0,0 +1,32 @@
import $ from 'cafy'; import ID from '../../../../../cafy-id';
import DriveFile from '../../../../../models/drive-file';
import del from '../../../../../services/drive/delete-file';
import { publishDriveStream } from '../../../../../publishers/stream';
/**
* Delete a file
*/
module.exports = async (params, user) => {
// Get 'fileId' parameter
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
if (fileIdErr) throw 'invalid fileId param';
// Fetch file
const file = await DriveFile
.findOne({
_id: fileId,
'metadata.userId': user._id
});
if (file === null) {
throw 'file-not-found';
}
// Delete
await del(file);
// Publish file_deleted event
publishDriveStream(user._id, 'file_deleted', file._id);
return;
};