mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 23:17:12 +01:00
fix type errors hopefully *fingerscrossed*
This commit is contained in:
@@ -34,7 +34,8 @@ const BillSchema = new mongoose.Schema<BillDocument>(
|
|||||||
|
|
||||||
return v <= bill.milageEnd
|
return v <= bill.milageEnd
|
||||||
},
|
},
|
||||||
message: (props) => `${props.value} is bigger than milageEnd!`,
|
message: (props: { value: Number }) =>
|
||||||
|
`${props.value} is bigger than milageEnd!`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
milageEnd: {
|
milageEnd: {
|
||||||
@@ -47,7 +48,8 @@ const BillSchema = new mongoose.Schema<BillDocument>(
|
|||||||
|
|
||||||
return v >= bill.milageStart
|
return v >= bill.milageStart
|
||||||
},
|
},
|
||||||
message: (props) => `${props.value} is smaller than milageStart!`,
|
message: (props: { value: Number }) =>
|
||||||
|
`${props.value} is smaller than milageStart!`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
tarif: {
|
tarif: {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import * as mongoose from 'mongoose'
|
import * as mongoose from 'mongoose'
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
import { dateFormatBackend, getDays, nowInTz } from '../helpers/date'
|
import { dateFormatBackend, getDays, nowInTz } from '../helpers/date'
|
||||||
|
|
||||||
import { Bill } from './bill'
|
import { Bill } from './bill'
|
||||||
import { Booker } from './booker'
|
import { Booker } from './booker'
|
||||||
import { BOOKING_STATUS } from './enums'
|
import { BOOKING_STATUS } from './enums'
|
||||||
@@ -49,13 +50,23 @@ const BookingSchema = new mongoose.Schema<BookingDocument>(
|
|||||||
type: Date,
|
type: Date,
|
||||||
required: true,
|
required: true,
|
||||||
get: dateFormatBackend,
|
get: dateFormatBackend,
|
||||||
min: nowInTz(),
|
validate: {
|
||||||
|
validator: function (v: Date) {
|
||||||
|
return v >= nowInTz()
|
||||||
|
},
|
||||||
|
message: (props: { value: Date }) => `${props.value} is in the past`,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
endDate: {
|
endDate: {
|
||||||
type: Date,
|
type: Date,
|
||||||
required: false,
|
required: false,
|
||||||
get: dateFormatBackend,
|
get: dateFormatBackend,
|
||||||
min: nowInTz(),
|
validate: {
|
||||||
|
validator: function (v: Date) {
|
||||||
|
return v >= nowInTz()
|
||||||
|
},
|
||||||
|
message: (props: { value: Date }) => `${props.value} is in the past`,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
days: {
|
days: {
|
||||||
type: [String],
|
type: [String],
|
||||||
|
|||||||
11
db/index.ts
11
db/index.ts
@@ -72,14 +72,11 @@ export async function createBooking({
|
|||||||
bookedDays.includes(day)
|
bookedDays.includes(day)
|
||||||
)
|
)
|
||||||
if (doubleBookedDays.length) {
|
if (doubleBookedDays.length) {
|
||||||
const error = new mongoose.Error.ValidationError(booking)
|
const error = new mongoose.Error.ValidationError(booking.uuid)
|
||||||
error.addError(
|
error.errors.days = new mongoose.Error.ValidatorError(
|
||||||
'days',
|
`${doubleBookedDays
|
||||||
new mongoose.Error.ValidatorError({
|
|
||||||
message: `${doubleBookedDays
|
|
||||||
.map((dateString) => dateFormatFrontend(new Date(dateString)))
|
.map((dateString) => dateFormatFrontend(new Date(dateString)))
|
||||||
.join(', ')} schon gebucht`,
|
.join(', ')} schon gebucht`
|
||||||
})
|
|
||||||
)
|
)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user