Commit d1128965 authored by Jarrod's avatar Jarrod 💬

First commit comments

parent d00ddc7a
################################################
# ┌─┐┬┌┬┐╦╔═╗╔╗╔╔═╗╦═╗╔═╗
# │ ┬│ │ ║║ ╦║║║║ ║╠╦╝║╣
# o└─┘┴ ┴ ╩╚═╝╝╚╝╚═╝╩╚═╚═╝
#
# > Files to exclude from your app's repo.
#
# This file (`.gitignore`) is only relevant if
# you are using git.
#
# It exists to signify to git that certain files
# and/or directories should be ignored for the
# purposes of version control.
#
# This keeps tmp files and sensitive credentials
# from being uploaded to your repository. And
# it allows you to configure your app for your
# machine without accidentally committing settings
# which will smash the local settings of other
# developers on your team.
#
# Some reasonable defaults are included below,
# but, of course, you should modify/extend/prune
# to fit your needs!
#
################################################
package-lock.json
################################################
# Local Configuration
#
# Explicitly ignore files which contain:
#
# 1. Sensitive information you'd rather not push to
# your git repository.
# e.g., your personal API keys or passwords.
#
# 2. Developer-specific configuration
# Basically, anything that would be annoying
# to have to change every time you do a
# `git pull` on your laptop.
# e.g. your local development database, or
# the S3 bucket you're using for file uploads
# during development.
#
################################################
config/local.js
################################################
# Dependencies
#
#
# When releasing a production app, you _could_
# hypothetically include your node_modules folder
# in your git repo, but during development, it
# is always best to exclude it, since different
# developers may be working on different kernels,
# where dependencies would need to be recompiled
# anyway.
#
# Most of the time, the node_modules folder can
# be excluded from your code repository, even
# in production, thanks to features like the
# package-lock.json file / NPM shrinkwrap.
#
# But no matter what, since this is a Sails app,
# you should always push up the package-lock.json
# or shrinkwrap file to your repository, to avoid
# accidentally pulling in upgraded dependencies
# and breaking your code.
#
# That said, if you are having trouble with
# dependencies, (particularly when using
# `npm link`) this can be pretty discouraging.
# But rather than just adding the lockfile to
# your .gitignore, try this first:
# ```
# rm -rf node_modules
# rm package-lock.json
# npm install
# ```
#
# [?] For more tips/advice, come by and say hi
# over at https://sailsjs.com/support
#
################################################
node_modules
################################################
#
# > Do you use bower?
# > re: the bower_components dir, see this:
# > http://addyosmani.com/blog/checking-in-front-end-dependencies/
# > (credit Addy Osmani, @addyosmani)
#
################################################
################################################
# Temporary files generated by Sails/Waterline.
################################################
.tmp
################################################
# Miscellaneous
#
# Common files generated by text editors,
# operating systems, file systems, dbs, etc.
################################################
*~
*#
.DS_STORE
.netbeans
nbproject
.idea
*.iml
.vscode
.node_history
dump.rdb
npm-debug.log
lib-cov
*.seed
*.log
*.out
*.pid
module.exports = {
friendlyName: 'Add a comment',
inputs: {
zone: {
type: 'string',
required: true,
isIn: ['article', 'song', '???']
},
id: {
type: 'string',
required: true
},
comment: {
type: 'string',
required: true
}
},
exits: {
created: {
statusCode: 201,
description: `Comment was successfully added`
}
},
fn: async function (inputs) {
const payload = Object.assign({}, inputs)
payload.user = this.req.me
let comment = await Comment.create(payload).fetch()
// All done.
return exits.created({ comment });
}
};
module.exports = {
friendlyName: 'Delete a comment',
// description: '',
inputs: {
id: {
type: 'number',
isInteger: true,
defaultsTo: 1,
min: 1
}
},
exits: {
},
fn: async function (inputs) {
const { req, res } = this
let where = { id: inputs.id }
if (!req.me.isAdmin) {
where.user = req.me.id
}
let comment = await Comment.findOne({ where })
if (!comment) {
return res.badRequest(`Unable to delete comment ${inputs.id}`)
}
let deleted = await Comment.destroy({ where })
// All done.
return {
message: 'Deleted comment'
};
}
};
module.exports = {
friendlyName: 'Update a comment',
inputs: {
id: {
type: 'string',
required: true
},
comment: {
type: 'string',
required: true
}
},
exits: {
},
fn: async function (inputs) {
const where = { id: inputs.id }
if (!this.req.me.isAdmin) {
where.user = this.req.me.id
}
let comment = await Comment.findOne({ where })
if (!comment) {
return res.badRequest(`Unable to update comment`)
}
// TODO: Add "pending"/spam status something something
const payload = { comment: inputs.comment }
comment = await Comment.updateOne({ id: comment.id })
.set(payload)
// All done.
return exits.created({ comment });
}
};
/**
* Forum
*/
const Pluggable = require('@nahanil/ahoy/lib/pluggable')
module.exports = new Pluggable({
apiBase: 'comment',
dir: __dirname,
actions: {
'POST /': {
name: 'addComment',
action: 'add-comment',
auth: true
},
'PUT /:id': {
name: 'updateComment',
action: 'update-comment',
auth: true
},
'DELETE /:id': {
name: 'deleteComment',
action: 'delete-comment',
auth: true
},
}
})
/**
* Comment.js
*
* A comment
*/
module.exports = {
attributes: {
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
zone: {
type: 'string',
required: true,
description: '"Zone" of the comment, ie "blog"'
},
comment: {
type: 'string',
required: true,
description: 'Comment text'
},
user: {
model: 'user'
}
},
extend: {
user: {
comments: {
collection: 'comment',
via: 'user'
}
}
}
};
{
"name": "@nahanil/ahoy-comments",
"version": "1.0.0",
"description": "",
"main": "lib/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"sails": {
"isHook": true,
"hookName": "comments"
},
"author": "Jarrod Linahan",
"license": "MIT"
}
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