mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-26 06:44:58 +00:00
code: page,get,dbal (1 files)
This commit is contained in:
@@ -2,37 +2,39 @@
|
||||
* @file get-page.ts
|
||||
* @description Get page operations
|
||||
*/
|
||||
import type { PageView, Result } from '../types';
|
||||
import type { InMemoryStore } from '../store/in-memory-store';
|
||||
import type { PageView, Result } from '../../types'
|
||||
import type { InMemoryStore } from '../../store/in-memory-store'
|
||||
import { validateId } from '../../validation/validate-id'
|
||||
|
||||
/**
|
||||
* Get a page by ID
|
||||
*/
|
||||
export async function getPage(store: InMemoryStore, id: string): Promise<Result<PageView>> {
|
||||
if (!id) {
|
||||
return { success: false, error: { code: 'VALIDATION_ERROR', message: 'ID required' } };
|
||||
export const getPage = async (store: InMemoryStore, id: string): Promise<Result<PageView>> => {
|
||||
const idErrors = validateId(id)
|
||||
if (idErrors.length > 0) {
|
||||
return { success: false, error: { code: 'VALIDATION_ERROR', message: idErrors[0] } }
|
||||
}
|
||||
|
||||
const page = store.pages.get(id);
|
||||
const page = store.pages.get(id)
|
||||
if (!page) {
|
||||
return { success: false, error: { code: 'NOT_FOUND', message: `Page not found: ${id}` } };
|
||||
return { success: false, error: { code: 'NOT_FOUND', message: `Page not found: ${id}` } }
|
||||
}
|
||||
|
||||
return { success: true, data: page };
|
||||
return { success: true, data: page }
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a page by slug
|
||||
*/
|
||||
export async function getPageBySlug(store: InMemoryStore, slug: string): Promise<Result<PageView>> {
|
||||
export const getPageBySlug = async (store: InMemoryStore, slug: string): Promise<Result<PageView>> => {
|
||||
if (!slug) {
|
||||
return { success: false, error: { code: 'VALIDATION_ERROR', message: 'Slug required' } };
|
||||
return { success: false, error: { code: 'VALIDATION_ERROR', message: 'Slug is required' } }
|
||||
}
|
||||
|
||||
const id = store.pageSlugs.get(slug);
|
||||
const id = store.pageSlugs.get(slug)
|
||||
if (!id) {
|
||||
return { success: false, error: { code: 'NOT_FOUND', message: `Page not found: ${slug}` } };
|
||||
return { success: false, error: { code: 'NOT_FOUND', message: `Page not found with slug: ${slug}` } }
|
||||
}
|
||||
|
||||
return getPage(store, id);
|
||||
return getPage(store, id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user