Replaced most properties in creature variables with links
instead of storing the entire property twice
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||
import CreatureVariables from '/imports/api/creature/creatures/CreatureVariables';
|
||||
import { JsonRoutes } from 'meteor/simple:json-routes';
|
||||
import { assertViewPermission } from '/imports/api/creature/creatures/creaturePermissions.js';
|
||||
import computeCreature from '/imports/api/engine/computeCreature.js';
|
||||
import VERSION from '/imports/constants/VERSION.js';
|
||||
import { getCreature, getProperties, getVariables } from '/imports/api/engine/loadCreatures';
|
||||
|
||||
Meteor.publish('api-creature', function(creatureId){
|
||||
JsonRoutes.add('get', 'api/creature/:id', function (req, res) {
|
||||
const creatureId = req.params.id;
|
||||
|
||||
// Validate the creature ID
|
||||
try {
|
||||
new SimpleSchema({
|
||||
creatureId: {
|
||||
@@ -14,7 +16,55 @@ Meteor.publish('api-creature', function(creatureId){
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
}).validate({ creatureId });
|
||||
} catch (e){
|
||||
} catch (e) {
|
||||
const error = new Meteor.Error('invalid-id', 'Invalid creature ID provided');
|
||||
error.statusCode = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
// Check permissions
|
||||
const creature = getCreature(creatureId);
|
||||
const userId = req.userId;
|
||||
try {
|
||||
assertViewPermission(creature, userId)
|
||||
} catch (e) {
|
||||
e.statusCode = 403;
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Compute the creature first if need be
|
||||
if (creature.computeVersion !== VERSION) {
|
||||
try {
|
||||
computeCreature(creatureId)
|
||||
} catch (e) {
|
||||
e.statusCode = 500;
|
||||
console.error(e)
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// Send the results
|
||||
JsonRoutes.sendResult(res, {
|
||||
data: {
|
||||
creatures: [creature],
|
||||
creatureProperties: getProperties(creatureId),
|
||||
creatureVariables: getVariables(creatureId),
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/*
|
||||
Meteor.publish('api-creature', function (creatureId) {
|
||||
try {
|
||||
new SimpleSchema({
|
||||
creatureId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
}).validate({ creatureId });
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
this.error(e);
|
||||
return;
|
||||
}
|
||||
@@ -25,14 +75,15 @@ Meteor.publish('api-creature', function(creatureId){
|
||||
const creature = creatureCursor.fetch()[0];
|
||||
try {
|
||||
assertViewPermission(creature, userId)
|
||||
} catch(e){
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
this.error(e);
|
||||
return;
|
||||
}
|
||||
if (creature.computeVersion !== VERSION){
|
||||
if (creature.computeVersion !== VERSION) {
|
||||
try {
|
||||
computeCreature(creatureId)
|
||||
} catch(e){
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
@@ -48,3 +99,4 @@ Meteor.publish('api-creature', function(creatureId){
|
||||
}, {
|
||||
url: 'api/creature/:0'
|
||||
});
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user