验证模式简单模式?

时间:2019-04-11 04:01:10

标签: javascript mongodb meteor

我有模式,然后在插入之前,我有方法验证金额金额字段模式错误我将其设置为对象,但金额仍然错误请帮助

这是我的收藏集

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

这是我在客户端上的方法调用

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

服务器上的方法

 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 })
   }
  }
 },
})

0 个答案:

没有答案