Simple Schema Validation


#1

I have schema and then before insert I have method validate error with amount amount field schema I set it to object but it still error with amount Please help

This is my collection

_id: {
 type: String,
 optional: true,
},
refNo: {
 type: String, // VDYYMM00000
},
tranDate: {
 type: Date,
},  
vendorId: {
 type: String,
}, 
amount: {
 type: Object,
 optional: true,
},

This is my method call on client

insertVendorDeposit
   .callPromise({ doc, opts })
   .then(result => {
     if (result) {
       Msg.success('Success')           
     }
   })
   .catch(error => {
     console.log(error)
     Notify.error({ message: error })
   })

Method on server

export const insertVendorDeposit = new ValidatedMethod({
 name: 'pos.insertVendorDeposit',
 mixins: [CallPromiseMixin],
 validate: new SimpleSchema({
 doc: VendorsDeposit.schema,
 opts: {
   type: Object,
   optional: true,
   blackbox: true,
 },
 }).validator(),
 run(doc, opts) {
   if (Meteor.isServer) {
    let _id
    try {
          doc.amount = Decimal(round(doc.amount))
          if (doc.depositType == 'CW') {
            doc.amount = -doc.amount
            doc.tranType = 'Vendor_Withdrawal'
            doc.refType = 'Withdrawal'
          }
         _id = VendorsDeposit.insert(doc) 
         return _id
    } catch (error) {      
        throwError('VendorDepositInsert', error, { doc })
   }
  }
 },
})

Error with Decimal on amount any suggestion or solution please


#2

Hey I was having a similar issue recently after upgrading to 1.8.1 , I went back to 1.8.0.1 and it worked… I haven’t dived into why yet, but you can look into see if that helps.