Commit e355d3fb authored by Jarrod's avatar Jarrod 💬

Forum boilerplate

parent bb6c09c7
......@@ -3,7 +3,7 @@ module.exports = {
description: 'Index something.',
inputs: {
slug: {
id: {
type: 'string',
required: true
}
......@@ -14,9 +14,10 @@ module.exports = {
},
fn: async function (inputs) {
let thread = await ForumThread.findOne({ id: inputs.id })
// All done.
return 'Forum thread';
return {
thread
};
}
};
......@@ -14,9 +14,13 @@ module.exports = {
},
fn: async function (inputs) {
const topic = await ForumTopic
.findOne({ slug: inputs.slug })
.populate('threads')
// All done.
return 'Forum topic';
return {
topic
};
}
};
module.exports = {
friendlyName: 'Forum Index',
description: 'Index something.',
description: 'Index of a forum or something.',
inputs: {
page: {
......@@ -16,9 +16,11 @@ module.exports = {
},
fn: async function (inputs) {
const topics = await ForumTopic.find()
// All done.
return 'Forum index';
return {
topics
};
}
};
......@@ -8,9 +8,10 @@ module.exports = new Pluggable({
dir: __dirname,
actions: {
'GET /': { action: 'index', cache: 30 },
'GET /:slug': { action: 'get-topic', cache: 30 },
'POST /': { action: 'create-topic', cache: 30 },
'GET /:topic/:thread': { action: 'get-thread', cache: 30 },
// 'GET /': { action: 'list-topics', cache: 10 },
'GET /topic': { action: 'list-topics', cache: 10 },
'GET /topic/:slug': { action: 'get-topic', cache: 10 },
'POST /topic': { action: 'create-topic', cache: 10 },
'GET /thread/:id': { action: 'get-thread', cache: 10 },
}
})
/**
* ForumThread.js
*
* A forum thread
*/
module.exports = {
attributes: {
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
title: {
type: 'string',
required: true,
description: 'Title of the topic'
},
content: {
type: 'string',
required: true,
description: 'Question/topic body'
},
user: {
model: 'user'
},
topic: {
model: 'forumtopic'
}
},
extend: {
user: {
forumTopics: {
collection: 'forumthread',
via: 'user'
}
}
}
};
/**
* ForumTopic.js
*
* A forum topic
*/
module.exports = {
attributes: {
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
title: {
type: 'string',
required: true,
description: 'Title of the topic'
},
description: {
type: 'string',
required: true,
description: 'Description of this topic'
},
slug: {
type: 'string',
required: true,
description: 'URL slug for this forum topic'
},
threads: {
collection: 'forumthread',
via: 'topic'
}
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment