mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-26 15:58:50 +00:00
50 lines
No EOL
1.4 KiB
JavaScript
50 lines
No EOL
1.4 KiB
JavaScript
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({
|
|
async 'add.store' (storeName) {
|
|
check(storeName, 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 await Stores.insertAsync({
|
|
storeName: storeName,
|
|
owner: this.userId,
|
|
});
|
|
},
|
|
async 'edit.store' (storeId, storeName) {
|
|
check(storeId, String);
|
|
check(storeName, 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 await Stores.updateAsync({ _id: storeId }, {
|
|
$set: {
|
|
storeName: storeName,
|
|
}
|
|
});
|
|
},
|
|
async '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.');
|
|
}
|
|
|
|
return await Stores.removeAsync({ _id: storeId });
|
|
},
|
|
}); |