From 23a8bf752de384a373b5923d4dd7fe26d7a7a676 Mon Sep 17 00:00:00 2001 From: augurk Date: Tue, 24 Jan 2023 13:20:27 +0100 Subject: [PATCH] Feat: Adding the collections --- src/collections/Couriers.ts | 17 +++++++++ src/collections/Dispatches.ts | 67 +++++++++++++++++++++++++++++++++++ src/collections/Makers.ts | 32 +++++++++++++++++ src/collections/Products.ts | 20 +++++++++++ src/collections/Retailers.ts | 31 ++++++++++++++++ src/payload.config.ts | 13 +++++-- 6 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 src/collections/Couriers.ts create mode 100644 src/collections/Dispatches.ts create mode 100644 src/collections/Makers.ts create mode 100644 src/collections/Products.ts create mode 100644 src/collections/Retailers.ts diff --git a/src/collections/Couriers.ts b/src/collections/Couriers.ts new file mode 100644 index 0000000..35ec5d1 --- /dev/null +++ b/src/collections/Couriers.ts @@ -0,0 +1,17 @@ +import { CollectionConfig } from 'payload/types'; + +const Couriers: CollectionConfig = { + slug: 'couriers', + access: { + read: () => true, + }, + fields: [ + { + name: 'name', // required + type: 'text', // required + required: true, + }, + ], +}; + +export default Couriers; \ No newline at end of file diff --git a/src/collections/Dispatches.ts b/src/collections/Dispatches.ts new file mode 100644 index 0000000..8c36f75 --- /dev/null +++ b/src/collections/Dispatches.ts @@ -0,0 +1,67 @@ +import { CollectionConfig } from 'payload/types'; + +const Dispatches: CollectionConfig = { + slug: 'dispatches', +// admin: { +// useAsTitle: 'email', +// }, + access: { + read: () => true, + }, + fields: [ + { + name: 'dispatchesCode', + type: 'text', + required: true, + }, + { + name: 'products', + type: 'relationship', + relationTo: 'products', + hasMany: true, + }, + { + name: 'startingPoint', + type: 'relationship', + relationTo: 'makers', + hasMany: false, + }, + { + name: 'endPoint', + type: 'relationship', + relationTo: 'makers', + hasMany: false, + }, + { + name: 'courier', + type: 'relationship', + relationTo: 'couriers', + hasMany: false, + }, + { + name: 'status', // required + type: 'select', // required + hasMany: true, + // admin: { + // isClearable: true, + // isSortable: true, // use mouse to drag and drop different values, and sort them according to your choice + // }, + options: [ + { + label: 'Route requested', + value: 'routeRequested', + }, + { + label: 'In transit', + value: 'inTransit', + }, + { + label: 'Completed', + value: 'completed', + }, + ], + } + ], +}; + +export default Dispatches; \ No newline at end of file diff --git a/src/collections/Makers.ts b/src/collections/Makers.ts new file mode 100644 index 0000000..aa7d205 --- /dev/null +++ b/src/collections/Makers.ts @@ -0,0 +1,32 @@ +import { CollectionConfig } from 'payload/types'; + +const Makers: CollectionConfig = { + slug: 'makers', +// admin: { +// useAsTitle: 'email', +// }, + access: { + read: () => true, + }, + fields: [ + { + name: 'name', // required + type: 'text', // required + required: true, + }, + { + name: 'location', + type: 'point', + label: 'Location', + }, + { + name: 'products', // required + type: 'relationship', // required + relationTo: 'products', // required + hasMany: true, + // TODO: make the name of the product visible in the dropdown + } + ], +}; + +export default Makers; \ No newline at end of file diff --git a/src/collections/Products.ts b/src/collections/Products.ts new file mode 100644 index 0000000..c39c3d9 --- /dev/null +++ b/src/collections/Products.ts @@ -0,0 +1,20 @@ +import { CollectionConfig } from 'payload/types'; + +const Products: CollectionConfig = { + slug: 'products', +// admin: { +// useAsTitle: 'email', +// }, + access: { + read: () => true, + }, + fields: [ + { + name: 'productTitle', // required + type: 'text', // required + required: true, + }, + ], +}; + +export default Products; \ No newline at end of file diff --git a/src/collections/Retailers.ts b/src/collections/Retailers.ts new file mode 100644 index 0000000..d56014b --- /dev/null +++ b/src/collections/Retailers.ts @@ -0,0 +1,31 @@ +import { CollectionConfig } from 'payload/types'; + +const Retailers: CollectionConfig = { + slug: 'retailers', +// admin: { +// useAsTitle: 'email', +// }, + access: { + read: () => true, + }, + fields: [ + { + name: 'name', // required + type: 'text', // required + required: true, + }, + { + name: 'location', + type: 'point', + label: 'Location', + }, + { + name: 'products', // required + type: 'relationship', // required + relationTo: 'products', // required + hasMany: true, + } + ], +}; + +export default Retailers; \ No newline at end of file diff --git a/src/payload.config.ts b/src/payload.config.ts index f4b206e..e2075f0 100644 --- a/src/payload.config.ts +++ b/src/payload.config.ts @@ -2,6 +2,12 @@ import { buildConfig } from 'payload/config'; import path from 'path'; // import Examples from './collections/Examples'; import Users from './collections/Users'; +import Couriers from './collections/Couriers'; +import Dispatches from './collections/Dispatches'; +import Makers from './collections/Makers'; +import Products from './collections/Products'; +import Retailers from './collections/Retailers'; + export default buildConfig({ serverURL: 'http://localhost:3000', @@ -10,8 +16,11 @@ export default buildConfig({ }, collections: [ Users, - // Add Collections here - // Examples, + Couriers, + Dispatches, + Makers, + Products, + Retailers, ], typescript: { outputFile: path.resolve(__dirname, 'payload-types.ts'),