mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
fix most type errors
still have a few things outstanding
This commit is contained in:
committed by
Thomas Ruoff
parent
c3d8c6f3e0
commit
90ac05a907
@@ -1,17 +1,13 @@
|
||||
import { getNextSmaller, getNextBigger } from './array'
|
||||
|
||||
// @ts-expect-error ts-migrate(2582) FIXME: Cannot find name 'test'. Do you need to install ty... Remove this comment to see the full error message
|
||||
test('getPreviousInOrder', () => {
|
||||
const result = getNextSmaller([3, 1, 2, 0, 8, 9, 10], 5)
|
||||
|
||||
// @ts-expect-error ts-migrate(2304) FIXME: Cannot find name 'expect'.
|
||||
expect(result).toEqual(3)
|
||||
})
|
||||
|
||||
// @ts-expect-error ts-migrate(2582) FIXME: Cannot find name 'test'. Do you need to install ty... Remove this comment to see the full error message
|
||||
test('getNextInOrder', () => {
|
||||
const result = getNextBigger([7, 8, 9, 3, 1, 2], 4)
|
||||
|
||||
// @ts-expect-error ts-migrate(2304) FIXME: Cannot find name 'expect'.
|
||||
expect(result).toEqual(7)
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export function getNextSmaller(array, pivot) {
|
||||
export function getNextSmaller<T>(array: T[], pivot: T) {
|
||||
if (!array || !Array.isArray(array) || !array.length) {
|
||||
return null
|
||||
}
|
||||
@@ -9,7 +9,7 @@ export function getNextSmaller(array, pivot) {
|
||||
.find((item) => item < pivot)
|
||||
}
|
||||
|
||||
export function getNextBigger(array, pivot) {
|
||||
export function getNextBigger<T>(array: T[], pivot: T) {
|
||||
if (!array || !Array.isArray(array) || !array.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -3,7 +3,13 @@ import moment from 'moment'
|
||||
const FRONTEND_FORMAT = 'DD.MM.YYYY'
|
||||
const BACKEND_FORMAT = 'YYYY-MM-DD'
|
||||
|
||||
export function getDays({ startDate, endDate }) {
|
||||
export function getDays({
|
||||
startDate,
|
||||
endDate,
|
||||
}: {
|
||||
startDate: moment.MomentInput
|
||||
endDate: moment.MomentInput
|
||||
}) {
|
||||
let currentDay = moment(startDate)
|
||||
const days = [dateFormatBackend(currentDay)]
|
||||
|
||||
@@ -20,31 +26,30 @@ export function getDays({ startDate, endDate }) {
|
||||
return days
|
||||
}
|
||||
|
||||
function dateFormat(date, format) {
|
||||
function dateFormat(date: moment.MomentInput, format: string) {
|
||||
if (!date) {
|
||||
return null
|
||||
}
|
||||
return moment(date).format(format)
|
||||
}
|
||||
|
||||
export function dateFormatBackend(date) {
|
||||
export function dateFormatBackend(date: moment.MomentInput) {
|
||||
return dateFormat(date, BACKEND_FORMAT)
|
||||
}
|
||||
|
||||
export function dateFormatFrontend(date) {
|
||||
export function dateFormatFrontend(date: moment.MomentInput) {
|
||||
return dateFormat(date, FRONTEND_FORMAT)
|
||||
}
|
||||
|
||||
function dateParse(string, format) {
|
||||
const date = moment(string, format)
|
||||
function dateParse(input: string, format: string) {
|
||||
const date = moment(input, format)
|
||||
if (date.isValid()) {
|
||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'getDate' does not exist on type 'Moment'... Remove this comment to see the full error message
|
||||
return date.getDate()
|
||||
return date.toDate()
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function dateParseFrontend(string) {
|
||||
return dateParse(string, FRONTEND_FORMAT)
|
||||
export function dateParseFrontend(input: string) {
|
||||
return dateParse(input, FRONTEND_FORMAT)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ if (!SENDGRID_API_KEY) {
|
||||
throw new Error('NO SENDGRID_API_KEY set!')
|
||||
}
|
||||
|
||||
async function sendMail(data) {
|
||||
async function sendMail(data: object) {
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -24,13 +24,11 @@ async function sendMail(data) {
|
||||
const response = await fetch(SENDGRID_URL, fetchOptions)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to send booking ${data._id} to booking admin with status ${response.status}: ${response.statusText}`
|
||||
)
|
||||
throw new Error(`Unable to send mail`)
|
||||
}
|
||||
}
|
||||
|
||||
function getReceivedBookingText(booking) {
|
||||
function getReceivedBookingText(booking: { uuid: string }) {
|
||||
return `Hallo lieber Admin,
|
||||
|
||||
es ging folgende Buchung ein: https://${process.env.VERCEL_URL}/booking/${booking.uuid}
|
||||
@@ -38,7 +36,7 @@ function getReceivedBookingText(booking) {
|
||||
MfG`
|
||||
}
|
||||
|
||||
export async function sendReceivedBookingMail(booking) {
|
||||
export async function sendReceivedBookingMail(booking: { uuid: string }) {
|
||||
const data = {
|
||||
personalizations: [
|
||||
{
|
||||
@@ -46,9 +44,13 @@ export async function sendReceivedBookingMail(booking) {
|
||||
},
|
||||
],
|
||||
from: { email: FROM_EMAIL },
|
||||
subject: 'Pfadi Bussle - Buchung eingegangen!',
|
||||
subject: `Pfadi Bussle - Buchung ${booking.uuid} eingegangen!`,
|
||||
content: [{ type: 'text/plain', value: getReceivedBookingText(booking) }],
|
||||
}
|
||||
|
||||
await sendMail(data)
|
||||
try {
|
||||
await sendMail(data)
|
||||
} catch (error) {
|
||||
console.error(`Failed in sendReceivedBookingMail for ${booking.uuid}`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user