problem solved
This commit is contained in:
@@ -6,6 +6,7 @@ import { Attributes, where } from "@sequelize/core";
|
||||
import { getCookieAuth, userIsAdmin } from '../../actions';
|
||||
import { ActionResult } from '../../ActionResult';
|
||||
import { PostAttributesWithBuckets } from '@/models';
|
||||
import { inspect } from 'util';
|
||||
|
||||
export async function deletePost(postID: number): Promise<ActionResult<boolean>> {
|
||||
await dbSync;
|
||||
@@ -30,7 +31,7 @@ export type GetPostsAttributes = {
|
||||
export async function getPostsWithBucketsAndProject(): Promise<ActionResult<GetPostsAttributes[]>> {
|
||||
await dbSync;
|
||||
if(! await userIsAdmin()) return {error:"Unauthorized, not fetching Posts."}
|
||||
const posts = await Post.findAll({
|
||||
const posts:Post[] = await Post.findAll({
|
||||
include: [
|
||||
{association: Post.associations.buckets, include: Bucket.associations.attachments},
|
||||
{association: Post.associations.user},
|
||||
@@ -38,22 +39,7 @@ export async function getPostsWithBucketsAndProject(): Promise<ActionResult<GetP
|
||||
nest: false
|
||||
});
|
||||
return {result:JSON.parse(JSON.stringify(posts.map((e:Post)=>{
|
||||
return {
|
||||
id: e.id,
|
||||
title: e.title,
|
||||
content: e.content,
|
||||
description: e.description,
|
||||
buckets: e.buckets ? e.buckets : [],
|
||||
user: e.user,
|
||||
project: {
|
||||
id: e.project_id,
|
||||
name: e.project ? e.project.name : "",
|
||||
readableIdentifier: e.project ? e.project.readableIdentifier : "",
|
||||
posts: e.project ? e.project.posts : []
|
||||
},
|
||||
createdAt: e.createdAt,
|
||||
updatedAt: e.updatedAt
|
||||
} as GetPostsAttributes
|
||||
return inspect(e)
|
||||
})))};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user