mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 23:17:12 +01:00
remove obsolete existence check for milageStart/End
This commit is contained in:
committed by
Thomas Ruoff
parent
2e73875d37
commit
367a16fabb
34
db/bill.ts
34
db/bill.ts
@@ -28,8 +28,31 @@ const BillSchema = new mongoose.Schema<BillDocument>(
|
|||||||
ref: 'Booking',
|
ref: 'Booking',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
milageStart: { type: Number, required: true },
|
milageStart: {
|
||||||
milageEnd: { type: Number, required: true },
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
validate: {
|
||||||
|
validator: function (v: number) {
|
||||||
|
const bill = this as BillDocument
|
||||||
|
|
||||||
|
return v <= bill.milageEnd
|
||||||
|
},
|
||||||
|
message: (props) => `${props.value} is bigger than milageEnd!`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
milageEnd: {
|
||||||
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
|
||||||
|
validate: {
|
||||||
|
validator: function (v: number) {
|
||||||
|
const bill = this as BillDocument
|
||||||
|
|
||||||
|
return v >= bill.milageStart
|
||||||
|
},
|
||||||
|
message: (props) => `${props.value} is smaller than milageStart!`,
|
||||||
|
},
|
||||||
|
},
|
||||||
rate: {
|
rate: {
|
||||||
type: Number,
|
type: Number,
|
||||||
enum: Object.values(MILAGE_RATES),
|
enum: Object.values(MILAGE_RATES),
|
||||||
@@ -54,19 +77,12 @@ const BillSchema = new mongoose.Schema<BillDocument>(
|
|||||||
|
|
||||||
BillSchema.virtual('milage').get(function () {
|
BillSchema.virtual('milage').get(function () {
|
||||||
const bill = this as BillDocument
|
const bill = this as BillDocument
|
||||||
|
|
||||||
if (!bill.milageStart || !bill.milageEnd) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
return bill.milageEnd - bill.milageStart
|
return bill.milageEnd - bill.milageStart
|
||||||
})
|
})
|
||||||
|
|
||||||
BillSchema.virtual('total').get(function () {
|
BillSchema.virtual('total').get(function () {
|
||||||
const bill = this as BillDocument
|
const bill = this as BillDocument
|
||||||
|
|
||||||
if (!bill.milageStart || !bill.milageEnd) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
const milageCosts = bill.milage * bill.rate
|
const milageCosts = bill.milage * bill.rate
|
||||||
const additionalCostSum = bill.additionalCosts
|
const additionalCostSum = bill.additionalCosts
|
||||||
.map(({ value }) => value)
|
.map(({ value }) => value)
|
||||||
|
|||||||
Reference in New Issue
Block a user