chore: request validation for searches (#5460)

This commit is contained in:
Apoorv Mishra
2023-06-21 10:38:38 +05:30
committed by GitHub
parent 6d556c7a55
commit 8d69de1be0
5 changed files with 184 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
import { isNull } from "lodash";
import { isNil, isNull } from "lodash";
import { v4 as uuidv4 } from "uuid";
import {
CollectionPermission,
@@ -28,6 +28,7 @@ import {
ApiKey,
Subscription,
Notification,
SearchQuery,
} from "@server/models";
let count = 1;
@@ -517,3 +518,33 @@ export async function buildNotification(
return Notification.create(overrides);
}
export async function buildSearchQuery(
overrides: Partial<SearchQuery> = {}
): Promise<SearchQuery> {
if (!overrides.teamId) {
const team = await buildTeam();
overrides.teamId = team.id;
}
if (!overrides.userId) {
const user = await buildUser({
teamId: overrides.teamId,
});
overrides.userId = user.id;
}
if (!overrides.source) {
overrides.source = "app";
}
if (isNil(overrides.query)) {
overrides.query = "query";
}
if (isNil(overrides.results)) {
overrides.results = 1;
}
return SearchQuery.create(overrides);
}