various changes

This commit is contained in:
2024-06-23 02:52:50 +02:00
committed by andreas
parent c3a8469371
commit adc02f2e5b
19 changed files with 268 additions and 155 deletions
@@ -1,11 +1,10 @@
'use server';
import { revalidatePath, revalidateTag } from 'next/cache'
import { Post } from "@/model/Post";
import { Bucket, Post, PostBucket, User, dbSync } from "@/model/Models";
import { Attributes, where } from "@sequelize/core";
import { cookies } from 'next/headers';
import { getCookieAuth, userIsAdmin } from '../actions';
import { User } from '@/model/User';
import { ActionResult } from '../ActionResult';
@@ -13,6 +12,7 @@ import { ActionResult } from '../ActionResult';
export async function deletePost(postID: number): Promise<ActionResult<boolean>> {
await dbSync;
// revalidatePath("/admin/man-post","page")
if(! await userIsAdmin()) return {error:"Unauthorized, not deleting Post", result: false}
const destroy = await Post.destroy({ where: { id: postID } });
@@ -21,12 +21,14 @@ export async function deletePost(postID: number): Promise<ActionResult<boolean>>
export async function getPosts(): Promise<ActionResult<Attributes<Post>[]>> {
await dbSync;
if(! await userIsAdmin()) return {error:"Unauthorized, not fetching Posts."}
const posts = await Post.findAll();
const posts = await Post.findAll({include: {association: Post.associations.postBuckets, include: Bucket.associations.attachments}},);
return {result:JSON.parse(JSON.stringify(posts))};
}
export async function updatePost(postAttributes: Partial<Attributes<Post>>): Promise<ActionResult<Attributes<Post>[]>> {
await dbSync;
if(! await userIsAdmin()) return {error:"Unauthorized, not updating Post."}
const post = await Post.update(postAttributes, {where:{id:postAttributes.id}});
return {result:JSON.parse(JSON.stringify(post))};
+39
View File
@@ -0,0 +1,39 @@
import React, { ReactElement, ReactNode } from 'react';
function renderAttributes(props: Record<string, any>): string {
return Object.keys(props)
.map((key) => {
const value = props[key];
if (key === 'children' || value === undefined || value === null) {
return '';
}
return `${key}="${value}"`;
})
.filter(Boolean)
.join(' ');
}
function renderElement(element: ReactNode): string {
if (typeof element === 'string' || typeof element === 'number') {
return String(element);
}
if (React.isValidElement(element)) {
const { type, props } = element;
const mapped = React.Children.map(props.children, renderElement)
const cilds = mapped? mapped.join('') : props.children;
const attributes = renderAttributes(props);
return `<${type}${attributes ? ' ' + attributes : ''}>${cilds}</${type}>`;
}
if (Array.isArray(element)) {
return element.map(renderElement).join('');
}
return '';
}
export function jsxToString(element: JSX.Element): string {
console.log(element);
return renderElement(element);
}