Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Deploy latest changes with enrollment endpoint #48

Merged
merged 11 commits into from
Nov 10, 2020
5 changes: 0 additions & 5 deletions .graphqlconfig.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .graphqlrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: 'https://api.entur.io/journey-planner/v2/graphql'
documents: 'src/**/*.{graphql,js,ts,jsx,tsx'
3 changes: 2 additions & 1 deletion cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA', '.']
timeout: 500s
timeout: '1500s'
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA']
- name: 'gcr.io/cloud-builders/gcloud'
Expand All @@ -18,3 +18,4 @@ steps:
- '--allow-unauthenticated'
images:
- gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA
timeout: '1500s'
26 changes: 26 additions & 0 deletions src/api/enrollment/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Hapi from '@hapi/hapi';
import { EnrollmentQuery } from '../../service/types';
import { postEnrollmentGroupRequest } from './schema';
import * as Boom from '@hapi/boom';
import { TICKET_INVITE_KEY } from '../../config/env';

export default (server: Hapi.Server) => () => {
server.route({
method: 'POST',
path: '/bff/v1/enrollment/group',
options: {
description: 'Enroll in beta groups with invite key',
tags: ['api', 'enrollment'],
validate: postEnrollmentGroupRequest
},
handler: async (request, h) => {
const query = (request.query as unknown) as EnrollmentQuery;

if (TICKET_INVITE_KEY && TICKET_INVITE_KEY === query.inviteKey) {
return { status: 'ok', groups: ['ticketing_group'] };
}

return Boom.notFound('Ukjent kode');
}
});
};
7 changes: 7 additions & 0 deletions src/api/enrollment/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Joi from '@hapi/joi';

export const postEnrollmentGroupRequest = {
query: Joi.object({
inviteKey: Joi.string().required()
})
};
2 changes: 2 additions & 0 deletions src/config/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const TICKET_INVITE_KEY: string | undefined =
process.env.TICKET_INVITE_KEY;
24 changes: 24 additions & 0 deletions src/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,11 @@ export type EstimatedCall = {
/** Whether the updated estimates are expected to be inaccurate. */
predictionInaccurate?: Maybe<Scalars['Boolean']>;
realtimeState?: Maybe<RealtimeState>;
/**
* OccupancyStatus.
* @deprecated Not yet officially supported.
*/
occupancyStatus?: Maybe<Occupancy>;
/** Whether vehicle may be boarded at quay. */
forBoarding?: Maybe<Scalars['Boolean']>;
/** Whether vehicle may be alighted at quay. */
Expand Down Expand Up @@ -1427,6 +1432,25 @@ export enum RealtimeState {
Modified = 'modified'
}

export enum Occupancy {
/** The Occupancy is unknown. DEFAULT. */
Unknown = 'unknown',
/** The vehicle is considered empty by most measures, and has few or no passengers onboard, but is still accepting passengers. */
Empty = 'empty',
/** The vehicle has a large percentage of seats available. What percentage of free seats out of the total seats available is to be considered large enough to fall into this category is determined at the discretion of the producer. */
ManySeatsAvailable = 'manySeatsAvailable',
/** The vehicle has a small percentage of seats available. What percentage of free seats out of the total seats available is to be considered small enough to fall into this category is determined at the discretion of the producer. */
FewSeatsAvailable = 'fewSeatsAvailable',
/** The vehicle can currently accommodate only standing passengers. */
StandingRoomOnly = 'standingRoomOnly',
/** The vehicle can currently accommodate only standing passengers and has limited space for them. */
CrushedStandingRoomOnly = 'crushedStandingRoomOnly',
/** The vehicle is considered full by most measures, but may still be allowing passengers to board. */
Full = 'full',
/** The vehicle can not accept passengers. */
NotAcceptingPassengers = 'notAcceptingPassengers'
}

export type KeyValue = {
/** Identifier of value. */
key?: Maybe<Scalars['String']>;
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import geocoderRoutes from './api/geocoder';
import stopsRoutes from './api/stops';
import journeyRoutes from './api/journey';
import healthRoutes from './api/health';
import enrollmentRoutes from './api/enrollment';

import registerMetricsExporter from './utils/metrics';

Expand Down Expand Up @@ -55,6 +56,7 @@ process.on('unhandledRejection', err => {
stopsRoutes(server)(stopsService(enturService));
geocoderRoutes(server)(geocoderService(enturService, pubSubClient));
journeyRoutes(server)(js);
enrollmentRoutes(server)();

registerMetricsExporter(projectId);
await server.initialize();
Expand Down
2 changes: 2 additions & 0 deletions src/service/impl/stops/departures-from-stops.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ fragment quayFields on Quay {
name
description
publicCode
latitude
longitude
situations {
...situationFields
}
Expand Down
4 changes: 3 additions & 1 deletion src/service/impl/stops/departures-from-stops.graphql-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type EstimatedCallFieldsFragment = { actualArrivalTime?: Types.Maybe<any>

export type NoticeFieldsFragment = { text?: Types.Maybe<string> };

export type QuayFieldsFragment = { id: string, name: string, description?: Types.Maybe<string>, publicCode?: Types.Maybe<string>, situations: Array<Types.Maybe<SituationFieldsFragment>>, stopPlace?: Types.Maybe<StopPlaceFieldsFragment> };
export type QuayFieldsFragment = { id: string, name: string, description?: Types.Maybe<string>, publicCode?: Types.Maybe<string>, latitude?: Types.Maybe<number>, longitude?: Types.Maybe<number>, situations: Array<Types.Maybe<SituationFieldsFragment>>, stopPlace?: Types.Maybe<StopPlaceFieldsFragment> };

export type SituationFieldsFragment = { situationNumber?: Types.Maybe<string>, reportType?: Types.Maybe<Types.ReportType>, summary: Array<{ language?: Types.Maybe<string>, value?: Types.Maybe<string> }>, description: Array<{ language?: Types.Maybe<string>, value?: Types.Maybe<string> }>, advice: Array<{ language?: Types.Maybe<string>, value?: Types.Maybe<string> }>, detail: Array<{ language?: Types.Maybe<string>, value?: Types.Maybe<string> }>, lines: Array<Types.Maybe<LineFieldsFragment>>, validityPeriod?: Types.Maybe<{ startTime?: Types.Maybe<any>, endTime?: Types.Maybe<any> }>, infoLinks?: Types.Maybe<Array<Types.Maybe<{ uri?: Types.Maybe<string>, label?: Types.Maybe<string> }>>> };

Expand Down Expand Up @@ -142,6 +142,8 @@ export const QuayFieldsFragmentDoc = gql`
name
description
publicCode
latitude
longitude
situations {
...situationFields
}
Expand Down
52 changes: 16 additions & 36 deletions src/service/impl/stops/departures.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,34 @@
import client from '../../../graphql/graphql-client';
import { Result } from '@badrap/result';
import {
convertPositionToBbox,
Coordinates,
EstimatedCall,
StopPlaceDetails,
Quay,
Situation,
ServiceJourney,
convertPositionToBbox,
Coordinates
Situation,
StopPlaceDetails
} from '@entur/sdk';
import haversineDistance from 'haversine-distance';
import sortBy from 'lodash.sortby';
import client from '../../../graphql/graphql-client';
import paginate from '../../pagination';
import {
DeparturesWithStop,
APIError,
DeparturesFromLocationPagingQuery,
DeparturesMetadata,
DeparturesFromLocationPagingQuery
DeparturesWithStop
} from '../../types';
import { Result } from '@badrap/result';
import paginate from '../../pagination';
import sortBy from 'lodash.sortby';
import haversineDistance from 'haversine-distance';
import { populateCacheIfNotThere } from './departure-time';
import {
ByBBoxDocument,
ByBBoxQueryVariables,
ByBBoxQuery,
ByIdQuery,
ByBBoxQueryVariables,
ByIdDocument,
ByIdQuery,
ByIdQueryVariables,
EstimatedCallFieldsFragment
QuayFieldsFragment
} from './departures-from-stops.graphql-gen';

export type ServiceJourneyWithDirection = ServiceJourney & {
directionType: 'inbound' | 'outbound' | 'clockwise' | 'anticlockwise';
};

export type EstimatedCallWithDirection = EstimatedCall & {
serviceJourney: ServiceJourneyWithDirection;
};

export type EstimatedQuay = Quay & { situations?: Situation[] } & {
estimatedCalls: EstimatedCallWithDirection[];
};

export type StopPlaceDetailsWithEstimatedCalls = StopPlaceDetails & {
quays?: EstimatedQuay[];
};

export type StopDepartures = {
stopPlaces: StopPlaceDetailsWithEstimatedCalls[];
};

export async function getDeparturesFromLocation(
coordinates: Coordinates,
distance: number = 500,
Expand All @@ -58,7 +38,7 @@ export async function getDeparturesFromLocation(

const variables = {
...bbox,
timeRange: 72000,
timeRange: 86400 * 2, // Two days
startTime: options.startTime,
limit: options.limit
};
Expand Down Expand Up @@ -106,7 +86,7 @@ export async function getDeparturesFromStops(
query: ByIdDocument,
variables: {
ids: [id],
timeRange: 72000,
timeRange: 86400 * 2, // Two days
startTime: options.startTime,
limit: options.limit
},
Expand Down
14 changes: 13 additions & 1 deletion src/service/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ export interface DeparturesFromQuayQuery {
includeCancelledTrips: boolean;
}

export interface EnrollmentQuery {
inviteKey: string;
}

export interface TripQuery {
from: string;
to: string;
Expand Down Expand Up @@ -149,10 +153,18 @@ export type DeparturesByIdWithStopName = DeparturesById & {
name: string;
};

export type QuayWithCoordinates = Quay & {
latitude?: number;
longitude?: number;
};

export type DeparturesWithStop = {
stop: StopPlaceDetails;
quays: {
[quayId: string]: { quay: Quay; departures: Array<Departure> };
[quayId: string]: {
quay: QuayWithCoordinates;
departures: Array<Departure>;
};
};
};

Expand Down
17 changes: 17 additions & 0 deletions swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ paths:
schema:
type: string
description: Successful

'/bff/v1/departures-from-location-paging':
post:
summary: Get departures from feature location
Expand Down Expand Up @@ -503,6 +504,22 @@ paths:
schema:
type: string
description: Successful
'/bff/v1/enrollment/group':
post:
summary: Enroll in beta groups with invite key
operationId: postBffV1EnrollmentGroup
parameters:
- type: string
name: inviteKey
in: query
required: true
tags:
- bff
responses:
default:
schema:
type: string
description: Successful
definitions:
coordinates:
type: object
Expand Down