mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { Resolvers } from "../generated/graphql";
|
|
import { ServerContext } from "../ServerContext";
|
|
|
|
export const ParkingSystemResolvers: Resolvers<ServerContext> = {
|
|
ParkingSystem: {
|
|
parkingStructures: async (parent, _args, contextValue, _info) => {
|
|
const system = contextValue.findSystemById(parent.systemId);
|
|
if (!system) {
|
|
return [];
|
|
}
|
|
const parkingRepository = system.parkingRepository;
|
|
if (!parkingRepository) return [];
|
|
|
|
const parkingStructures = await parkingRepository.getParkingStructures();
|
|
return parkingStructures.map((structure) => {
|
|
return {
|
|
...structure,
|
|
systemId: parent.systemId
|
|
};
|
|
});
|
|
},
|
|
parkingStructure: async (parent, args, contextValue, _info) => {
|
|
if (!args.id) return null;
|
|
|
|
const system = contextValue.findSystemById(parent.systemId);
|
|
if (!system) {
|
|
return null;
|
|
}
|
|
const parkingRepository = system.parkingRepository;
|
|
if (!parkingRepository) return null;
|
|
|
|
const parkingStructure = await parkingRepository.getParkingStructureById(args.id);
|
|
return parkingStructure ? {
|
|
...parkingStructure,
|
|
systemId: parent.systemId,
|
|
} : null;
|
|
},
|
|
}
|
|
}
|