2016-12-13 11:32:23 +09:00
import { newMutation , editMutation , removeMutation } from 'meteor/nova:core' ;
2016-11-22 18:14:51 -05:00
import Users from 'meteor/nova:users' ;
const performCheck = ( mutation , user , document ) => {
2017-02-02 15:15:51 +01:00
if ( ! mutation . check ( user , document ) ) throw new Error ( Utils . encodeIntlError ( { id : ` app.mutation_not_allowed ` , value : ` " ${ mutation . name } " on _id " ${ document . _id } " ` } ) ) ;
2016-11-22 18:14:51 -05:00
} ;
const mutations = {
new : {
name : 'categoriesNew' ,
check ( user , document ) {
if ( ! user ) return false ;
return Users . canDo ( user , 'categories.new' ) ;
} ,
mutation ( root , { document } , context ) {
performCheck ( this , context . currentUser , document ) ;
return newMutation ( {
collection : context . Categories ,
document : document ,
currentUser : context . currentUser ,
2016-11-24 15:47:51 +09:00
validate : true ,
context ,
2016-11-22 18:14:51 -05:00
} ) ;
} ,
2016-11-07 23:04:41 +01:00
} ,
2016-11-22 18:14:51 -05:00
edit : {
name : 'categoriesEdit' ,
check ( user , document ) {
if ( ! user || ! document ) return false ;
return Users . canDo ( user , ` categories.edit.all ` ) ;
} ,
mutation ( root , { documentId , set , unset } , context ) {
const document = context . Categories . findOne ( documentId ) ;
performCheck ( this , context . currentUser , document ) ;
return editMutation ( {
collection : context . Categories ,
documentId : documentId ,
set : set ,
unset : unset ,
currentUser : context . currentUser ,
2016-11-24 15:47:51 +09:00
validate : true ,
context ,
2016-11-22 18:14:51 -05:00
} ) ;
} ,
2016-11-07 23:04:41 +01:00
} ,
2016-11-22 18:14:51 -05:00
remove : {
name : 'categoriesRemove' ,
check ( user , document ) {
if ( ! user || ! document ) return false ;
return Users . canDo ( user , ` categories.remove.all ` ) ;
} ,
mutation ( root , { documentId } , context ) {
const document = context . Categories . findOne ( documentId ) ;
performCheck ( this , context . currentUser , document ) ;
return removeMutation ( {
collection : context . Categories ,
documentId : documentId ,
currentUser : context . currentUser ,
2016-11-24 15:47:51 +09:00
validate : true ,
context ,
2016-11-22 18:14:51 -05:00
} ) ;
} ,
2016-11-07 23:04:41 +01:00
} ,
} ;
2017-02-02 15:15:51 +01:00
export default mutations ;