Skip to content

Commit

Permalink
style(poster): prettier --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperVK committed Dec 18, 2024
1 parent 8abe036 commit da00b41
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Request as ExpressRequest } from 'express';
import BasePosterScreenHandler from './base-poster-screen-handler';
import { Poster } from './poster';
import logger from '../../../../logger';
import OlympicsService from "./olympics-service";
import NsTrainsService, {TrainResponse} from "./ns-trains-service";
import OlympicsService from './olympics-service';
import NsTrainsService, { TrainResponse } from './ns-trains-service';

export interface BorrelModeParams {
enabled: boolean;
Expand All @@ -32,7 +32,7 @@ export class BasePosterScreenController extends Controller {
}
const posters = this.screenHandler.posterManager.posters ?? [];
return {
posters: posters.filter((p) => !p.borrelMode)
posters: posters.filter((p) => !p.borrelMode),
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,103 +1,111 @@
import {BasePosterResponse, BasePosterScreenController, BorrelModeParams} from "../base-poster-screen-controller";
import HandlerManager from "../../../../root/handler-manager";
import {Screen} from "../../../../root/entities";
import {GewisPosterScreenHandler} from "../../index";
import {Body, Get, Post, Put, Query, Request, Route, Security, Tags} from "tsoa";
import {SecurityNames} from "../../../../../helpers/security";
import {securityGroups} from "../../../../../helpers/security-groups";
import logger from "../../../../../logger";
import {Request as ExpressRequest} from "express";
import {TrainResponse} from "../ns-trains-service";
import GEWISPosterService, {GEWISPhotoAlbumParams} from "./gewis-poster-service";
import OlympicsService from "../olympics-service";
import {FeatureEnabled} from "../../../../server-settings";
import {
BasePosterResponse,
BasePosterScreenController,
BorrelModeParams,
} from '../base-poster-screen-controller';
import HandlerManager from '../../../../root/handler-manager';
import { Screen } from '../../../../root/entities';
import { GewisPosterScreenHandler } from '../../index';
import { Body, Get, Post, Put, Query, Request, Route, Security, Tags } from 'tsoa';
import { SecurityNames } from '../../../../../helpers/security';
import { securityGroups } from '../../../../../helpers/security-groups';
import logger from '../../../../../logger';
import { Request as ExpressRequest } from 'express';
import { TrainResponse } from '../ns-trains-service';
import GEWISPosterService, { GEWISPhotoAlbumParams } from './gewis-poster-service';
import OlympicsService from '../olympics-service';
import { FeatureEnabled } from '../../../../server-settings';

interface GewisPosterResponse extends BasePosterResponse {
borrelMode: boolean;
borrelMode: boolean;
}

@Route('handler/screen/gewis-poster')
@Tags('Handlers')
@FeatureEnabled('GewisPosterScreenHandler')
export class GewisPosterScreenController extends BasePosterScreenController {
protected screenHandler: GewisPosterScreenHandler;
protected screenHandler: GewisPosterScreenHandler;

constructor() {
super();
this.screenHandler = HandlerManager.getInstance()
.getHandlers(Screen)
.filter((h) => h.constructor.name === GewisPosterScreenHandler.name)[0] as GewisPosterScreenHandler;
}
constructor() {
super();
this.screenHandler = HandlerManager.getInstance()
.getHandlers(Screen)
.filter(
(h) => h.constructor.name === GewisPosterScreenHandler.name,
)[0] as GewisPosterScreenHandler;
}

@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Get('')
public async getGewisPosters(@Query() alwaysReturnBorrelPosters?: boolean): Promise<GewisPosterResponse> {
if (!this.screenHandler.posterManager.posters) {
try {
await this.screenHandler.posterManager.fetchPosters();
} catch (e) {
logger.error(e);
}
}
const posters = this.screenHandler.posterManager.posters ?? [];
if (alwaysReturnBorrelPosters || this.screenHandler.borrelMode) {
return {
posters,
borrelMode: this.screenHandler.borrelMode,
};
}
return {
posters: posters.filter((p) => !p.borrelMode),
borrelMode: false,
};
@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Get('')
public async getGewisPosters(
@Query() alwaysReturnBorrelPosters?: boolean,
): Promise<GewisPosterResponse> {
if (!this.screenHandler.posterManager.posters) {
try {
await this.screenHandler.posterManager.fetchPosters();
} catch (e) {
logger.error(e);
}
}

@Security(SecurityNames.LOCAL, securityGroups.poster.privileged)
@Post('force-update')
public async forceUpdateGewisPosters(@Request() req: ExpressRequest): Promise<void> {
super.forceUpdatePosters(req);
const posters = this.screenHandler.posterManager.posters ?? [];
if (alwaysReturnBorrelPosters || this.screenHandler.borrelMode) {
return {
posters,
borrelMode: this.screenHandler.borrelMode,
};
}
return {
posters: posters.filter((p) => !p.borrelMode),
borrelMode: false,
};
}

@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Get('borrel-mode')
public async getPosterBorrelMode(): Promise<BorrelModeParams> {
return { enabled: this.screenHandler.borrelMode };
}
@Security(SecurityNames.LOCAL, securityGroups.poster.privileged)
@Post('force-update')
public async forceUpdateGewisPosters(@Request() req: ExpressRequest): Promise<void> {
super.forceUpdatePosters(req);
}

@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Put('borrel-mode')
public async setPosterBorrelMode(
@Request() req: ExpressRequest,
@Body() body: BorrelModeParams,
): Promise<void> {
logger.audit(
req.user,
`Set poster screen borrel mode to "${body.enabled ? 'true' : 'false'}".`,
);
this.screenHandler.setBorrelModeEnabled(body.enabled);
}
@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Get('borrel-mode')
public async getPosterBorrelMode(): Promise<BorrelModeParams> {
return { enabled: this.screenHandler.borrelMode };
}

@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Get('train-departures')
public async getTrains(): Promise<TrainResponse[]> {
return super.getTrains();
}
@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Put('borrel-mode')
public async setPosterBorrelMode(
@Request() req: ExpressRequest,
@Body() body: BorrelModeParams,
): Promise<void> {
logger.audit(
req.user,
`Set poster screen borrel mode to "${body.enabled ? 'true' : 'false'}".`,
);
this.screenHandler.setBorrelModeEnabled(body.enabled);
}

@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Post('photo')
public async getPhoto(@Body() params: GEWISPhotoAlbumParams) {
return new GEWISPosterService().getPhoto(params);
}
@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Get('train-departures')
public async getTrains(): Promise<TrainResponse[]> {
return super.getTrains();
}

@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Get('olympics/medal-table')
public async getOlympicsMedalTable() {
return super.getOlympicsMedalTable();
}
@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Post('photo')
public async getPhoto(@Body() params: GEWISPhotoAlbumParams) {
return new GEWISPosterService().getPhoto(params);
}

@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Get('olympics/country-medals')
public async getDutchOlympicMedals() {
return new OlympicsService().getDutchMedals();
}
}
@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Get('olympics/medal-table')
public async getOlympicsMedalTable() {
return super.getOlympicsMedalTable();
}

@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Get('olympics/country-medals')
public async getDutchOlympicMedals() {
return new OlympicsService().getDutchMedals();
}
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
import BasePosterScreenHandler from "../base-poster-screen-handler";
import { Namespace } from "socket.io";
import { FeatureEnabled } from "../../../../server-settings";
import BasePosterScreenHandler from '../base-poster-screen-handler';
import { Namespace } from 'socket.io';
import { FeatureEnabled } from '../../../../server-settings';

@FeatureEnabled('GewisPosterScreenHandler')
export default class GewisPosterScreenHandler extends BasePosterScreenHandler {
private borrelModeDay: number | undefined;
private borrelModeDay: number | undefined;

public borrelModeInterval: NodeJS.Timeout;
public borrelModeInterval: NodeJS.Timeout;

constructor(socket: Namespace) {
super(socket);
constructor(socket: Namespace) {
super(socket);

// Check whether we need to enable/disable borrel mode
this.borrelModeInterval = setInterval(this.checkBorrelMode.bind(this), 60 * 1000);
}
// Check whether we need to enable/disable borrel mode
this.borrelModeInterval = setInterval(this.checkBorrelMode.bind(this), 60 * 1000);
}

public get borrelMode() {
return this.borrelModeDay !== undefined;
}

public get borrelMode() {
return this.borrelModeDay !== undefined;
}
private checkBorrelMode() {
const now = new Date();

private checkBorrelMode() {
const now = new Date();

// If borrelmode is enabled, but we arrive at the next day, disable borrelmode again
if (this.borrelMode && this.borrelModeDay !== now.getDay()) {
this.borrelModeDay = undefined;
return;
}
// if borrelmode is enabled, we do not have to check whether we can enable it
if (this.borrelMode) return;

// By default, enable borrelmode on Thursdays 16:30 local time
if (
now.getDay() === 4 &&
((now.getHours() === 16 && now.getMinutes() >= 30) || now.getHours() >= 17)
) {
this.borrelModeDay = now.getDay();
}
// If borrelmode is enabled, but we arrive at the next day, disable borrelmode again
if (this.borrelMode && this.borrelModeDay !== now.getDay()) {
this.borrelModeDay = undefined;
return;
}
// if borrelmode is enabled, we do not have to check whether we can enable it
if (this.borrelMode) return;

// By default, enable borrelmode on Thursdays 16:30 local time
if (
now.getDay() === 4 &&
((now.getHours() === 16 && now.getMinutes() >= 30) || now.getHours() >= 17)
) {
this.borrelModeDay = now.getDay();
}
}

public setBorrelModeEnabled(enabled: boolean) {
if (enabled) {
this.borrelModeDay = new Date().getDay();
} else {
this.borrelModeDay = undefined;
}
public setBorrelModeEnabled(enabled: boolean) {
if (enabled) {
this.borrelModeDay = new Date().getDay();
} else {
this.borrelModeDay = undefined;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
import {BasePosterResponse, BasePosterScreenController} from "../base-poster-screen-controller";
import HandlerManager from "../../../../root/handler-manager";
import {Screen} from "../../../../root/entities";
import BasePosterScreenHandler from "../base-poster-screen-handler";
import {HubblePosterScreenHandler} from "../../index";
import {Get, Post, Request, Route, Security, Tags} from "tsoa";
import {SecurityNames} from "../../../../../helpers/security";
import {securityGroups} from "../../../../../helpers/security-groups";
import {Request as ExpressRequest} from "express";
import {FeatureEnabled} from "../../../../server-settings";
import { BasePosterResponse, BasePosterScreenController } from '../base-poster-screen-controller';
import HandlerManager from '../../../../root/handler-manager';
import { Screen } from '../../../../root/entities';
import BasePosterScreenHandler from '../base-poster-screen-handler';
import { HubblePosterScreenHandler } from '../../index';
import { Get, Post, Request, Route, Security, Tags } from 'tsoa';
import { SecurityNames } from '../../../../../helpers/security';
import { securityGroups } from '../../../../../helpers/security-groups';
import { Request as ExpressRequest } from 'express';
import { FeatureEnabled } from '../../../../server-settings';

@Route('handler/screen/hubble-poster')
@Tags('Handlers')
@FeatureEnabled('HubblePosterScreenHandler')
export class HubblePosterScreenController extends BasePosterScreenController {
constructor() {
super();
this.screenHandler = HandlerManager.getInstance()
.getHandlers(Screen)
.filter((h) => h.constructor.name === HubblePosterScreenHandler.name)[0] as BasePosterScreenHandler;
}
constructor() {
super();
this.screenHandler = HandlerManager.getInstance()
.getHandlers(Screen)
.filter(
(h) => h.constructor.name === HubblePosterScreenHandler.name,
)[0] as BasePosterScreenHandler;
}

@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Get('')
public async getHubblePosters(): Promise<BasePosterResponse> {
return super.getPosters();
}
@Security(SecurityNames.LOCAL, securityGroups.poster.base)
@Get('')
public async getHubblePosters(): Promise<BasePosterResponse> {
return super.getPosters();
}

@Security(SecurityNames.LOCAL, securityGroups.poster.privileged)
@Post('force-update')
public async forceUpdateHubblePosters(@Request() req: ExpressRequest): Promise<void> {
super.forceUpdatePosters(req);
}
}
@Security(SecurityNames.LOCAL, securityGroups.poster.privileged)
@Post('force-update')
public async forceUpdateHubblePosters(@Request() req: ExpressRequest): Promise<void> {
super.forceUpdatePosters(req);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import BasePosterScreenHandler from "../base-poster-screen-handler";
import { Namespace } from "socket.io";
import {FeatureEnabled} from "../../../../server-settings";
import BasePosterScreenHandler from '../base-poster-screen-handler';
import { Namespace } from 'socket.io';
import { FeatureEnabled } from '../../../../server-settings';

@FeatureEnabled('HubblePosterScreenHandler')
export default class HubblePosterScreenHandler extends BasePosterScreenHandler {
constructor(socket: Namespace) {
super(socket);
}
}
constructor(socket: Namespace) {
super(socket);
}
}
Loading

0 comments on commit da00b41

Please sign in to comment.