started move folder fixes

This commit is contained in:
subnub
2024-07-17 21:49:29 -04:00
parent 6a137858bf
commit 7d23910fd5
5 changed files with 34 additions and 29 deletions
+2 -2
View File
@@ -729,9 +729,9 @@ class FileController {
try {
const fileID = req.body.id;
const userID = req.user._id;
const parentID = req.body.parent;
const folderID = req.body.parentID;
await fileService.moveFile(userID, fileID, parentID);
await fileService.moveFile(userID, fileID, folderID);
res.send();
} catch (e: unknown) {
+2 -1
View File
@@ -188,7 +188,8 @@ class DbUtil {
"metadata.parent": parent,
"metadata.parentList": parentList,
},
}
},
{ new: true }
);
return file;
+20 -25
View File
@@ -38,8 +38,7 @@ class MongoFileService {
removeLink = async (userID: string, fileID: string) => {
const file = await dbUtilsFile.removeLink(fileID, userID);
if (!file.lastErrorObject.updatedExisting)
throw new NotFoundError("Remove Link File Not Found Error");
if (!file) throw new NotFoundError("Remove Link File Not Found Error");
};
makePublic = async (userID: string, fileID: string) => {
@@ -47,17 +46,13 @@ class MongoFileService {
const file = await dbUtilsFile.makePublic(fileID, userID, token);
if (!file.lastErrorObject.updatedExisting)
throw new NotFoundError("Make Public File Not Found Error");
if (!file) throw new NotFoundError("Make Public File Not Found Error");
return token;
};
getPublicInfo = async (fileID: string, tempToken: string) => {
const file: FileInterface = await dbUtilsFile.getPublicInfo(
fileID,
tempToken
);
const file = await dbUtilsFile.getPublicInfo(fileID, tempToken);
if (!file || !file.metadata.link || file.metadata.link !== tempToken) {
throw new NotFoundError("Public Info Not Found");
@@ -71,8 +66,7 @@ class MongoFileService {
const file = await dbUtilsFile.makeOneTimePublic(fileID, userID, token);
if (!file.lastErrorObject.updatedExisting)
throw new NotFoundError("Make One Time Public Not Found Error");
if (!file) throw new NotFoundError("Make One Time Public Not Found Error");
return token;
};
@@ -319,28 +313,29 @@ class MongoFileService {
return file;
};
moveFile = async (userID: string, fileID: string, parentID: string) => {
let parentList = ["/"];
moveFile = async (userID: string, fileID: string, folderID: string) => {
const file = await dbUtilsFile.getFileInfo(fileID, userID);
if (parentID.length !== 1) {
const parentFile = await dbUtilsFolder.getFolderInfo(parentID, userID);
if (!parentFile)
throw new NotFoundError("Rename Parent File Not Found Error");
const parentList = parentFile.parentList;
parentList.push(parentID);
}
if (!file) throw new NotFoundError("Move File Not Found Error");
const file = await dbUtilsFile.moveFile(
const folder = await dbUtilsFolder.getFolderInfo(folderID, userID);
if (!folder) throw new NotFoundError("Move Folder Not Found Error");
const newParentList = [...folder.parentList, folder._id];
const updatedFile = await dbUtilsFile.moveFile(
fileID,
userID,
parentID,
parentList.toString()
folderID,
newParentList.toString()
);
if (!file || !file.lastErrorObject.updatedExisting)
throw new NotFoundError("Rename File Not Found Error");
if (!updatedFile) {
throw new NotFoundError("Move Updated File Not Found Error");
}
return file;
return updatedFile;
};
}
+10
View File
@@ -219,6 +219,16 @@ class FolderService {
await utilsFile.restoreFilesByParent(parentList.toString(), userID);
};
renameFolder2 = async (folderID: string, userID: string, title: string) => {
const folder = await utilsFolder.getFolderInfo(folderID, userID);
if (!folder) throw new NotFoundError("Rename Folder Not Found");
folder.name = title;
await folder.save();
};
moveFolder = async (userID: string, folderID: string, parentID: string) => {
let parentList = ["/"];
-1
View File
@@ -5,7 +5,6 @@ import { useFolder } from "../../hooks/folders";
const ParentBar = memo(() => {
const { data: folder } = useFolder();
console.log("folder", folder);
const navigate = useNavigate();
const { isHome, isTrash } = useUtils();