UNPKG

@golemio/pid

Version:
54 lines 3.11 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PublicDepartureCacheTransformation = void 0; const AbstractTransformation_1 = require("@golemio/core/dist/helpers/transformation/AbstractTransformation"); const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe"); let PublicDepartureCacheTransformation = class PublicDepartureCacheTransformation extends AbstractTransformation_1.AbstractTransformation { constructor() { super(...arguments); this.name = "PublicDepartureCacheTransformation"; this.transformInternal = (inputDto) => { const flags = {}; if (inputDto.is_night === "1") { flags.night = 1; } if (inputDto.is_regional === "1") { flags.reg = 1; } if (inputDto.is_substitute_transport === "1") { flags.subst = 1; } const outputDto = { stop_id: inputDto.stop_id, departure_datetime: inputDto.departure_datetime.toISOString(), arrival_datetime: inputDto.arrival_datetime?.toISOString() ?? null, route_short_name: inputDto.route_short_name, route_type: inputDto.route_type, trip_id: inputDto.trip_id, stop_sequence: inputDto.stop_sequence, platform_code: inputDto.platform_code, trip_headsign: inputDto.stop_headsign ?? inputDto.trip_headsign, // TODO: One day, when we resolve issues around ajv's handling of undefined/null type unions, // refactor this to only include the property if it's non-nullish, to save Valkey memory // (see <https://golemiocz.slack.com/archives/C03H9T45QTA/p1767640758044149>). trip_headsign_icons: inputDto.trip_headsign_icons ?? null, connections: inputDto.trip_connections ?? null, wheelchair_accessible: inputDto.wheelchair_accessible ?? null, direction_id: inputDto.direction_id ?? null, ...(Object.keys(flags).length > 0 ? { flags } : {}), }; return outputDto; }; } }; exports.PublicDepartureCacheTransformation = PublicDepartureCacheTransformation; exports.PublicDepartureCacheTransformation = PublicDepartureCacheTransformation = __decorate([ (0, tsyringe_1.injectable)() ], PublicDepartureCacheTransformation); //# sourceMappingURL=PublicDepartureCacheTransformation.js.map