infer return type of functions

This commit is contained in:
Thomas Ruoff
2021-03-22 23:14:48 +01:00
parent 3cf2aff832
commit 9fe3fffb86
16 changed files with 54 additions and 54 deletions

View File

@@ -22,8 +22,8 @@ export interface Booking {
export interface BookingDocument
extends Booking,
mongoose.Document,
mongoose.SchemaTimestampsConfig {}
mongoose.Document,
mongoose.SchemaTimestampsConfig { }
export interface BookingModel extends mongoose.Model<BookingDocument> {
findBookedDays(uuidsToIngore?: string[]): Promise<string[]>
@@ -52,10 +52,10 @@ const BookingSchema = new mongoose.Schema<BookingDocument>(
required: true,
get: dateFormatBackend,
validate: {
validator: function (v: Date) {
validator: function(v: Date): boolean {
return v >= nowInTz()
},
message: (props: { value: Date }) => `${props.value} is in the past`,
message: (props: { value: Date }): string => `${props.value} is in the past`,
},
},
endDate: {
@@ -63,27 +63,27 @@ const BookingSchema = new mongoose.Schema<BookingDocument>(
required: false,
get: dateFormatBackend,
validate: {
validator: function (v: Date) {
validator: function(v: Date): boolean {
return v >= nowInTz()
},
message: (props: { value: Date }) => `${props.value} is in the past`,
message: (props: { value: Date }): string => `${props.value} is in the past`,
},
},
days: {
type: [String],
required: true,
validate: {
validator: async function (days: string[]) {
validator: async function(days: string[]): Promise<boolean> {
const booking = this as Booking
const uuid = booking.uuid && [booking.uuid]
const bookedDays = await getBookedDays(uuid)
const doubleBookedDays = days.filter((day: string) =>
const doubleBookedDays = days.filter((day: string): boolean =>
bookedDays.includes(day)
)
return doubleBookedDays.length === 0
},
message: (props: { value: string[] }) =>
message: (props: { value: string[] }): string =>
`At least one day is of ${props.value.join(',')} is already booked`,
type: VALIDATION_ERRORS.AT_LEAST_ONE_DAY_BOOKED,
},
@@ -105,7 +105,7 @@ const BookingSchema = new mongoose.Schema<BookingDocument>(
}
)
BookingSchema.pre('validate', function (next: () => void) {
BookingSchema.pre('validate', function(next: () => void): void {
const booking = this as BookingDocument
booking.days = getDays({
startDate: new Date(booking.startDate),
@@ -114,7 +114,7 @@ BookingSchema.pre('validate', function (next: () => void) {
next()
})
BookingSchema.static('findBookedDays', async function (
BookingSchema.static('findBookedDays', async function(
uuidsToIngore: string[] = []
): Promise<string[]> {
const model = this as BookingModel