🍄 Separate trash for the personal and shared drive (#189)
This commit is contained in:
+1
-17
@@ -5,7 +5,7 @@ import { defer, Subject, throwError, timer } from "rxjs";
|
||||
import { concat, delayWhen, retryWhen, take, tap } from "rxjs/operators";
|
||||
import { UpsertOptions } from "..";
|
||||
import { logger } from "../../../../../../framework";
|
||||
import { getEntityDefinition, unwrapIndexes, unwrapPrimarykey } from "../../utils";
|
||||
import { getEntityDefinition, unwrapPrimarykey } from "../../utils";
|
||||
import { EntityDefinition, ColumnDefinition, ObjectType } from "../../types";
|
||||
import { AbstractConnector } from "../abstract-connector";
|
||||
import {
|
||||
@@ -451,22 +451,6 @@ export class CassandraConnector extends AbstractConnector<
|
||||
const instance = new (entityType as any)();
|
||||
const { columnsDefinition, entityDefinition } = getEntityDefinition(instance);
|
||||
|
||||
const pk = unwrapPrimarykey(entityDefinition);
|
||||
const indexes = unwrapIndexes(entityDefinition);
|
||||
|
||||
if (
|
||||
Object.keys(filters).some(key => pk.indexOf(key) < 0) &&
|
||||
Object.keys(filters).some(key => indexes.indexOf(key) < 0)
|
||||
) {
|
||||
//Filter not in primary key
|
||||
throw new Error(
|
||||
`All filter parameters must be defined in entity primary key,
|
||||
got: ${JSON.stringify(Object.keys(filters))}
|
||||
on table ${entityDefinition.name} but pk is ${JSON.stringify(pk)},
|
||||
instance was ${JSON.stringify(instance)}`,
|
||||
);
|
||||
}
|
||||
|
||||
const query = buildSelectQuery<Table>(
|
||||
entityType as unknown as ObjectType<Table>,
|
||||
filters,
|
||||
|
||||
+7
-2
@@ -1,6 +1,6 @@
|
||||
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>(
|
||||
@@ -17,12 +17,17 @@ export function buildSelectQuery<Entity>(
|
||||
): string {
|
||||
const instance = new (entityType as any)();
|
||||
const { columnsDefinition, entityDefinition } = getEntityDefinition(instance);
|
||||
let allowFiltering = false;
|
||||
|
||||
const where = Object.keys(filters)
|
||||
.map(key => {
|
||||
let result: string;
|
||||
const filter = filters[key];
|
||||
|
||||
if (filteringRequired(key)) {
|
||||
allowFiltering = true;
|
||||
}
|
||||
|
||||
if (!filter) {
|
||||
return;
|
||||
}
|
||||
@@ -77,7 +82,7 @@ export function buildSelectQuery<Entity>(
|
||||
whereClause.trim().length ? "WHERE " + whereClause : ""
|
||||
} ${orderByClause.trim().length ? "ORDER BY " + orderByClause : ""}`
|
||||
.trimEnd()
|
||||
.concat(";");
|
||||
.concat(allowFiltering ? " ALLOW FILTERING;" : ";");
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
+1
-19
@@ -3,7 +3,7 @@ import { UpsertOptions } from "..";
|
||||
import { ListResult, Paginable, Pagination } from "../../../../../../framework/api/crud-service";
|
||||
import { FindOptions } from "../../repository/repository";
|
||||
import { ColumnDefinition, EntityDefinition, ObjectType } from "../../types";
|
||||
import { getEntityDefinition, unwrapIndexes, unwrapPrimarykey } from "../../utils";
|
||||
import { getEntityDefinition, unwrapPrimarykey } from "../../utils";
|
||||
import { AbstractConnector } from "../abstract-connector";
|
||||
import { buildSelectQuery } from "./query-builder";
|
||||
import { transformValueFromDbString, transformValueToDbString } from "./typeTransforms";
|
||||
@@ -186,24 +186,6 @@ export class MongoConnector extends AbstractConnector<MongoConnectionOptions, mo
|
||||
const instance = new (entityType as any)();
|
||||
const { columnsDefinition, entityDefinition } = getEntityDefinition(instance);
|
||||
|
||||
const pk = unwrapPrimarykey(entityDefinition);
|
||||
|
||||
const indexes = unwrapIndexes(entityDefinition);
|
||||
if (
|
||||
Object.keys(filters).some(key => pk.indexOf(key) < 0) &&
|
||||
Object.keys(filters).some(key => indexes.indexOf(key) < 0)
|
||||
) {
|
||||
//Filter not in primary key
|
||||
throw Error(
|
||||
"All filter parameters must be defined in entity primary key, got: " +
|
||||
JSON.stringify(Object.keys(filters)) +
|
||||
" on table " +
|
||||
entityDefinition.name +
|
||||
" but pk is " +
|
||||
JSON.stringify(pk),
|
||||
);
|
||||
}
|
||||
|
||||
const db = await this.getDatabase();
|
||||
const collection = db.collection(`${entityDefinition.name}`);
|
||||
|
||||
|
||||
@@ -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";
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user