mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
add data to repository instead of shared memory
This commit is contained in:
148
src/testData.ts
148
src/testData.ts
@@ -1,39 +1,31 @@
|
|||||||
// Mock data
|
// Mock data
|
||||||
import { Eta, OrderedStop, Route, Shuttle, Stop, System } from "./generated/graphql";
|
import { IOrderedStop, IRoute, IShuttle, IStop, ISystem, Repository } from "./repository";
|
||||||
import { SharedMemory } from "./sharedMemory";
|
|
||||||
|
|
||||||
const systems: System[] = [
|
const systems: ISystem[] = [
|
||||||
{
|
{
|
||||||
id: "1",
|
id: "1",
|
||||||
name: "Chapman University",
|
name: "Chapman University",
|
||||||
routes: [],
|
|
||||||
stops: [],
|
|
||||||
shuttles: [],
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const routes: Route[] = [
|
const routes: IRoute[] = [
|
||||||
{
|
{
|
||||||
name: "Red Route",
|
name: "Red Route",
|
||||||
id: "1",
|
id: "1",
|
||||||
system: systems[0],
|
systemId: systems[0].id,
|
||||||
orderedStops: [],
|
|
||||||
shuttles: [],
|
|
||||||
polylineCoordinates: [],
|
polylineCoordinates: [],
|
||||||
color: "#ffffff",
|
color: "#ffffff",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Teal Route",
|
name: "Teal Route",
|
||||||
id: "2",
|
id: "2",
|
||||||
system: systems[0],
|
systemId: systems[0].id,
|
||||||
orderedStops: [],
|
|
||||||
shuttles: [],
|
|
||||||
polylineCoordinates: [],
|
polylineCoordinates: [],
|
||||||
color: "#ffffff",
|
color: "#ffffff",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const stops: Stop[] = [
|
const stops: IStop[] = [
|
||||||
{
|
{
|
||||||
id: "1",
|
id: "1",
|
||||||
name: "Chapman Court",
|
name: "Chapman Court",
|
||||||
@@ -41,9 +33,7 @@ const stops: Stop[] = [
|
|||||||
latitude: 33.796001,
|
latitude: 33.796001,
|
||||||
longitude: -117.8892805,
|
longitude: -117.8892805,
|
||||||
},
|
},
|
||||||
system: systems[0],
|
systemId: systems[0].id,
|
||||||
etas: [],
|
|
||||||
orderedStops: [],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "2",
|
id: "2",
|
||||||
@@ -52,45 +42,43 @@ const stops: Stop[] = [
|
|||||||
latitude: 33.804433,
|
latitude: 33.804433,
|
||||||
longitude: -117.895966,
|
longitude: -117.895966,
|
||||||
},
|
},
|
||||||
system: systems[0],
|
systemId: systems[0].id,
|
||||||
etas: [],
|
|
||||||
orderedStops: [],
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const orderedStopsForRedRoute: OrderedStop[] = [
|
// const orderedStopsForRedRoute: IOrderedStop[] = [
|
||||||
{
|
// {
|
||||||
route: routes[0],
|
// routeId: routes[0].id,
|
||||||
stop: stops[0],
|
// stopId: stops[0].id
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
route: routes[0],
|
// route: routes[0],
|
||||||
stop: stops[1],
|
// stop: stops[1],
|
||||||
},
|
// },
|
||||||
];
|
// ];
|
||||||
|
//
|
||||||
|
// const orderedStopsForTealRoute: OrderedStop[] = [
|
||||||
|
// {
|
||||||
|
// route: routes[1],
|
||||||
|
// stop: stops[1],
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// route: routes[1],
|
||||||
|
// stop: stops[0],
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
|
||||||
const orderedStopsForTealRoute: OrderedStop[] = [
|
// orderedStopsForRedRoute[0].nextStop = orderedStopsForRedRoute[1];
|
||||||
{
|
// orderedStopsForRedRoute[1].previousStop = orderedStopsForRedRoute[0];
|
||||||
route: routes[1],
|
// orderedStopsForTealRoute[0].nextStop = orderedStopsForTealRoute[1];
|
||||||
stop: stops[1],
|
// orderedStopsForTealRoute[1].previousStop = orderedStopsForTealRoute[0];
|
||||||
},
|
|
||||||
{
|
|
||||||
route: routes[1],
|
|
||||||
stop: stops[0],
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
orderedStopsForRedRoute[0].nextStop = orderedStopsForRedRoute[1];
|
// stops[0].orderedStops = [orderedStopsForRedRoute[0], orderedStopsForTealRoute[1]];
|
||||||
orderedStopsForRedRoute[1].previousStop = orderedStopsForRedRoute[0];
|
// stops[1].orderedStops = [orderedStopsForRedRoute[1], orderedStopsForTealRoute[0]];
|
||||||
orderedStopsForTealRoute[0].nextStop = orderedStopsForTealRoute[1];
|
// routes[0].orderedStops = orderedStopsForRedRoute;
|
||||||
orderedStopsForTealRoute[1].previousStop = orderedStopsForTealRoute[0];
|
// routes[1].orderedStops = orderedStopsForTealRoute;
|
||||||
|
|
||||||
stops[0].orderedStops = [orderedStopsForRedRoute[0], orderedStopsForTealRoute[1]];
|
const shuttles: IShuttle[] = [
|
||||||
stops[1].orderedStops = [orderedStopsForRedRoute[1], orderedStopsForTealRoute[0]];
|
|
||||||
routes[0].orderedStops = orderedStopsForRedRoute;
|
|
||||||
routes[1].orderedStops = orderedStopsForTealRoute;
|
|
||||||
|
|
||||||
const shuttles: Shuttle[] = [
|
|
||||||
{
|
{
|
||||||
name: "Red Shuttle 17",
|
name: "Red Shuttle 17",
|
||||||
id: "1",
|
id: "1",
|
||||||
@@ -98,33 +86,47 @@ const shuttles: Shuttle[] = [
|
|||||||
latitude: 33.796001,
|
latitude: 33.796001,
|
||||||
longitude: -117.8892805,
|
longitude: -117.8892805,
|
||||||
},
|
},
|
||||||
route: routes[0],
|
routeId: routes[0].id,
|
||||||
system: systems[0],
|
systemId: systems[0].id,
|
||||||
etas: [],
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const etas: Eta[] = [
|
// const etas: Eta[] = [
|
||||||
{
|
// {
|
||||||
stop: stops[0],
|
// stop: stops[0],
|
||||||
shuttle: shuttles[0],
|
// shuttle: shuttles[0],
|
||||||
secondsRemaining: 12.023,
|
// secondsRemaining: 12.023,
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
stop: stops[1],
|
// stop: stops[1],
|
||||||
shuttle: shuttles[0],
|
// shuttle: shuttles[0],
|
||||||
secondsRemaining: 600.123,
|
// secondsRemaining: 600.123,
|
||||||
}
|
// }
|
||||||
];
|
// ];
|
||||||
|
|
||||||
shuttles[0].etas = etas;
|
// shuttles[0].etas = etas;
|
||||||
|
//
|
||||||
|
// routes[0].shuttles = shuttles;
|
||||||
|
//
|
||||||
|
// systems[0].stops = stops;
|
||||||
|
// systems[0].routes = routes;
|
||||||
|
// systems[0].shuttles = shuttles;
|
||||||
|
|
||||||
routes[0].shuttles = shuttles;
|
// export function loadTestData(sharedMemory: SharedMemory) {
|
||||||
|
// sharedMemory.systems = systems;
|
||||||
|
// }
|
||||||
|
|
||||||
systems[0].stops = stops;
|
export async function loadTestData(repository: Repository) {
|
||||||
systems[0].routes = routes;
|
await Promise.all(systems.map(async (system) => {
|
||||||
systems[0].shuttles = shuttles;
|
await repository.addOrUpdateSystem(system);
|
||||||
|
}));
|
||||||
export function loadTestData(sharedMemory: SharedMemory) {
|
await Promise.all(routes.map(async (route) => {
|
||||||
sharedMemory.systems = systems;
|
await repository.addOrUpdateRoute(route);
|
||||||
|
}));
|
||||||
|
await Promise.all(shuttles.map(async (shuttle) => {
|
||||||
|
await repository.addOrUpdateShuttle(shuttle);
|
||||||
|
}));
|
||||||
|
await Promise.all(stops.map(async (stop) => {
|
||||||
|
await repository.addOrUpdateStop(stop);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user