#7 - Added new Type definition and filter by status where we are on dev or prod
All checks were successful
CodyOps Core Builder / build-conteiner (pull_request) Successful in 2m55s

This commit is contained in:
Luciano Giacchetta 2025-08-08 17:48:45 -03:00
parent 5715c7cc11
commit 8e6c810d57
2 changed files with 40 additions and 5 deletions

View File

@ -1,11 +1,29 @@
import directus from "./directus";
import { readItems } from "@directus/sdk";
import { readItems, type Query } from "@directus/sdk";
import type { Post, DirectusSchema } from "../types/codyops-post";
const isDev = import.meta.env.DEV; // Astro's way to check for development mode
export const posts = await directus.request(
readItems("codyops_posts", {
fields: ['*']
readItems<DirectusSchema, 'codyops_posts', Query<DirectusSchema, Post>>("codyops_posts", {
fields: [
'slug',
'status',
'sort',
'user_created',
'user_updated',
'date_created',
'date_updated',
'title',
'description',
'tags',
'cover_image',
'content'
],
filter: {
status: isDev ? { '_neq': 'archived' } : { '_eq': 'published' }
}
)
})
);
export function getAllPosts() {
@ -21,4 +39,3 @@ export function getUniqueTags(posts: any ) {
export function filterPostsByTag(posts: any, tag: any) {
return posts.filter((post: any) => post.tags.includes(tag));
};

18
src/types/codyops-post.ts Normal file
View File

@ -0,0 +1,18 @@
export interface Post {
slug: string;
status: string;
sort: number | null;
user_created: string | null;
user_updated: string | null;
date_created: string | null;
date_updated: string | null;
title: string;
description: string;
tags: string[];
cover_image: string | null;
content: string;
}
export interface DirectusSchema {
codyops_posts: Post[];
}