Feat: Adding the collections

This commit is contained in:
augurk 2023-01-24 13:20:27 +01:00
parent bdf11ce3b6
commit 23a8bf752d
6 changed files with 178 additions and 2 deletions

View File

@ -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;

View File

@ -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;

32
src/collections/Makers.ts Normal file
View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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'),