get_my/imports/api/stores.js
2025-06-21 07:28:59 -05:00

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({
'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 Stores.insertAsync({
storeName: storeName,
owner: this.userId,
});
},
'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 Stores.updateAsync({ _id: storeId }, {
$set: {
storeName: storeName,
}
});
},
'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 Stores.removeAsync({ _id: storeId });
},
});