Formatting fixes
This commit is contained in:
parent
a3a2f12082
commit
9da2d5e2f2
14 changed files with 359 additions and 340 deletions
|
|
@ -25,7 +25,7 @@ import { LoggerModule } from './logger/module'
|
|||
},
|
||||
defaultJobOptions: {
|
||||
removeOnComplete: true,
|
||||
}
|
||||
},
|
||||
}),
|
||||
ScheduleModule.forRoot(),
|
||||
ConfigModule.forRoot({ isGlobal: true }),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common'
|
||||
import {
|
||||
Injectable,
|
||||
NestInterceptor,
|
||||
ExecutionContext,
|
||||
CallHandler,
|
||||
} from '@nestjs/common'
|
||||
import { Observable } from 'rxjs'
|
||||
import { map } from 'rxjs/operators'
|
||||
|
||||
|
|
@ -7,8 +12,13 @@ export interface CustomResponse<T = unknown> {
|
|||
}
|
||||
|
||||
@Injectable()
|
||||
export class CustomResponseTransformInterceptor<T> implements NestInterceptor<T, CustomResponse<T>> {
|
||||
intercept(_context: ExecutionContext, next: CallHandler): Observable<CustomResponse<T>> {
|
||||
return next.handle().pipe(map(data => ({ data })))
|
||||
export class CustomResponseTransformInterceptor<T>
|
||||
implements NestInterceptor<T, CustomResponse<T>>
|
||||
{
|
||||
intercept(
|
||||
_context: ExecutionContext,
|
||||
next: CallHandler,
|
||||
): Observable<CustomResponse<T>> {
|
||||
return next.handle().pipe(map((data) => ({ data })))
|
||||
}
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ export const convertDateRangeStringToObject = ({
|
|||
}): DateRange => ({ start: dayjs(start), end: dayjs(end) })
|
||||
|
||||
const dayjsTz = (
|
||||
date?: string | number | Date | dayjs.Dayjs | null | undefined
|
||||
date?: string | number | Date | dayjs.Dayjs | null | undefined,
|
||||
) => {
|
||||
return dayjs(date).tz()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export const RESERVATIONS_QUEUE_NAME = 'reservations'
|
||||
|
||||
export default () => ({
|
||||
queueName: RESERVATIONS_QUEUE_NAME
|
||||
queueName: RESERVATIONS_QUEUE_NAME,
|
||||
})
|
||||
|
|
@ -25,7 +25,11 @@ export class ReservationsCronService {
|
|||
})
|
||||
async handleDailyReservations() {
|
||||
const reservationsToPerform = await this.reservationService.getByDate()
|
||||
this.logger.log(`Found ${reservationsToPerform.length} reservations to perform`)
|
||||
await this.reservationsQueue.addBulk(reservationsToPerform.map((r) => ({ data: r })))
|
||||
this.logger.log(
|
||||
`Found ${reservationsToPerform.length} reservations to perform`,
|
||||
)
|
||||
await this.reservationsQueue.addBulk(
|
||||
reservationsToPerform.map((r) => ({ data: r })),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import { ReservationsWorker } from './worker'
|
|||
import { LoggerModule } from '../logger/module'
|
||||
import { RunnerModule } from '../runner/module'
|
||||
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
LoggerModule,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ export class ReservationsService {
|
|||
}
|
||||
|
||||
getByDate(date = dayjs()) {
|
||||
return this.reservationsRepository.createQueryBuilder()
|
||||
return this.reservationsRepository
|
||||
.createQueryBuilder()
|
||||
.where(`DATE(dateRangeStart, '-7 day') = DATE(:date)`, { date })
|
||||
.getMany()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,12 @@ export class ReservationsWorker {
|
|||
|
||||
@Process()
|
||||
async handleReservationJob(job: Job<Reservation>) {
|
||||
const reservation = plainToInstance(Reservation, job.data, { groups: ['password'] })
|
||||
this.logger.log('Handling reservation', { reservation: instanceToPlain(reservation) })
|
||||
const reservation = plainToInstance(Reservation, job.data, {
|
||||
groups: ['password'],
|
||||
})
|
||||
this.logger.log('Handling reservation', {
|
||||
reservation: instanceToPlain(reservation),
|
||||
})
|
||||
await this.performReservation(reservation)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -135,8 +135,8 @@ export class BaanReserverenService {
|
|||
await this.page
|
||||
?.waitForSelector(
|
||||
`td#cal_${date.get('year')}_${date.get('month') + 1}_${date.get(
|
||||
'date'
|
||||
)}`
|
||||
'date',
|
||||
)}`,
|
||||
)
|
||||
.then((d) => d?.click())
|
||||
.catch((e: Error) => {
|
||||
|
|
@ -145,8 +145,8 @@ export class BaanReserverenService {
|
|||
await this.page
|
||||
?.waitForSelector(
|
||||
`td#cal_${date.get('year')}_${date.get('month') + 1}_${date.get(
|
||||
'date'
|
||||
)}.selected`
|
||||
'date',
|
||||
)}.selected`,
|
||||
)
|
||||
.catch((e: Error) => {
|
||||
throw new RunnerNavigationSelectionError(e)
|
||||
|
|
|
|||
|
|
@ -10,5 +10,4 @@ import { LoggerModule } from '../logger/module'
|
|||
imports: [LoggerModule, BullModule.registerQueue({ name: 'reservations' })],
|
||||
exports: [EmptyPageFactory, BaanReserverenService],
|
||||
})
|
||||
|
||||
export class RunnerModule {}
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
import { Inject, Injectable, BeforeApplicationShutdown, OnModuleInit, Scope } from '@nestjs/common'
|
||||
import puppeteer, { Browser, BrowserConnectOptions, BrowserLaunchArgumentOptions, LaunchOptions, Page } from 'puppeteer'
|
||||
import { LoggerService } from '../logger/service'
|
||||
|
||||
enum SessionAction {
|
||||
NoAction,
|
||||
Logout,
|
||||
Login,
|
||||
}
|
||||
import {
|
||||
Injectable,
|
||||
BeforeApplicationShutdown,
|
||||
OnModuleInit,
|
||||
} from '@nestjs/common'
|
||||
import puppeteer, {
|
||||
Browser,
|
||||
BrowserConnectOptions,
|
||||
BrowserLaunchArgumentOptions,
|
||||
LaunchOptions,
|
||||
} from 'puppeteer'
|
||||
|
||||
interface RunnerSession {
|
||||
username: string
|
||||
|
|
@ -20,7 +22,7 @@ export class RunnerService implements OnModuleInit, BeforeApplicationShutdown {
|
|||
BrowserLaunchArgumentOptions &
|
||||
BrowserConnectOptions = {
|
||||
args: ['--disable-setuid-sandbox', '--no-sandbox'],
|
||||
headless: 'new'
|
||||
headless: 'new',
|
||||
}
|
||||
private session: RunnerSession | null = null
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue