aboutsummaryrefslogtreecommitdiff
path: root/src/files.ts
diff options
context:
space:
mode:
authorjw2552018-04-17 10:38:32 +0100
committerjw2552018-04-17 10:38:32 +0100
commit7905240ed1655f9db3f571976034e287d88e1315 (patch)
tree816b5839b4b5505b08371b00e982b820966f809a /src/files.ts
parentWorld War Files - ideas all there, but SQLize part still missing. (diff)
downloadmedicine-7905240ed1655f9db3f571976034e287d88e1315.tar.gz
medicine-7905240ed1655f9db3f571976034e287d88e1315.zip

World War Files - changed precondition + filled addSubFileToFolder() function. Need to test tho

Diffstat (limited to 'src/files.ts')
-rw-r--r--src/files.ts40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/files.ts b/src/files.ts
index 6572c53..a5fd08d 100644
--- a/src/files.ts
+++ b/src/files.ts
@@ -28,18 +28,6 @@ const readableStream: (filename: string, projectName: string, { offset, length }
};
return fs.createReadStream(path(filename, projectName), options);
};
-/*
-// prj name, file uuid => if exists and return path string/ parent folder
-const findParent: (projectName: string, fileUUID: string) => File | null = (projectName: string, fileUUID: string) => {
- if(!projectName || !fileUUID){
- return null;
- }
- function findFile(dir: string, fileList: string[]) : string {
-
- }
-
-}
-*/
const logPath: (type: string, projectName?: string) => string = (
type: string, projectName?: string): string => {
@@ -209,9 +197,29 @@ export const createProjectFolder: (name: string) => void = (projName: string): a
}
}
-export const addSubFileToFolder: (parentId: string, subFileId: string) => void = (parentId: string, subFileId: string): any => {
- // TODO:
- // fetch parent file object from database
- // update parent file object
+export const addSubFileToFolder: (parentId: string, subFileId: string) => Promise<boolean> = async(parentId: string, subFileId: string): Promise<boolean> => {
+ // Fetch parent and subFile object from database
+ const parent: File | null = await File.findOne({
+ include: [{all: true}],
+ where: {
+ uuid: parentId
+ }
+ });
+ const file: File | null = await File.findOne({
+ include: [{all: true}],
+ where: {
+ uuid: subFileId
+ }
+ });
+ if(!parent || !file){
+ return false;
+ }
+ // update both objects
+ parent.containedFiles.push(file);
+ file.parentFolderId = parent.id;
// save
+ await parent.save();
+ await file.save();
+
+ return true;
}