diff --git a/demo/Category/Category.model.js b/demo/Category/Category.model.js deleted file mode 100644 index 7865fb2dce..0000000000 --- a/demo/Category/Category.model.js +++ /dev/null @@ -1,33 +0,0 @@ -import mongoose from 'mongoose'; -import autopopulate from '../../src/plugins/autopopulate'; -import buildQuery from '../../src/plugins/buildQuery'; -import paginate from '../../src/plugins/paginate'; -import internationalization from '../../src/plugins/internationalization'; -import payloadConfig from '.././payload.config'; -import { schemaBaseFields } from '../../src/helpers/mongoose/schemaBaseFields'; - -const CategorySchema = new mongoose.Schema({ - ...schemaBaseFields, - title: { type: String, intl: true, unique: true }, - description: { type: String, intl: true }, - pages: [{ - type: mongoose.Schema.Types.ObjectId, - ref: 'Page', - autopopulate: true - }], -}, - { timestamps: true } -); - -CategorySchema.plugin(paginate); -CategorySchema.plugin(buildQuery); -CategorySchema.plugin(internationalization, payloadConfig.localization); -CategorySchema.plugin(autopopulate); - -// CategorySchema.post('find', function (results) { -// results.forEach(doc => { -// doc.setLocale(this.options.autopopulate.locale) -// }) -// }); - -module.exports = mongoose.model('Category', CategorySchema); diff --git a/demo/Category/Category.policy.js b/demo/Category/Category.policy.js deleted file mode 100644 index 2cdf8d3092..0000000000 --- a/demo/Category/Category.policy.js +++ /dev/null @@ -1,23 +0,0 @@ -import Category from './Category.model'; - -const categoryPolicy = { - - read(req, res, next) { - next(); - }, - - create(req, res, next) { - // TODO: how to get current authenticated user? - next(); - }, - - update(req, res, next) { - next(); - }, - - destroy(req, res, next) { - next(); - }, -}; - -export default categoryPolicy; diff --git a/demo/Category/Category.resolvers.js b/demo/Category/Category.resolvers.js deleted file mode 100644 index c2e4c86561..0000000000 --- a/demo/Category/Category.resolvers.js +++ /dev/null @@ -1,40 +0,0 @@ -import Category from './Category.model'; -import { modelById, find, create } from '../../src/resolvers'; - -export default { - Query: { - category: async (parent, args) => { - - const query = { - Model: Category, - id: args.id, - locale: args.locale, - fallback: args['fallbackLocale'] - }; - - return await modelById(query); - }, - categories: async (parent, args) => { - - const query = { - Model: Category, - locale: args.locale, - fallback: args['fallbackLocale'] - }; - - return await find(query); - } - }, - Mutation: { - createCategory: async (parent, args) => { - - const query = { - Model: Category, - locale: args.locale, - input: args.input - }; - - return await create(query) - } - } -} diff --git a/demo/Category/Category.routes.js b/demo/Category/Category.routes.js deleted file mode 100644 index 15134cec6a..0000000000 --- a/demo/Category/Category.routes.js +++ /dev/null @@ -1,23 +0,0 @@ -import express from 'express'; -import bindModel from '../../src/middleware/bindModel'; -import { query, create, findOne, destroy, update } from '../../src/requestHandlers'; - -import Category from './Category.model'; -import categoryPolicy from './Category.policy'; - -const categoryRoutes = express.Router(); // eslint-disable-line new-cap - -categoryRoutes.all('*', bindModel(Category)); - -categoryRoutes - .route('') - .get(categoryPolicy.read, query) - .post(categoryPolicy.create, create); - -categoryRoutes - .route('/:_id') - .get(categoryPolicy.read, findOne) - .put(categoryPolicy.update, update) - .delete(categoryPolicy.destroy, destroy); - -export { categoryRoutes }; diff --git a/demo/Category/Category.types.js b/demo/Category/Category.types.js deleted file mode 100644 index 1dc2c155ac..0000000000 --- a/demo/Category/Category.types.js +++ /dev/null @@ -1,23 +0,0 @@ -export default ` - input CategoryInput { - title: String! - description: String - } - - type Category { - id: String - title: String - description: String - createdAt: String - updatedAt: String - } - - type Query { - category(id: String!, locale: String): Category - categories(locale: String): [Category] - } - - type Mutation { - createCategory(input: CategoryInput): Category - } -`; diff --git a/demo/app.js b/demo/app.js index 0cfcff2fe3..3f76d8f0b2 100644 --- a/demo/app.js +++ b/demo/app.js @@ -6,6 +6,7 @@ import payloadConfig from './payload.config'; import { authRoutes } from './Auth/Auth.routes'; import { userRoutes } from './User/User.routes'; import Page from './config/Page'; +import Category from './config/Category'; const router = express.Router({}); // eslint-disable-line new-cap @@ -14,6 +15,7 @@ export const app = express(); new Payload({ models: [ Page, + Category ], config: payloadConfig, app: app, diff --git a/demo/Category/Category.config.js b/demo/config/Category.js similarity index 52% rename from demo/Category/Category.config.js rename to demo/config/Category.js index 69e5841426..cd082bdd0e 100644 --- a/demo/Category/Category.config.js +++ b/demo/config/Category.js @@ -1,9 +1,25 @@ export default { slug: 'categories', label: 'Categories', - singular: 'Category', - plural: 'Categories', + labels: { + singular: 'Category', + plural: 'Categories', + }, useAsTitle: 'title', + policies: { + create: (req, res, next) => { + return next(); + }, + read: (req, res, next) => { + return next(); + }, + update: (req, res, next) => { + return next(); + }, + destroy: (req, res, next) => { + return next(); + }, + }, fields: [ { name: 'title', diff --git a/package.json b/package.json index fc13bbe385..1de4a9ec8a 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "http-status": "^1.2.0", "ignore-styles": "^5.0.1", "image-size": "^0.7.1", + "joi": "^14.3.1", "jsonwebtoken": "^8.4.0", "merge-graphql-schemas": "^1.5.8", "method-override": "^3.0.0",