Skip to content

Commit

Permalink
feat: added is_in_trash index + ref
Browse files Browse the repository at this point in the history
  • Loading branch information
MontaGhanmy committed Sep 21, 2023
1 parent 75c676b commit 9565442
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { isObject } from "lodash";
import { FindOptions } from "../../repository/repository";
import { ObjectType } from "../../types";
import { getEntityDefinition, secureOperators } from "../../utils";
import { getEntityDefinition, secureOperators, filteringRequired } from "../../utils";
import { transformValueToDbString } from "./typeTransforms";

export function buildSelectQuery<Entity>(
Expand All @@ -25,14 +24,13 @@ export function buildSelectQuery<Entity>(
let result: string;
const filter = filters[key];

if (filteringRequired(key)) {
allowFiltering = true;
}

if (!filter) {
return;
}
if (isObject(filter) && JSON.stringify(filter).includes("ne")) {
allowFiltering = true;
result = `${key} IN (NULL, false)`;
return result;
}

if (Array.isArray(filter)) {
if (!filter.length) {
Expand All @@ -49,7 +47,6 @@ export function buildSelectQuery<Entity>(

result = `${key} IN (${inClause.join(",")})`;
} else {
if (key === "is_in_trash" || key === "scope") allowFiltering = true;
result = `${key} = ${transformValueToDbString(filter, columnsDefinition[key].type, {
columns: columnsDefinition[key].options,
secret: options.secret || "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,12 @@ export function toMongoDbOrderable(timeuuid?: string): string {
const time_str = [uuid_arr[2], uuid_arr[1], uuid_arr[0], uuid_arr[3], uuid_arr[4]].join("-");
return time_str;
}

/**
* Check if filtering is necessary
* @param {string} key
* @returns {boolean} Returns true if key is "is_in_trash" or "scope", otherwise returns false.
*/
export const filteringRequired = (key: string) => {
return key === "is_in_trash" || key === "scope";
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export const TYPE = "drive_files";
export type DriveScope = "personal" | "shared";

@Entity(TYPE, {
globalIndexes: [["company_id", "parent_id"]],
globalIndexes: [
["company_id", "parent_id"],
["company_id", "is_in_trash"],
],
primaryKey: [["company_id"], "id"],
type: TYPE,
search,
Expand Down

0 comments on commit 9565442

Please sign in to comment.