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