[Resolved] ValidatedMethod and SimpleSchema

Hello,

I spent all my afternoon for this thing… :’(

I try to realize methods.js file, according to “todos” example.

I have many erros on Invalid definition for equipmentUpdated field. and ValidateMethod is not a function.

Could you help me ?

import { Meteor } from 'meteor/meteor';
import { ValidateMethod } from 'meteor/mdg:validated-method';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';

import { Equipments } from './equipments';

const EQUIPMENT_ID_ONLY = new SimpleSchema({
  _id: Equipments.simpleSchema().schema('_id'),
}).validator({ clean: true, filtre: false });


export const update = new ValidateMethod({
  name: 'equipments.update',
  validate: new SimpleSchema({
    equipmentId: Equipments.simpleSchema().schema('_id'),
    equipmentUpdated: Equipments.simpleSchema().schema(),
  }).validator({ clean: true, filter: false }),
  run({ equipmentId, equipmentUpdated }) {
    if (!this.userId) {
      throw new Meteor.Error('equipments.insert.not-logged-in', 'Must be logged in to create invoice.');
    }
    Equipments.update(equipmentId, _.omit(equipmentUpdated, '_id'), { validate: false });
  },
});

Many thanks :’)

import { ValidateMethod } from 'meteor/mdg:validated-method'; and export const update = new ValidateMethod({

Should be ValidatedMethod.

Don’t know - sorry.

1 Like

Have you read up here: aldeed:simple-schema?

Thanks. :+1: Stupid error… Missing the letter ‘d’…

For validate, the good way appear to be this :

  validate: new SimpleSchema({
    equipmentId: EQUIPMENT_ID_ONLY,
    equipmentUpdated: {
      type: Equipments.simpleSchema(),
    },
  }).validator(),
1 Like