Artikel DB struktur geändert von CODEX

This commit is contained in:
Marco_205 committed 2026-10-12 14:42:28 +00:00
1 parent 0c0a678eaa
commit 9c18234efe
95 files changed
+3872 -2316

No files matched your search

+83 -80
View File
@@ -1,94 +1,97 @@
'use server'
'use server';
import { revalidatePath } from 'next/cache'
import { Article, ArticleCreate, ArticleUpsert } from "@/apps/frontend/types/catalog";
import { revalidatePath } from 'next/cache';
import {
Article,
ArticleCreate,
ArticleGroup,
ArticleUpsert,
} from '../types/catalog';
import { sites } from '../_config/sites';
import { endpoints } from '../_config/endpoints';
export async function articleCreate(data: ArticleCreate) {
console.log(data);
const result = await fetch('http://192.168.50.205/api/articles', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
const resultData = await result.json();
const api = endpoints.apiServer.url;
if (!result.ok) {
async function mutate(
url: string,
method: string,
data?: unknown,
): Promise<ActionResult> {
try {
const response = await fetch(`${api}${url}`, {
method,
headers: { 'Content-Type': 'application/json' },
body: data === undefined ? undefined : JSON.stringify(data),
});
const result = await response.json();
if (!response.ok) {
return {
success: false,
errors: Array.isArray(result.message)
? result.message
: [result.message ?? 'Speichern fehlgeschlagen'],
};
}
revalidatePath(sites.article.url);
return { success: true, data: result };
} catch {
return {
success: false,
errors: resultData.message, // kommt aus NestJS
errors: [
'Der Artikelserver ist nicht erreichbar. Bitte erneut versuchen.',
],
};
}
revalidatePath(sites.article.new.url)
}
export async function articleUpdate(id: string, data: ArticleUpsert): Promise<ActionResult> {
const result = await fetch(`http://192.168.50.205/api/articles/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
const resultData = await result.json();
if (!result.ok) {
return {
success: false,
errors: resultData.message, // kommt aus NestJS
};
}
revalidatePath(sites.article.update.url + '/' + id);
return { success: true };
export async function articleCreate(
data: ArticleCreate,
): Promise<ActionResult> {
return mutate('/articles', 'POST', data);
}
export async function articleUpdate(
id: string,
data: ArticleUpsert,
): Promise<ActionResult> {
const result = await mutate(`/articles/${id}`, 'PATCH', data);
if (result.success) revalidatePath(`${sites.article.update.url}/${id}`);
return result;
}
export async function articleFindAll(): Promise<Article[]> {
const result = await fetch(`http://192.168.50.205/api/articles`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json() as Article[];
return data;
const response = await fetch(`${api}/articles`, { cache: 'no-store' });
if (!response.ok) throw new Error('Artikel konnten nicht geladen werden');
return response.json();
}
export async function articleFindById(id: string): Promise<Article | null> {
const response = await fetch(`${api}/articles/${id}`, { cache: 'no-store' });
if (response.status === 404) return null;
if (!response.ok) throw new Error('Artikel konnte nicht geladen werden');
return response.json();
}
export async function articleDelete(
id: string,
revalidateUrl?: string,
): Promise<ActionResult> {
const result = await mutate(`/articles/${id}`, 'DELETE');
if (result.success && revalidateUrl) revalidatePath(revalidateUrl);
return result;
}
export async function articleGroupsFindAll(): Promise<ArticleGroup[]> {
const response = await fetch(`${api}/article-groups`, { cache: 'no-store' });
if (!response.ok)
throw new Error('Produktgruppen konnten nicht geladen werden');
return response.json();
}
export async function articleGroupCreate(name: string): Promise<ActionResult> {
return mutate('/article-groups', 'POST', { name });
}
export async function articleFindById(id: string): Promise<any> {
const result = await fetch(`http://192.168.50.205/api/articles/${id}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json() as Article
console.log('getArticle', data)
return data;
export async function articleMigrationStatus(): Promise<{
pendingLegacyArticles: number;
}> {
const response = await fetch(`${api}/articles/migration-status`, {
cache: 'no-store',
});
if (!response.ok)
throw new Error('Migrationsstatus konnte nicht geladen werden');
return response.json();
}
export async function articleDelete(id: string,revalidateUrl?:string): Promise<ActionResult> {
const result = await fetch(`http://192.168.50.205/api/articles/${id}`, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' }
})
const resultData = await result.json();
if (!result.ok) {
return {
success: false,
errors: resultData.message, // kommt aus NestJS
};
}
if(revalidateUrl) revalidatePath(revalidateUrl);
return { success: true };
}