import { ArraySchema, Command, CommandSet, DateTimeConverter, ICommand, ObjectSchema, TypeCode } from "pip-services3-commons-nodex"; import { Parameters } from 'pip-services3-commons-nodex'; import { FireMapUpdateV1, FireMapUpdateV1Schema } from "../data/version1"; import { LocationV1 } from "../data/version1/LocationV1"; import { IFireMapController } from "./IFireMapController"; export class FireMapCommandSet extends CommandSet { private _controller: IFireMapController; public constructor(controller: IFireMapController) { super(); this._controller = controller this.addCommand(this.makeGetTilesCommand()); this.addCommand(this.makeUpdateTilesCommand()); } private makeGetTilesCommand(): ICommand { return new Command( 'get_tiles', new ObjectSchema() .withOptionalProperty('flat', TypeCode.Float) .withOptionalProperty('flng', TypeCode.Float) .withOptionalProperty('tlat', TypeCode.Float) .withOptionalProperty('tlng', TypeCode.Float) .withOptionalProperty('zoom', TypeCode.Integer), async (correlationId: string, args: Parameters) => { let from: LocationV1 = { lat: args.getAsNullableDouble('flat'), long: args.getAsNullableDouble('flng') }; let to: LocationV1 = { lat: args.getAsNullableDouble('tlat'), long: args.getAsNullableDouble('tlng') }; let zoom: number = args.getAsNullableInteger('zoom'); return await this._controller.getTiles(correlationId, from, to, zoom); } ); } private makeUpdateTilesCommand(): ICommand { return new Command( 'update_tiles', new ObjectSchema() .withRequiredProperty('updates', new ArraySchema(new FireMapUpdateV1Schema())), async (correlationId: string, args: Parameters) => { let updates: FireMapUpdateV1[] = args.getAsArray('updates'); for (let i=0; i < updates.length; i++) { updates[i].time = DateTimeConverter.toNullableDateTime(updates[i].time); } return await this._controller.updateTiles(correlationId, updates); } ); } }