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 = {
|
||||
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.`);
|
||||
}
|
||||
|
|
@ -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.`);
|
||||
}
|
||||
|
|
@ -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
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue