implemented file upload for attachments

This commit is contained in:
2024-06-11 02:23:22 +02:00
parent e841ba8938
commit 86eb422dd5
23 changed files with 332 additions and 147 deletions
@@ -0,0 +1,33 @@
'use server';
import { revalidatePath, revalidateTag } from 'next/cache'
import { Post } from "@/model/Post";
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';
export async function deletePost(postID: number): Promise<ActionResult<boolean>> {
// revalidatePath("/admin/man-post","page")
if(! await userIsAdmin()) return {error:"Unauthorized, not deleting Post", result: false}
const destroy = await Post.destroy({ where: { id: postID } });
return {result: true};
}
export async function getPosts(): Promise<ActionResult<Attributes<Post>[]>> {
if(! await userIsAdmin()) return {error:"Unauthorized, not fetching Posts."}
const posts = await Post.findAll();
return {result:JSON.parse(JSON.stringify(posts))};
}
export async function updatePost(postAttributes: Partial<Attributes<Post>>): Promise<ActionResult<Attributes<Post>[]>> {
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))};
}