mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 00:08:49 +00:00
My big initial commit to this repo and project.
This commit is contained in:
parent
750811a81f
commit
8636f8cf9b
2433 changed files with 199488 additions and 1042 deletions
61
imports/api/stores.js
Normal file
61
imports/api/stores.js
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
|
||||
export const Stores = new Mongo.Collection('stores');
|
||||
|
||||
Stores.allow({
|
||||
insert: function(userId, doc){
|
||||
// if use id exists, allow insert
|
||||
return !!userId;
|
||||
},
|
||||
});
|
||||
|
||||
Meteor.methods({
|
||||
'add.store' (storeName, storeType) {
|
||||
check(storeName, String);
|
||||
check(storeType, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to add stores. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
return Stores.insert({
|
||||
storeName: storeName,
|
||||
storeType: storeType,
|
||||
owner: this.userid,
|
||||
});
|
||||
},
|
||||
'edit.store' (storeId, storeName, storeType) {
|
||||
check(storeId, String);
|
||||
check(storeName, String);
|
||||
check(storeType, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to edit stores. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
return Stores.update({ _id: storeId }, {
|
||||
$set: {
|
||||
storeName: storeName,
|
||||
storeType: storeType,
|
||||
}
|
||||
});
|
||||
},
|
||||
'delete.store' (storeId) {
|
||||
check(storeId, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to delete stores. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
let storeInfo = Stores.findOne({ _id: storeId });
|
||||
let myId = this.userId;
|
||||
if (myId == storeInfo.owner) {
|
||||
return Stores.remove({ _id: storeId });
|
||||
} else {
|
||||
console.log("User not allowed to delete this store. Not the owner!");
|
||||
return("Not Allowed!");
|
||||
}
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue