parse-cloud-classes
v1.0.1
Published
Easily extend parse cloud triggers behaviour
Maintainers
Readme
Parse Cloud Classes
Easily extend parse cloud triggers behaviour
An easy way to extend parse cloud triggers behaviour
Installation
npm i parse-cloud-classesExample
A working example can be found here
Supported versions
- parse-server >= 3.0.0
- node >= 6.4
Basic Usage
//parse cloud code file
const ParseClass = require('parse-cloud-classes')
const Joi = require('joi')
//validation service
const validation = async req => {
const { object } = req
const { error } = Joi.validate(object.toJSON(), validationSchema)
if (error) throw error.details[0].message
return req.object
}
//sendWelcomeMail service
const sendWelcomeMail = async req => {
const { object } = req
if (!object.existed()) {
//send welcome email here
}
}
//analytics service
analytics = {
afterDelete: async req => {
const analytic = new Parse.Object('Analytic')
analytic.set('event', 'deleted')
analytic.set('object', {
className: req.object.className,
id: req.object.id,
})
await analytic.save({}, { userMasterKey: true })
},
afterSave: async req => {
const analytic = new Parse.Object('Analytic')
analytic.set('event', 'created')
analytic.set('object', {
className: req.object.className,
id: req.object.id,
})
await analytic.save({}, { userMasterKey: true })
},
}
new ParseClass(Parse.User)
.beforeSave([validation])
.afterSave([analytics.afterSave, sendWelcomeMail])
.afterDelete([analytics.afterDelete])
.beforeDelete([
async req => {
if (!req.master) throw 'unauthorized'
return req.object
},
])Development setup
npm install && npm run devContribution
- Fork the project
- Create your feature branch (
git checkout -b feature/fooBar), or hotfix branch (git checkout -b hotfix/fooBar) - Commit your changes (
npm run cz) - Push to the feature branch (
git push origin feature/fooBar), or hotfix branch (git push origin hotfix/fooBar) - Create a new Pull Request
License
This project is licensed under the MIT License, See LICENSE for more information
