refactor: utility handlers (#5510)

This commit is contained in:
Aaryan Khandelwal 2024-09-03 18:36:31 +05:30 committed by GitHub
parent b6d596b474
commit 747905a96d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 19 deletions

View file

@ -4,14 +4,12 @@ import { TDocumentTypes } from "@/core/types/common.js";
type TArgs = {
connection: ConnectionConfiguration
cookie: string | undefined;
cookie: string;
documentType: TDocumentTypes | undefined;
params: URLSearchParams;
}
export const authenticateUser = (args: TArgs): Promise<void> => {
const { params } = args;
const documentType = params.get("documentType")?.toString() as
| TDocumentTypes
| undefined;
export const authenticateUser = async (args: TArgs): Promise<void> => {
const { documentType } = args;
throw Error(`Authentication failed: Invalid document type ${documentType} provided.`);
}

View file

@ -2,16 +2,14 @@
import { TDocumentTypes } from "@/core/types/common.js";
type TArgs = {
params: URLSearchParams;
pageId: string;
updatedDescription: Uint8Array;
cookie: string | undefined;
documentType: TDocumentTypes | undefined;
pageId: string;
params: URLSearchParams;
updatedDescription: Uint8Array;
}
export const updateDocument = (args: TArgs): Promise<void> => {
const { params } = args;
const documentType = params.get("documentType")?.toString() as
| TDocumentTypes
| undefined;
export const updateDocument = async (args: TArgs): Promise<void> => {
const { documentType } = args;
throw Error(`Update failed: Invalid document type ${documentType} provided.`);
}

View file

@ -18,8 +18,6 @@ type Props = {
export const handleAuthentication = async (props: Props) => {
const { connection, cookie, params, token } = props;
// params
const workspaceSlug = params.get("workspaceSlug")?.toString();
const projectId = params.get("projectId")?.toString();
const documentType = params.get("documentType")?.toString() as
| TDocumentTypes
| undefined;
@ -36,6 +34,9 @@ export const handleAuthentication = async (props: Props) => {
}
if (documentType === "project_page") {
// params
const workspaceSlug = params.get("workspaceSlug")?.toString();
const projectId = params.get("projectId")?.toString();
if (!workspaceSlug || !projectId) {
throw Error(
"Authentication failed: Incomplete query params. Either workspaceSlug or projectId is missing."
@ -56,6 +57,7 @@ export const handleAuthentication = async (props: Props) => {
await authenticateUser({
connection,
cookie,
documentType,
params
});
}

View file

@ -108,10 +108,11 @@ const server = Server.configure({
await updatePageDescription(params, pageId, state, cookie);
} else {
await updateDocument({
params,
pageId,
updatedDescription: state,
cookie,
documentType,
pageId,
params,
updatedDescription: state,
})
}
} catch (error) {