refactor: utility handlers (#5510)
This commit is contained in:
parent
b6d596b474
commit
747905a96d
4 changed files with 18 additions and 19 deletions
|
|
@ -4,14 +4,12 @@ import { TDocumentTypes } from "@/core/types/common.js";
|
||||||
|
|
||||||
type TArgs = {
|
type TArgs = {
|
||||||
connection: ConnectionConfiguration
|
connection: ConnectionConfiguration
|
||||||
cookie: string | undefined;
|
cookie: string;
|
||||||
|
documentType: TDocumentTypes | undefined;
|
||||||
params: URLSearchParams;
|
params: URLSearchParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const authenticateUser = (args: TArgs): Promise<void> => {
|
export const authenticateUser = async (args: TArgs): Promise<void> => {
|
||||||
const { params } = args;
|
const { documentType } = args;
|
||||||
const documentType = params.get("documentType")?.toString() as
|
|
||||||
| TDocumentTypes
|
|
||||||
| undefined;
|
|
||||||
throw Error(`Authentication failed: Invalid document type ${documentType} provided.`);
|
throw Error(`Authentication failed: Invalid document type ${documentType} provided.`);
|
||||||
}
|
}
|
||||||
|
|
@ -2,16 +2,14 @@
|
||||||
import { TDocumentTypes } from "@/core/types/common.js";
|
import { TDocumentTypes } from "@/core/types/common.js";
|
||||||
|
|
||||||
type TArgs = {
|
type TArgs = {
|
||||||
params: URLSearchParams;
|
|
||||||
pageId: string;
|
|
||||||
updatedDescription: Uint8Array;
|
|
||||||
cookie: string | undefined;
|
cookie: string | undefined;
|
||||||
|
documentType: TDocumentTypes | undefined;
|
||||||
|
pageId: string;
|
||||||
|
params: URLSearchParams;
|
||||||
|
updatedDescription: Uint8Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateDocument = (args: TArgs): Promise<void> => {
|
export const updateDocument = async (args: TArgs): Promise<void> => {
|
||||||
const { params } = args;
|
const { documentType } = args;
|
||||||
const documentType = params.get("documentType")?.toString() as
|
|
||||||
| TDocumentTypes
|
|
||||||
| undefined;
|
|
||||||
throw Error(`Update failed: Invalid document type ${documentType} provided.`);
|
throw Error(`Update failed: Invalid document type ${documentType} provided.`);
|
||||||
}
|
}
|
||||||
|
|
@ -18,8 +18,6 @@ type Props = {
|
||||||
export const handleAuthentication = async (props: Props) => {
|
export const handleAuthentication = async (props: Props) => {
|
||||||
const { connection, cookie, params, token } = props;
|
const { connection, cookie, params, token } = props;
|
||||||
// params
|
// params
|
||||||
const workspaceSlug = params.get("workspaceSlug")?.toString();
|
|
||||||
const projectId = params.get("projectId")?.toString();
|
|
||||||
const documentType = params.get("documentType")?.toString() as
|
const documentType = params.get("documentType")?.toString() as
|
||||||
| TDocumentTypes
|
| TDocumentTypes
|
||||||
| undefined;
|
| undefined;
|
||||||
|
|
@ -36,6 +34,9 @@ export const handleAuthentication = async (props: Props) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (documentType === "project_page") {
|
if (documentType === "project_page") {
|
||||||
|
// params
|
||||||
|
const workspaceSlug = params.get("workspaceSlug")?.toString();
|
||||||
|
const projectId = params.get("projectId")?.toString();
|
||||||
if (!workspaceSlug || !projectId) {
|
if (!workspaceSlug || !projectId) {
|
||||||
throw Error(
|
throw Error(
|
||||||
"Authentication failed: Incomplete query params. Either workspaceSlug or projectId is missing."
|
"Authentication failed: Incomplete query params. Either workspaceSlug or projectId is missing."
|
||||||
|
|
@ -56,6 +57,7 @@ export const handleAuthentication = async (props: Props) => {
|
||||||
await authenticateUser({
|
await authenticateUser({
|
||||||
connection,
|
connection,
|
||||||
cookie,
|
cookie,
|
||||||
|
documentType,
|
||||||
params
|
params
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -108,10 +108,11 @@ const server = Server.configure({
|
||||||
await updatePageDescription(params, pageId, state, cookie);
|
await updatePageDescription(params, pageId, state, cookie);
|
||||||
} else {
|
} else {
|
||||||
await updateDocument({
|
await updateDocument({
|
||||||
params,
|
|
||||||
pageId,
|
|
||||||
updatedDescription: state,
|
|
||||||
cookie,
|
cookie,
|
||||||
|
documentType,
|
||||||
|
pageId,
|
||||||
|
params,
|
||||||
|
updatedDescription: state,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue