Skip to content

Commit

Permalink
Merge pull request #315 from internxt/fix/intial-folders-parent-uuid
Browse files Browse the repository at this point in the history
[_]: Fix/Add parent uuid to intial folders
  • Loading branch information
sg-gs authored May 17, 2024
2 parents 3131816 + 55cf500 commit 0fd1d99
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/modules/folder/folder.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,9 @@ export class SequelizeFolderRepository implements FolderRepository {
userId: UserAttributes['id'],
name: FolderAttributes['name'],
bucket: FolderAttributes['bucket'],
parentId: FolderAttributes['id'],
parentId: FolderAttributes['parentId'],
encryptVersion: FolderAttributes['encryptVersion'],
parentUuid?: FolderAttributes['parentUuid'],
): Promise<Folder> {
const folder = await this.folderModel.create({
userId,
Expand All @@ -339,6 +340,7 @@ export class SequelizeFolderRepository implements FolderRepository {
parentId,
encryptVersion,
uuid: v4(),
parentUuid,
});

return this.toDomain(folder);
Expand All @@ -349,8 +351,9 @@ export class SequelizeFolderRepository implements FolderRepository {
userId: UserAttributes['id'];
name: FolderAttributes['name'];
bucket: FolderAttributes['bucket'];
parentId: FolderAttributes['id'];
parentId: FolderAttributes['parentId'];
encryptVersion: FolderAttributes['encryptVersion'];
parentUuid: FolderAttributes['parentUuid'];
}[],
): Promise<Folder[]> {
const rawFolders = await this.folderModel.bulkCreate(folders);
Expand Down
8 changes: 6 additions & 2 deletions src/modules/folder/folder.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ export class FolderUseCases {
creator: User,
folders: {
name: FolderAttributes['name'];
parentFolderId: FolderAttributes['id'];
parentFolderId: FolderAttributes['parentId'];
parentUuid: FolderAttributes['parentUuid'];
}[],
): Promise<Folder[]> {
for (const { parentFolderId } of folders) {
Expand Down Expand Up @@ -226,6 +227,7 @@ export class FolderUseCases {
encryptVersion: '03-aes',
bucket: null,
parentId: folder.parentFolderId,
parentUuid: folder.parentUuid,
};
}),
);
Expand All @@ -234,7 +236,8 @@ export class FolderUseCases {
async createFolder(
creator: User,
name: FolderAttributes['name'],
parentFolderId: FolderAttributes['id'],
parentFolderId: FolderAttributes['parentId'],
parentUuid: FolderAttributes['parentUuid'],
): Promise<Folder> {
if (parentFolderId >= 2147483648) {
throw new Error('Invalid parent folder');
Expand Down Expand Up @@ -285,6 +288,7 @@ export class FolderUseCases {
null,
parentFolderId,
'03-aes',
parentUuid,
);

return folder;
Expand Down
12 changes: 10 additions & 2 deletions src/modules/user/user.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,16 @@ export class UserUseCases {
// Relate the root folder to the user
this.userRepository.updateById(user.id, { rootFolderId: rootFolder.id }),
this.folderUseCases.createFolders(user, [
{ name: 'Family', parentFolderId: rootFolder.id },
{ name: 'Personal', parentFolderId: rootFolder.id },
{
name: 'Family',
parentFolderId: rootFolder.id,
parentUuid: rootFolder.uuid,
},
{
name: 'Personal',
parentFolderId: rootFolder.id,
parentUuid: rootFolder.uuid,
},
]),
]);

Expand Down

0 comments on commit 0fd1d99

Please sign in to comment.