Error (.... is not allowed by the schema) (with my code)


#1

Hello everyone, I need help with my form and my schema, which always sendme error:
"nombreApellidos is not allowed by the schema" ¿why can be my the error? ¿some ideas?

Here is my code…

imports/api/tarjetaBancaria/collection.js

import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';

export const TarjetaBancaria = new Mongo.Collection('tarjetaBancaria');

TarjetaBancaria.deny({
  insert() {return true;},
  update() {return true;},
  remove() {return true;}
});

  const Schema = {};
  Schema.tarjetaBancaria = new SimpleSchema ({
    _id: {
      type: String,
      regEx: SimpleSchema.RegEx.Id
    },
    nombreApellidos: {
      type: String,
      max : 30,
      min : 1,
      regEx: /^[a-zA-Z-ñáéíóú\s]+$/
    }
  });

  TarjetaBancaria.attachSchema(Schema.tarjetaBancaria);

imports/api/tarjetaBancaria/methods.js

import { Meteor } from 'meteor/meteor';
import { _ } from 'meteor/underscore';
import { ValidatedMethod } from 'meteor/mdg:validated-method';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import { LoggedInMixin } from 'meteor/tunifight:loggedin-mixin';

import { TarjetaBancaria } from './collection.js';

export const insert = new ValidatedMethod({
    name: 'tarjetaBancaria.insert',
    mixins: [LoggedInMixin],
    checkLoggedInError: {
        error: '403',
        message: 'Para modificar estos datos necesitas iniciar sesión',
        reason: 'El usuario no loggeado',
    },
    validate: TarjetaBancaria
    .simpleSchema()
    .pick(['propietario'])
    .validator({
        clean: true,
        filter: false
    }),
    run(tarjetaBancaria) {
      console.log('llegó a run');
        tarjetaBancaria.propietario = this.userId;
        return TarjetaBancaria.insert(tarjetaBancaria);
    }

});

imports/api/tarjetaBancaria/publish.js

import { Meteor } from 'meteor/meteor';

import { TarjetaBancaria } from './collection';

if (Meteor.isServer) {
  Meteor.publish('tarjetaBancaria', function() {
    const selector =  {
        owner: this.userId
      };

    return TarjetaBancaria.find(selector);
  });
}

**imports/api/tarjetaBancaria/index.js**

import './publish';

export * from './collection';

imports/ui/components/datosBancarios/tarjeta/tarjeta.js

// modules
import angular from 'angular';
import angularMeteor from 'angular-meteor';
import uiRouter from 'angular-ui-router';
import ngAnimate from 'angular-animate';
import { Meteor } from 'meteor/meteor';
import { ValidationError } from 'meteor/mdg:validation-error';

import './tarjeta.html';

import { TarjetaBancaria } from '../../../../api/tarjetaBancaria';
import { insert } from '../../../../api/tarjetaBancaria/methods.js';

class Tarjeta {
  constructor($scope, $reactive) {
    'ngInject';
    $reactive(this).attach($scope);

    this.respuesta = {mostrar: false, mensaje: '', tipo: ''};

    this.subscribe('tarjetaBancaria');

    this.helpers({
      tarjetaBancaria() {
        return TarjetaBancaria.findOne();
      }
    });
  }
  guardar(){
    insert.call(this.tarjetaBancaria, (err) => {
        console.log('error', err);
    });
  }
}

const name = 'tarjeta';

// CREATE A MODULE
export default angular
.module(name, [
  angularMeteor,
  uiRouter,
  ngAnimate
])
.component(name, {
  templateUrl: `imports/ui/components/datosBancarios/${name}/${name}.html`,
  controllerAs: name,
  controller: Tarjeta
})
.config(config);

function config($stateProvider) {
  'ngInject';
  $stateProvider
    .state('app.tarjeta', {
      url: '/tarjeta',
      template: '<tarjeta></tarjeta>',
      resolve: {
        currentUser($q) {
          if (Meteor.userId() === null) {
            return $q.reject('AUTH_REQUIRED');
          } else {
            return $q.resolve();
          }
        }
      }
    });
}

imports/ui/components/datosBancarios/tarjeta/tarjeta.html

<form
id="tarjetaFrmId"
class="property-submit-form"
role="form"
name="tarjetaFrm"
nonvalidate>
  <div class="row">
    <!-- NOMBRE DE LA PERSONA -->
    <div class="col-sm-12 ">
      <div class="form-group" ng-class="{ 'has-error' : tarjetaFrm.nombreApellidos.$invalid && !tarjetaFrm.nombreApellidos.$pristine}">
        <input
        id="nombreApellidosId"
        class="form-control"
        name="nombreApellidos"
        type="text"
        autocomplete="off"
        placeholder="Nombre y Apellidos"
        required
        minlength="1"
        maxlength="31"
        ng-minlength="1"
        ng-maxlength="30"
        ng-pattern="/^[a-zA-Z-ñáéíóú\s]+$/"
        ng-model="tarjeta.tarjetaBancaria.nombreApellidos"
        ng-disabled="deshabilitarCampos" />
        <div ng-messages="tarjetaFrm.nombreApellidos.$dirty && tarjetaFrm.nombreApellidos.$error" role="alert">
          <div style="color:red;" ng-message="required">Campo requerido.</div>
          <div style="color:red;" ng-message="minlength, maxlength">30 caracteres máximo</div>
          <div style="color:red;" ng-message="pattern">Únicamente caracteres alfabéticos</div>
        </div>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-sm-12">
      <!-- ALERT:  -->
      <div class="row">
        <div class="col-xs-12" ng-show="tarjeta.respuesta.mostrar">
          <uib-alert type="{{ tarjeta.respuesta.tipo }}">
            <span class="fa fa-exclamation-triangle"></span>
            <strong> {{ tarjeta.respuesta.mensaje }} </strong>
          </uib-alert>
        </div>
      </div>
    </div>
    <!-- BOTON SAVE TARJETA -->
    <div class="col-sm-12">
      <!-- SAVE-->
      <button
      class="btn btn-primary btn-block pull-right"
      type="button"
      ng-click="tarjeta.guardar()"
      ng-disabled="tarjetaFrm.$invalid">
        SAVE
      </button>
    </div>
  </div>
</form>

thanks for your time, i will hope help


#2

Hello.
TarjetaBancaria.deny({
insert() {return true;},
update() {return true;},
remove() {return true;}
});
Shouldn’t this be TarjetaBancaria.allow instead of TarjetaBancaria.deny ?


#3

I don’t think so. He’s following the strategy of denying everything and doing all updates through methods.

I believe the problems here are more in the ValidatedMethod interface definition. The poster has
a) told it via the validate option to accept only a single parameter named 'propietario’
b) told it via the run option that it has a parameter named tarjetaBancaria (mismatch to validate)
c) didn’t put that run parameter within curly braces {}.
etc.

I’d advise digging into the full meteor/todos sample application and the guide section on methods.


#4

AHa! Thank you. I should’ve looked into it more carefully. :sweat_smile:


#5

You well
The error was in the pick,

Thanks for yor time.


#6

jajaja yeah
is very common in programing, sometimes camelcase, sometimes semicolon… jajaja
anyway
THANKS FOR YOUR TIME!