Refactoring
This commit is contained in:
@@ -3,15 +3,10 @@
|
||||
import { revalidatePath, revalidateTag } from 'next/cache'
|
||||
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 { ActionResult } from '../ActionResult';
|
||||
import { PostAttributesWithBuckets } from '@/model/Post';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export async function deletePost(postID: number): Promise<ActionResult<boolean>> {
|
||||
await dbSync;
|
||||
// revalidatePath("/admin/man-post","page")
|
||||
@@ -20,16 +15,14 @@ export async function deletePost(postID: number): Promise<ActionResult<boolean>>
|
||||
return {result: true};
|
||||
}
|
||||
|
||||
|
||||
export async function getPostsWithBuckets(): Promise<ActionResult<PostAttributesWithBuckets[]>> {
|
||||
export async function getPostsWithBucketsAndProject(): Promise<ActionResult<PostAttributesWithBuckets[]>> {
|
||||
await dbSync;
|
||||
if(! await userIsAdmin()) return {error:"Unauthorized, not fetching Posts."}
|
||||
const posts = await Post.findAll({include: {association: Post.associations.buckets, include: Bucket.associations.attachments}},);
|
||||
const posts = await Post.findAll({include: [{association: Post.associations.buckets, include: Bucket.associations.attachments}, {association: Post.associations.project}], nest: false});
|
||||
console.dir(JSON.parse(JSON.stringify(posts)),{depth: 10, colors: true})
|
||||
return {result:JSON.parse(JSON.stringify(posts))};
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function getPosts(): Promise<ActionResult<Attributes<Post>[]>> {
|
||||
await dbSync;
|
||||
if(! await userIsAdmin()) return {error:"Unauthorized, not fetching Posts."}
|
||||
@@ -37,7 +30,6 @@ export async function getPosts(): Promise<ActionResult<Attributes<Post>[]>> {
|
||||
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."}
|
||||
|
||||
Reference in New Issue
Block a user