|
| 1 | +import { db } from '../src/lib/server/db/index.js'; |
| 2 | + |
| 3 | +async function getTours() { |
| 4 | + return await db.selectFrom('tour').where('tour.approachAndReturnM', 'is not', null).selectAll().execute(); |
| 5 | +} |
| 6 | + |
| 7 | +async function getRsTours() { |
| 8 | + return await db.selectFrom('rideShareTour').where('rideShareTour.approachAndReturnM', 'is not', null).selectAll().execute(); |
| 9 | +} |
| 10 | + |
| 11 | +type Tours = Awaited<ReturnType<typeof getTours>>; |
| 12 | +type RsTours = Awaited<ReturnType<typeof getRsTours>>; |
| 13 | + |
| 14 | +async function viewStatistics() { |
| 15 | + const tours = await getTours(); |
| 16 | + const tourEntries = { |
| 17 | + all: createEntries(tours), |
| 18 | + cancelled: createEntries(tours.filter((t) => t.cancelled)), |
| 19 | + uncancelledTours: createEntries(tours.filter((t) => !t.cancelled)) |
| 20 | + } |
| 21 | + |
| 22 | + const rsTours = await getRsTours(); |
| 23 | + const rsTourEntries = { |
| 24 | + all: createRsEntries(rsTours), |
| 25 | + cancelled: createRsEntries(rsTours.filter((t) => t.cancelled)), |
| 26 | + uncancelledTours: createRsEntries(rsTours.filter((t) => !t.cancelled)) |
| 27 | + } |
| 28 | + console.log("TAXI"); |
| 29 | + console.log(JSON.stringify(tourEntries,null,2)); |
| 30 | + console.log(); |
| 31 | + console.log("RIDE SHARE"); |
| 32 | + console.log(JSON.stringify(rsTourEntries,null,2)); |
| 33 | +} |
| 34 | + |
| 35 | +function createEntries(tours: Tours) { |
| 36 | + return { |
| 37 | + count: tours.length, |
| 38 | + approachAndReturnM: tours.reduce((prev, curr) => prev += curr.approachAndReturnM!, 0), |
| 39 | + fullyPayedM: tours.reduce((prev, curr) => prev += curr.fullyPayedM!, 0), |
| 40 | + occupiedM: tours.reduce((prev, curr) => prev+= curr.occupiedM!, 0) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +function createRsEntries(tours: RsTours) { |
| 45 | + return { |
| 46 | + count: tours.length, |
| 47 | + approachAndReturnM: tours.reduce((prev, curr) => prev += curr.approachAndReturnM!, 0), |
| 48 | + fullyPayedM: tours.reduce((prev, curr) => prev += curr.fullyPayedM!, 0), |
| 49 | + occupiedM: tours.reduce((prev, curr) => prev+= curr.occupiedM!, 0) |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +viewStatistics().catch((error) => { |
| 54 | + console.error('Error in main function:', error); |
| 55 | +}); |
0 commit comments