不能在Mongoose模式的默认函数中使用固定值?

jslywgbw  于 2022-11-13  发布在  Go
关注(0)|答案(1)|浏览(89)

我试图计算SSC,它是通过将basicSalary乘以0.07%计算出来的,在totalEarningstotalDeductionsnetSalary中,它通过对字段进行计算工作得很好,但在SSC中,将basicSalary乘以0.07%会产生错误expression expected,这是不是意味着我只能使用字段?

const mongoose = require("mongoose");

const salariesSchema = mongoose.Schema({

  basicSalary: { type: Number, default: 0, required: true },
  accomodation: { type: Number, default: 0 },
  transportation: { type: Number, default: 0 },
  bonus: { type: Number, default: 0 },

  SSC: { type: Number, default: function(){
    return this.basicSalary * 0.07%
  } },

  incomeTax: { type: Number, default: 0 },
  medicalInsurance: { type: Number, default: 0 },
  loan: { type: Number, default: 0, default: null },

  totalEarnings: {
    type: Number,
    default: function () {
      return (
        this.basicSalary + this.accomodation + this.transportation + this.bonus
      );
    },
  },

  totalDeductions: {
    type: Number,
    defualt: function () {
      return this.SSC - this.incomeTax - this.medicalInsurance - this.loan;
    },
  },

  netSalary: {
    type: Number,
    default: function () {
      return this.totalEarnings - this.totalDeductions;
    },
  },
});

module.exports = mongoose.model("salarie", salariesSchema);
os8fio9y

os8fio9y1#

如果要计算7%的值,应写出:

SSC: { 
    type: Number, 
    default: function () {
        return this.basicSalary * 0.07;
    } 
}

相关问题