Skip to content

Commit

Permalink
Add checking displayKey for parent folder (#13)
Browse files Browse the repository at this point in the history
* add checking displayKey for parent folder

* move parentFolderDisplayKey

* fix type

* fix after review
  • Loading branch information
Sergey-weber authored Oct 18, 2023
1 parent f0f75df commit e2520f7
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/db/models/entry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ class Entry extends Model {
const isDeleted = false;
const deletedAt = null;

if (key.slice(-1) === '/') {
const isLastLetterSlash = key.slice(-1) === '/';

if (isLastLetterSlash) {
key = key.slice(0, key.length - 1);
}

Expand Down Expand Up @@ -244,11 +246,9 @@ class Entry extends Model {

if (parentFolderKey !== '/') {
if (recursion) {
let existedParentFolder: any;

const folderKeysMap = Utils.getFoldersKeys({
folderKey: Utils.getParentFolderKey({keyFormatted: displayKey}),
}).reduce((keysMap: {[key: string]: any}, folderKey: string) => {
}).reduce((keysMap: {[key: string]: null}, folderKey: string) => {
keysMap[folderKey] = null;

return keysMap;
Expand All @@ -258,17 +258,18 @@ class Entry extends Model {
const folderKeysLowerCase = Object.keys(folderKeysMap).map((key) =>
key.toLowerCase(),
);

const existedFolders = await Entry.query(TRX)
.select(['display_key as key', 'entryId'])
.where({tenantId})
.whereIn('key', folderKeysLowerCase);

let existedParentFolder: Entry;

existedFolders.forEach((existedFolder) => {
const existedFolderJSON = existedFolder.toJSON();
// @ts-ignore

const entryId = existedFolderJSON.entryId;
// @ts-ignore

const key = existedFolderJSON.key;

folderKeysMap[key] = entryId;
Expand Down Expand Up @@ -386,7 +387,7 @@ class Entry extends Model {
.join('revisions', 'entries.savedId', 'revisions.revId')
.where({
tenantId,
key: parentFolderKey,
displayKey: Utils.getParentFolderKey({keyFormatted: displayKey}),
isDeleted: false,
})
.first();
Expand Down

0 comments on commit e2520f7

Please sign in to comment.