35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
/**
|
|
* Guards for the category request bodies.
|
|
*
|
|
* @module
|
|
*/
|
|
|
|
import type {
|
|
CreateCategoryRequest,
|
|
UpdateCategoryRequest,
|
|
} from "../../shared/category.ts";
|
|
|
|
/** Checks whether `obj` is a valid {@link CreateCategoryRequest}. */
|
|
export function isCreateCategoryRequest(
|
|
obj: unknown,
|
|
): obj is CreateCategoryRequest {
|
|
if (!obj || typeof obj !== "object") return false;
|
|
const o = obj as Record<string, unknown>;
|
|
if (typeof o.slug !== "string") return false;
|
|
if (typeof o.name !== "string") return false;
|
|
if ("position" in o && typeof o.position !== "number") return false;
|
|
return true;
|
|
}
|
|
|
|
/** Checks whether `obj` is a valid {@link UpdateCategoryRequest}. */
|
|
export function isUpdateCategoryRequest(
|
|
obj: unknown,
|
|
): obj is UpdateCategoryRequest {
|
|
if (!obj || typeof obj !== "object") return false;
|
|
const o = obj as Record<string, unknown>;
|
|
if ("slug" in o && typeof o.slug !== "string") return false;
|
|
if ("name" in o && typeof o.name !== "string") return false;
|
|
if ("position" in o && typeof o.position !== "number") return false;
|
|
return true;
|
|
}
|