From 797054a550112f47e85d1fe05db6484c7deed8bc Mon Sep 17 00:00:00 2001 From: Yehoshua Sandler Date: Thu, 10 Apr 2025 19:19:36 -0500 Subject: [PATCH] feat: created core collections --- src/app/(payload)/admin/importMap.js | 46 ++++++- src/collections/Authors/Authors.ts | 3 +- src/collections/Books/Books.ts | 43 +++++- src/collections/Books/Genre.ts | 13 ++ src/collections/Copies/Copies.ts | 30 +++++ src/collections/Repositories/Repositories.ts | 35 +++++ src/payload-types.ts | 130 +++++++++++++++++++ src/payload.config.ts | 5 +- 8 files changed, 298 insertions(+), 7 deletions(-) create mode 100644 src/collections/Books/Genre.ts create mode 100644 src/collections/Copies/Copies.ts create mode 100644 src/collections/Repositories/Repositories.ts diff --git a/src/app/(payload)/admin/importMap.js b/src/app/(payload)/admin/importMap.js index a3bc0e8..dfe0789 100644 --- a/src/app/(payload)/admin/importMap.js +++ b/src/app/(payload)/admin/importMap.js @@ -1,5 +1,47 @@ - +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 { HorizontalRuleFeatureClient as HorizontalRuleFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { UploadFeatureClient as UploadFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { BlockquoteFeatureClient as BlockquoteFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { RelationshipFeatureClient as RelationshipFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { LinkFeatureClient as LinkFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { ChecklistFeatureClient as ChecklistFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { OrderedListFeatureClient as OrderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { UnorderedListFeatureClient as UnorderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { IndentFeatureClient as IndentFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { AlignFeatureClient as AlignFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { HeadingFeatureClient as HeadingFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { ParagraphFeatureClient as ParagraphFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { InlineCodeFeatureClient as InlineCodeFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { SuperscriptFeatureClient as SuperscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { SubscriptFeatureClient as SubscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { StrikethroughFeatureClient as StrikethroughFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { UnderlineFeatureClient as UnderlineFeatureClient_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' 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#HorizontalRuleFeatureClient": HorizontalRuleFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#UploadFeatureClient": UploadFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#BlockquoteFeatureClient": BlockquoteFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#RelationshipFeatureClient": RelationshipFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#LinkFeatureClient": LinkFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#ChecklistFeatureClient": ChecklistFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#OrderedListFeatureClient": OrderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#UnorderedListFeatureClient": UnorderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#IndentFeatureClient": IndentFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#AlignFeatureClient": AlignFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#HeadingFeatureClient": HeadingFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#ParagraphFeatureClient": ParagraphFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#InlineCodeFeatureClient": InlineCodeFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#SuperscriptFeatureClient": SuperscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#SubscriptFeatureClient": SubscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#StrikethroughFeatureClient": StrikethroughFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#UnderlineFeatureClient": UnderlineFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#BoldFeatureClient": BoldFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#ItalicFeatureClient": ItalicFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } diff --git a/src/collections/Authors/Authors.ts b/src/collections/Authors/Authors.ts index c1dde26..66d7cc1 100644 --- a/src/collections/Authors/Authors.ts +++ b/src/collections/Authors/Authors.ts @@ -12,7 +12,6 @@ export const Authors: CollectionConfig = { label: 'last, first name', type: 'text', required: true, - unique: true, index: true, }, { @@ -33,6 +32,6 @@ export const Authors: CollectionConfig = { value: 'Translator' }, ], - } + }, ], } diff --git a/src/collections/Books/Books.ts b/src/collections/Books/Books.ts index 88ec9c5..72d8293 100644 --- a/src/collections/Books/Books.ts +++ b/src/collections/Books/Books.ts @@ -2,6 +2,9 @@ import { CollectionConfig } from "payload"; export const Books: CollectionConfig = { slug: "books", + admin: { + useAsTitle: 'title' + }, fields: [ { name: "books_id", // This is from the import @@ -21,7 +24,43 @@ export const Books: CollectionConfig = { type: "relationship", relationTo: "authors", hasMany: true, - maxDepth: 200, - } + }, + { + name: 'pages', + type: 'number', + }, + { + name: 'lcc', + type: 'text', + unique: true, + }, + { + name: 'publication', + type: 'text', + }, + { + label: 'Publication Date', + name: 'date', + type: 'date', + admin: { + date: { + pickerAppearance: 'dayOnly' + } + }, + }, + { + name: 'genre', + type: 'relationship', + relationTo: 'genre', + hasMany: true, + admin: { + allowEdit: true, + allowCreate: true + } + }, + { + name: 'description', + type: 'richText' + }, ], } diff --git a/src/collections/Books/Genre.ts b/src/collections/Books/Genre.ts new file mode 100644 index 0000000..89aebb4 --- /dev/null +++ b/src/collections/Books/Genre.ts @@ -0,0 +1,13 @@ +import { CollectionConfig } from "payload"; + +export const Genre: CollectionConfig = { + slug: 'genre', + fields: [ + { + name: 'name', + type: 'text', + unique: true, + required: true, + } + ] +} diff --git a/src/collections/Copies/Copies.ts b/src/collections/Copies/Copies.ts new file mode 100644 index 0000000..30bffb5 --- /dev/null +++ b/src/collections/Copies/Copies.ts @@ -0,0 +1,30 @@ +import { CollectionConfig } from "payload"; + +export const Copies: CollectionConfig = { + slug: 'copies', + fields: [ + { + name: 'condition', + label: 'Condition out of 5', + type: 'number', + min: 1, + max: 5, + }, + { + name: 'book', + type: 'relationship', + relationTo: 'books', + hasMany: false, + }, + { + name: 'repository', + type: 'relationship', + relationTo: 'repositories', + hasMany: false, + }, + { + name: 'notes', + type: 'richText' + } + ] +} diff --git a/src/collections/Repositories/Repositories.ts b/src/collections/Repositories/Repositories.ts new file mode 100644 index 0000000..1bccf02 --- /dev/null +++ b/src/collections/Repositories/Repositories.ts @@ -0,0 +1,35 @@ +import { CollectionConfig } from "payload"; + +export const Repositories: CollectionConfig = { + slug: 'repositories', admin: { + useAsTitle: 'name' + }, + fields: [ + { + name: 'name', + type: 'text', + required: true, + unique: true + }, + { + name: 'abbreviation', + type: 'text', + required: true, + unique: true, + admin: { + description: 'This is used to help identify which copies belong to this repo.' + } + }, + { + name: 'owner', + type: 'relationship', + relationTo: 'users', + hasMany: true, + required: true, + }, + { + name: 'dateOpenToPublic', + type: 'date' + } + ] +} diff --git a/src/payload-types.ts b/src/payload-types.ts index 2576947..fae681c 100644 --- a/src/payload-types.ts +++ b/src/payload-types.ts @@ -71,6 +71,9 @@ export interface Config { media: Media; books: Book; authors: Author; + repositories: Repository; + copies: Copy; + genre: Genre; 'payload-locked-documents': PayloadLockedDocument; 'payload-preferences': PayloadPreference; 'payload-migrations': PayloadMigration; @@ -81,6 +84,9 @@ export interface Config { media: MediaSelect | MediaSelect; books: BooksSelect | BooksSelect; authors: AuthorsSelect | AuthorsSelect; + repositories: RepositoriesSelect | RepositoriesSelect; + copies: CopiesSelect | CopiesSelect; + genre: GenreSelect | GenreSelect; 'payload-locked-documents': PayloadLockedDocumentsSelect | PayloadLockedDocumentsSelect; 'payload-preferences': PayloadPreferencesSelect | PayloadPreferencesSelect; 'payload-migrations': PayloadMigrationsSelect | PayloadMigrationsSelect; @@ -162,6 +168,26 @@ export interface Book { books_id?: string | null; title?: string | null; authors?: (number | Author)[] | null; + pages?: number | null; + lcc?: string | null; + publication?: string | null; + date?: string | null; + genre?: (number | Genre)[] | null; + description?: { + root: { + type: string; + children: { + type: string; + version: number; + [k: string]: unknown; + }[]; + direction: ('ltr' | 'rtl') | null; + format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + indent: number; + version: number; + }; + [k: string]: unknown; + } | null; updatedAt: string; createdAt: string; } @@ -177,6 +203,59 @@ export interface Author { updatedAt: string; createdAt: string; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "genre". + */ +export interface Genre { + id: number; + name: string; + updatedAt: string; + createdAt: string; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "repositories". + */ +export interface Repository { + id: number; + name: string; + /** + * This is used to help identify which copies belong to this repo. + */ + abbreviation: string; + owner: (number | User)[]; + dateOpenToPublic?: string | null; + updatedAt: string; + createdAt: string; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "copies". + */ +export interface Copy { + id: number; + condition?: number | null; + book?: (number | null) | Book; + repository?: (number | null) | Repository; + notes?: { + root: { + type: string; + children: { + type: string; + version: number; + [k: string]: unknown; + }[]; + direction: ('ltr' | 'rtl') | null; + format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + indent: number; + version: number; + }; + [k: string]: unknown; + } | null; + updatedAt: string; + createdAt: string; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "payload-locked-documents". @@ -199,6 +278,18 @@ export interface PayloadLockedDocument { | ({ relationTo: 'authors'; value: number | Author; + } | null) + | ({ + relationTo: 'repositories'; + value: number | Repository; + } | null) + | ({ + relationTo: 'copies'; + value: number | Copy; + } | null) + | ({ + relationTo: 'genre'; + value: number | Genre; } | null); globalSlug?: string | null; user: { @@ -283,6 +374,12 @@ export interface BooksSelect { books_id?: T; title?: T; authors?: T; + pages?: T; + lcc?: T; + publication?: T; + date?: T; + genre?: T; + description?: T; updatedAt?: T; createdAt?: T; } @@ -297,6 +394,39 @@ export interface AuthorsSelect { updatedAt?: T; createdAt?: T; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "repositories_select". + */ +export interface RepositoriesSelect { + name?: T; + abbreviation?: T; + owner?: T; + dateOpenToPublic?: T; + updatedAt?: T; + createdAt?: T; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "copies_select". + */ +export interface CopiesSelect { + condition?: T; + book?: T; + repository?: T; + notes?: T; + updatedAt?: T; + createdAt?: T; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "genre_select". + */ +export interface GenreSelect { + name?: T; + updatedAt?: T; + createdAt?: T; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "payload-locked-documents_select". diff --git a/src/payload.config.ts b/src/payload.config.ts index f844eb8..50ca5d6 100644 --- a/src/payload.config.ts +++ b/src/payload.config.ts @@ -10,6 +10,9 @@ import { Users } from './collections/Users' import { Media } from './collections/Media' import { Books } from './collections/Books/Books' import { Authors } from './collections/Authors/Authors' +import { Repositories } from './collections/Repositories/Repositories' +import { Copies } from './collections/Copies/Copies' +import { Genre } from './collections/Books/Genre' const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) @@ -29,7 +32,7 @@ export default buildConfig({ fileSize: 5000000, // in bytes }, }, - collections: [Users, Media, Books, Authors], + collections: [Users, Media, Books, Authors, Repositories, Copies, Genre], editor: lexicalEditor(), secret: process.env.PAYLOAD_SECRET || '', typescript: {