feat: create basic book and authur

This commit is contained in:
Yehoshua Sandler 2025-04-10 16:00:25 -05:00
parent 66c4c17887
commit 828ec41a8b
5 changed files with 114 additions and 9 deletions

View File

@ -1 +1,5 @@
export const importMap = {}
export const importMap = {
}

View File

@ -2,15 +2,37 @@ import type { CollectionConfig } from 'payload'
export const Authors: CollectionConfig = { export const Authors: CollectionConfig = {
slug: 'authors', slug: 'authors',
admin: {
useAsTitle: 'lf'
},
fields: [ fields: [
{ {
name: 'firstName', name: 'lf',
label: 'last, first name',
type: 'text',
required: true,
unique: true,
index: true,
},
{
name: 'fl',
label: 'First and Last Name',
type: 'text', type: 'text',
}, },
{ {
name: 'lastName', name: "role",
type: 'text', type: 'select',
required: true, options: [
{
label: 'Author',
value: 'Author'
},
{
label: 'Translator',
value: 'Translator'
}, },
], ],
} }
],
}

View File

@ -6,10 +6,22 @@ export const Books: CollectionConfig = {
{ {
name: "books_id", // This is from the import name: "books_id", // This is from the import
type: "text", type: "text",
unique: true,
admin: {
placeholder: "This is only for books that have been imported.",
//readOnly: true,
}
}, },
{ {
name: "title", name: "title",
type: "text", type: "text",
}, },
{
name: "authors",
type: "relationship",
relationTo: "authors",
hasMany: true,
maxDepth: 200,
}
], ],
} }

View File

@ -69,6 +69,8 @@ export interface Config {
collections: { collections: {
users: User; users: User;
media: Media; media: Media;
books: Book;
authors: Author;
'payload-locked-documents': PayloadLockedDocument; 'payload-locked-documents': PayloadLockedDocument;
'payload-preferences': PayloadPreference; 'payload-preferences': PayloadPreference;
'payload-migrations': PayloadMigration; 'payload-migrations': PayloadMigration;
@ -77,6 +79,8 @@ export interface Config {
collectionsSelect: { collectionsSelect: {
users: UsersSelect<false> | UsersSelect<true>; users: UsersSelect<false> | UsersSelect<true>;
media: MediaSelect<false> | MediaSelect<true>; media: MediaSelect<false> | MediaSelect<true>;
books: BooksSelect<false> | BooksSelect<true>;
authors: AuthorsSelect<false> | AuthorsSelect<true>;
'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>; 'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>;
'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>; 'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>;
'payload-migrations': PayloadMigrationsSelect<false> | PayloadMigrationsSelect<true>; 'payload-migrations': PayloadMigrationsSelect<false> | PayloadMigrationsSelect<true>;
@ -149,6 +153,30 @@ export interface Media {
focalX?: number | null; focalX?: number | null;
focalY?: number | null; focalY?: number | null;
} }
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "books".
*/
export interface Book {
id: number;
books_id?: string | null;
title?: string | null;
authors?: (number | Author)[] | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "authors".
*/
export interface Author {
id: number;
lf: string;
fl?: string | null;
role?: ('Author' | 'Translator') | null;
updatedAt: string;
createdAt: string;
}
/** /**
* This interface was referenced by `Config`'s JSON-Schema * This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-locked-documents". * via the `definition` "payload-locked-documents".
@ -163,6 +191,14 @@ export interface PayloadLockedDocument {
| ({ | ({
relationTo: 'media'; relationTo: 'media';
value: number | Media; value: number | Media;
} | null)
| ({
relationTo: 'books';
value: number | Book;
} | null)
| ({
relationTo: 'authors';
value: number | Author;
} | null); } | null);
globalSlug?: string | null; globalSlug?: string | null;
user: { user: {
@ -239,6 +275,28 @@ export interface MediaSelect<T extends boolean = true> {
focalX?: T; focalX?: T;
focalY?: T; focalY?: T;
} }
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "books_select".
*/
export interface BooksSelect<T extends boolean = true> {
books_id?: T;
title?: T;
authors?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "authors_select".
*/
export interface AuthorsSelect<T extends boolean = true> {
lf?: T;
fl?: T;
role?: T;
updatedAt?: T;
createdAt?: T;
}
/** /**
* This interface was referenced by `Config`'s JSON-Schema * This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-locked-documents_select". * via the `definition` "payload-locked-documents_select".

View File

@ -1,6 +1,5 @@
// storage-adapter-import-placeholder // storage-adapter-import-placeholder
import { postgresAdapter } from '@payloadcms/db-postgres' import { postgresAdapter } from '@payloadcms/db-postgres'
import { payloadCloudPlugin } from '@payloadcms/payload-cloud'
import { lexicalEditor } from '@payloadcms/richtext-lexical' import { lexicalEditor } from '@payloadcms/richtext-lexical'
import path from 'path' import path from 'path'
import { buildConfig } from 'payload' import { buildConfig } from 'payload'
@ -9,6 +8,8 @@ import sharp from 'sharp'
import { Users } from './collections/Users' import { Users } from './collections/Users'
import { Media } from './collections/Media' import { Media } from './collections/Media'
import { Books } from './collections/Books/Books'
import { Authors } from './collections/Authors/Authors'
const filename = fileURLToPath(import.meta.url) const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename) const dirname = path.dirname(filename)
@ -19,8 +20,16 @@ export default buildConfig({
importMap: { importMap: {
baseDir: path.resolve(dirname), baseDir: path.resolve(dirname),
}, },
dateFormat: 'MM/dd/yyyy',
}, },
collections: [Users, Media], cors: [process.env.DOMAIN_NAME || ''],
csrf: [process.env.DOMAIN_NAME || ''],
upload: {
limits: {
fileSize: 5000000, // in bytes
},
},
collections: [Users, Media, Books, Authors],
editor: lexicalEditor(), editor: lexicalEditor(),
secret: process.env.PAYLOAD_SECRET || '', secret: process.env.PAYLOAD_SECRET || '',
typescript: { typescript: {
@ -33,7 +42,7 @@ export default buildConfig({
}), }),
sharp, sharp,
plugins: [ plugins: [
payloadCloudPlugin(), //payloadCloudPlugin(),
// storage-adapter-placeholder // storage-adapter-placeholder
], ],
}) })