Hi,
Is it possible to use then/catch on a validated method from the client, instead of callbacks?
For example, on the server
export async function zonesselect(systemId, geometry) {
const selectedZones = await Zones.find({ systemId, geometry }).fetch();
const selectedZoneIds = selectedZones.map(zone => (zone._id));
return selectedZoneIds;
}
Shared between client and server
export const zonesSelect = new ValidatedMethod({
name: 'zones.Select',
validate: new SimpleSchema({
systemId: { type: String, regEx: SimpleSchema.RegEx.Id },
geometry: { type: Object, blackbox: true },
}).validator(),
run({ systemId, geometry }) {
if (Meteor.isServer) {
import { iseditorismanager } from '../server/user';
import { zonesselect } from '../../collections/server/Zones';
if (iseditorismanager(systemId)) {
return zonesselect(systemId, geometry);
} else throw new Meteor.Error('permission denied', 'User not a system manager or editor');
}
},
});
On the client something like…
zonesSelect.call({ systemId, geometry })
.then((zoneIds) => {
zoneIds.forEach((zoneId) => {
console.log('zoneId', zoneId);
});
})
.catch((err) => { console.log('error', err); });