Action interruption progress
This commit is contained in:
3
app/imports/api/engine/action/methods/index.ts
Normal file
3
app/imports/api/engine/action/methods/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import './insertAction';
|
||||
import './runAction';
|
||||
import './updateAction';
|
||||
@@ -4,7 +4,7 @@ import EngineActions, { EngineAction, ActionSchema } from '/imports/api/engine/a
|
||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions';
|
||||
import { getCreature } from '/imports/api/engine/loadCreatures';
|
||||
|
||||
export const insertAction: ValidatedMethod = new ValidatedMethod({
|
||||
export const insertAction = new ValidatedMethod({
|
||||
name: 'actions.insertAction',
|
||||
validate: new SimpleSchema({
|
||||
action: ActionSchema
|
||||
@@ -16,6 +16,6 @@ export const insertAction: ValidatedMethod = new ValidatedMethod({
|
||||
EngineActions.removeAsync({ creatureId: action.creatureId });
|
||||
// Force a random id even if one was provided, we may use it later as the seed for PRNG
|
||||
delete action._id;
|
||||
return await EngineActions.insertAsync(action);
|
||||
return EngineActions.insertAsync(action);
|
||||
},
|
||||
});
|
||||
|
||||
22
app/imports/api/engine/action/methods/updateAction.ts
Normal file
22
app/imports/api/engine/action/methods/updateAction.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import EngineActions from '/imports/api/engine/action/EngineActions';
|
||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions';
|
||||
import { getCreature } from '/imports/api/engine/loadCreatures';
|
||||
|
||||
export const updateAction = new ValidatedMethod({
|
||||
name: 'actions.updateAction',
|
||||
validate({ _id, path, value }) {
|
||||
if (!_id) throw new Meteor.Error('No _id', '_id is required');
|
||||
// We cannot change these fields with a simple update
|
||||
if (path !== 'targetIds') throw new Meteor.Error('Can only update target ids');
|
||||
if (!Array.isArray(value)) throw new Meteor.Error('TargetIds must be an array');
|
||||
},
|
||||
run: async function ({ _id, path, value }: { _id: string, path: 'targetIds', value: string[] }) {
|
||||
const action = await EngineActions.findOneAsync(_id);
|
||||
if (!action) {
|
||||
throw new Meteor.Error('not found', 'The given action was not found');
|
||||
}
|
||||
assertEditPermission(getCreature(action.creatureId), this.userId);
|
||||
return EngineActions.updateAsync(_id, { $set: { [path]: value } });
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user