add: working JSON data insert
This commit is contained in:
@@ -1,51 +1,5 @@
|
||||
import { RscEntryLexicalCell as RscEntryLexicalCell_44fe37237e0ebf4470c9990d8cb7b07e } from '@payloadcms/richtext-lexical/rsc'
|
||||
import { RscEntryLexicalField as RscEntryLexicalField_44fe37237e0ebf4470c9990d8cb7b07e } from '@payloadcms/richtext-lexical/rsc'
|
||||
import { InlineToolbarFeatureClient as InlineToolbarFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { FixedToolbarFeatureClient as FixedToolbarFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { BoldFeatureClient as BoldFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { ItalicFeatureClient as ItalicFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { UnderlineFeatureClient as UnderlineFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { StrikethroughFeatureClient as StrikethroughFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { SubscriptFeatureClient as SubscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { SuperscriptFeatureClient as SuperscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { InlineCodeFeatureClient as InlineCodeFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { ParagraphFeatureClient as ParagraphFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { HeadingFeatureClient as HeadingFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { AlignFeatureClient as AlignFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { IndentFeatureClient as IndentFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { UnorderedListFeatureClient as UnorderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { OrderedListFeatureClient as OrderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { ChecklistFeatureClient as ChecklistFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { LinkFeatureClient as LinkFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { RelationshipFeatureClient as RelationshipFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { BlockquoteFeatureClient as BlockquoteFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { UploadFeatureClient as UploadFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { HorizontalRuleFeatureClient as HorizontalRuleFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||
import { SignInWithAuthjsButton as SignInWithAuthjsButton_06d0cb594d8f6ba2ac35015f930c882e } from 'payload-authjs/components'
|
||||
|
||||
export const importMap = {
|
||||
"@payloadcms/richtext-lexical/rsc#RscEntryLexicalCell": RscEntryLexicalCell_44fe37237e0ebf4470c9990d8cb7b07e,
|
||||
"@payloadcms/richtext-lexical/rsc#RscEntryLexicalField": RscEntryLexicalField_44fe37237e0ebf4470c9990d8cb7b07e,
|
||||
"@payloadcms/richtext-lexical/client#InlineToolbarFeatureClient": InlineToolbarFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#FixedToolbarFeatureClient": FixedToolbarFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#BoldFeatureClient": BoldFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#ItalicFeatureClient": ItalicFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#UnderlineFeatureClient": UnderlineFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#StrikethroughFeatureClient": StrikethroughFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#SubscriptFeatureClient": SubscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#SuperscriptFeatureClient": SuperscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#InlineCodeFeatureClient": InlineCodeFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#ParagraphFeatureClient": ParagraphFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#HeadingFeatureClient": HeadingFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#AlignFeatureClient": AlignFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#IndentFeatureClient": IndentFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#UnorderedListFeatureClient": UnorderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#OrderedListFeatureClient": OrderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#ChecklistFeatureClient": ChecklistFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#LinkFeatureClient": LinkFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#RelationshipFeatureClient": RelationshipFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#BlockquoteFeatureClient": BlockquoteFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#UploadFeatureClient": UploadFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"@payloadcms/richtext-lexical/client#HorizontalRuleFeatureClient": HorizontalRuleFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||
"payload-authjs/components#SignInWithAuthjsButton": SignInWithAuthjsButton_06d0cb594d8f6ba2ac35015f930c882e
|
||||
}
|
||||
|
||||
40
src/app/(payload)/api/insert-papers/route.ts
Normal file
40
src/app/(payload)/api/insert-papers/route.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getPayload } from 'payload';
|
||||
import config from '@payload-config';
|
||||
|
||||
const payload = await getPayload({ config });
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
const papersJson = await req.json();
|
||||
|
||||
const mapPaperData = (paper) => ({
|
||||
title: paper.title,
|
||||
department: paper.Abteilung.includes('WI') ? 'WI' : paper.Abteilung.includes('CI') ? 'CI' : 'MD',
|
||||
year: paper.id.toString().slice(0, 4),
|
||||
issue: paper.Ausgangslage,
|
||||
goal: paper.Zielsetzung,
|
||||
result: paper["Geplantes Ergebnis der Prüfungskandidatin/des Prüfungskandidaten"],
|
||||
mentor: paper["Betreuer/innen"].replace("Hauptverantwortlich: ", ""),
|
||||
authors: paper.Projektteam.split(",").map((author) => {
|
||||
const isLeader = author.includes("(Hauptverantwortlich)");
|
||||
return {
|
||||
name: author.replace("(Hauptverantwortlich)", "").trim(),
|
||||
position: isLeader ? "leader" : "member",
|
||||
};
|
||||
}).filter(author => author.name.length > 0),
|
||||
});
|
||||
|
||||
for (const paper of papersJson) {
|
||||
await payload.create({
|
||||
collection: "papers",
|
||||
data: mapPaperData(paper),
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Papers successfully inserted!" });
|
||||
} catch (err) {
|
||||
console.error("Insertion error:", err);
|
||||
return NextResponse.json({ error: "Failed to insert papers." }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,9 @@ const dirname = path.dirname(filename)
|
||||
export const Media: CollectionConfig = {
|
||||
slug: 'media',
|
||||
access: {
|
||||
|
||||
create: ({ req: { user } }) => Boolean(user),
|
||||
update: ({ req: { user } }) => Boolean(user && user.role === 'admin'),
|
||||
delete: ({ req: { user } }) => Boolean(user && user.role === 'admin'),
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import type { CollectionConfig } from "payload";
|
||||
|
||||
|
||||
|
||||
|
||||
export const Papers: CollectionConfig = {
|
||||
slug: "papers",
|
||||
labels: {
|
||||
@@ -18,49 +15,61 @@ export const Papers: CollectionConfig = {
|
||||
if (!user || !id) return false; // Explicitly handle missing ID
|
||||
|
||||
const paper = await payload.findByID({
|
||||
collection: 'papers',
|
||||
collection: "papers",
|
||||
id,
|
||||
depth: 1,
|
||||
});
|
||||
|
||||
if (!paper) return false;
|
||||
|
||||
return paper.authors.some((author: any) => author.user.id === user.id);
|
||||
return paper.authors.some((author: any) => author.user.name === user.name);
|
||||
},
|
||||
|
||||
|
||||
},
|
||||
admin: {
|
||||
useAsTitle: "title",
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: "published",
|
||||
type: "checkbox",
|
||||
defaultValue: false,
|
||||
label: "Veröffentlicht",
|
||||
access: {
|
||||
update: ({ req: { user } }) => Boolean(user?.type === "admin"),
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "title",
|
||||
type: "text",
|
||||
required: true,
|
||||
unique: true,
|
||||
},
|
||||
{
|
||||
name: "department",
|
||||
type: "select",
|
||||
options: [
|
||||
{ label: "WI", value: "WI" },
|
||||
{ label: "CI", value: "CI" },
|
||||
{ label: "MD", value: "MD" },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "year",
|
||||
type: "text",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "issue",
|
||||
label: "Problemstellung",
|
||||
type: "textarea",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "goal",
|
||||
label: "Zielsetzung",
|
||||
type: "textarea",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "result",
|
||||
label: "Ergebnis",
|
||||
type: "textarea",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "technologies",
|
||||
@@ -75,7 +84,6 @@ export const Papers: CollectionConfig = {
|
||||
{
|
||||
name: "description",
|
||||
type: "text",
|
||||
required: true,
|
||||
admin: {
|
||||
placeholder: "... wurde für das Frontend verwendet",
|
||||
},
|
||||
@@ -90,32 +98,26 @@ export const Papers: CollectionConfig = {
|
||||
name: "image",
|
||||
type: "upload",
|
||||
relationTo: "media",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "description",
|
||||
type: "text",
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
name: "mentor",
|
||||
type: "text",
|
||||
label: "Betreuer",
|
||||
},
|
||||
{
|
||||
name: "authors",
|
||||
type: "array",
|
||||
label: "Projektmitglieder",
|
||||
required: true,
|
||||
fields: [
|
||||
{
|
||||
name: "profilePicture",
|
||||
type: "upload",
|
||||
relationTo: "media",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "user",
|
||||
type: "relationship",
|
||||
relationTo: "users",
|
||||
name: "name",
|
||||
type: "text",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
@@ -136,7 +138,6 @@ export const Papers: CollectionConfig = {
|
||||
{
|
||||
name: "description",
|
||||
type: "text",
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
validate: (authors) => {
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
import type { CollectionConfig } from 'payload'
|
||||
import type { CollectionConfig } from 'payload';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const filename = fileURLToPath(import.meta.url);
|
||||
const dirname = path.dirname(filename);
|
||||
|
||||
export const Users: CollectionConfig = {
|
||||
slug: 'users',
|
||||
admin: {
|
||||
useAsTitle: 'email',
|
||||
},
|
||||
access: {
|
||||
create: ({ req: { user } }) => Boolean(user && user.type === 'admin'),
|
||||
update: ({ req: { user } }) => {
|
||||
if (!user) return false;
|
||||
if(user.type === 'admin') return true;
|
||||
return false;
|
||||
},
|
||||
delete: ({ req: { user } }) => Boolean(user && user.type === 'admin'),
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'type',
|
||||
@@ -13,8 +27,26 @@ export const Users: CollectionConfig = {
|
||||
{ label: 'Admin', value: 'admin' },
|
||||
{ label: 'Schüler', value: 'student' },
|
||||
],
|
||||
}
|
||||
defaultValue: 'student',
|
||||
},
|
||||
{
|
||||
name: 'email',
|
||||
type: 'email',
|
||||
required: true,
|
||||
unique: true,
|
||||
|
||||
},
|
||||
{
|
||||
name: 'emailVerified',
|
||||
type: 'date',
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
name: 'image',
|
||||
type: 'text',
|
||||
required: false,
|
||||
},
|
||||
// Email added by default
|
||||
// Add more fields as needed
|
||||
],
|
||||
}
|
||||
};
|
||||
|
||||
@@ -123,29 +123,33 @@ export interface UserAuthOperations {
|
||||
*/
|
||||
export interface Paper {
|
||||
id: number;
|
||||
title: string;
|
||||
year: string;
|
||||
issue: string;
|
||||
goal: string;
|
||||
result: string;
|
||||
published?: boolean | null;
|
||||
title?: string | null;
|
||||
department?: ('WI' | 'CI' | 'MD') | null;
|
||||
year?: string | null;
|
||||
issue?: string | null;
|
||||
goal?: string | null;
|
||||
result?: string | null;
|
||||
technologies?:
|
||||
| {
|
||||
technology: number | Technology;
|
||||
description: string;
|
||||
description?: string | null;
|
||||
id?: string | null;
|
||||
}[]
|
||||
| null;
|
||||
prototype: {
|
||||
image: number | Media;
|
||||
description: string;
|
||||
prototype?: {
|
||||
image?: (number | null) | Media;
|
||||
description?: string | null;
|
||||
};
|
||||
authors: {
|
||||
profilePicture: number | Media;
|
||||
user: string | User;
|
||||
mentor?: string | null;
|
||||
authors?:
|
||||
| {
|
||||
name: string;
|
||||
position: 'leader' | 'member';
|
||||
description: string;
|
||||
description?: string | null;
|
||||
id?: string | null;
|
||||
}[];
|
||||
}[]
|
||||
| null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
@@ -356,7 +360,9 @@ export interface PayloadMigration {
|
||||
* via the `definition` "papers_select".
|
||||
*/
|
||||
export interface PapersSelect<T extends boolean = true> {
|
||||
published?: T;
|
||||
title?: T;
|
||||
department?: T;
|
||||
year?: T;
|
||||
issue?: T;
|
||||
goal?: T;
|
||||
@@ -374,11 +380,11 @@ export interface PapersSelect<T extends boolean = true> {
|
||||
image?: T;
|
||||
description?: T;
|
||||
};
|
||||
mentor?: T;
|
||||
authors?:
|
||||
| T
|
||||
| {
|
||||
profilePicture?: T;
|
||||
user?: T;
|
||||
name?: T;
|
||||
position?: T;
|
||||
description?: T;
|
||||
id?: T;
|
||||
|
||||
Reference in New Issue
Block a user