2017-12-24 09:02:57 +00:00
|
|
|
import { GET, Path, PathParam, POST, QueryParam } from "typescript-rest";
|
|
|
|
import { ApiError } from "../ApiError";
|
|
|
|
import { DimensionAdminService } from "./DimensionAdminService";
|
|
|
|
import { DimensionIntegrationsService, IntegrationsResponse } from "./DimensionIntegrationsService";
|
|
|
|
import { WidgetStore } from "../../db/WidgetStore";
|
2018-03-24 03:01:56 +00:00
|
|
|
import { Cache, CACHE_INTEGRATIONS } from "../../MemoryCache";
|
2017-12-24 09:02:57 +00:00
|
|
|
|
|
|
|
interface SetEnabledRequest {
|
|
|
|
enabled: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface SetOptionsRequest {
|
|
|
|
options: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Path("/api/v1/dimension/admin/integrations")
|
|
|
|
export class DimensionIntegrationsAdminService {
|
|
|
|
|
|
|
|
@POST
|
|
|
|
@Path(":category/:type/options")
|
2018-03-24 03:01:56 +00:00
|
|
|
public async setOptions(@QueryParam("scalar_token") scalarToken: string, @PathParam("category") category: string, @PathParam("type") type: string, body: SetOptionsRequest): Promise<any> {
|
|
|
|
await DimensionAdminService.validateAndGetAdminTokenOwner(scalarToken);
|
|
|
|
|
|
|
|
if (category === "widget") await WidgetStore.setOptions(type, body.options);
|
|
|
|
else throw new ApiError(400, "Unrecognized category");
|
|
|
|
|
|
|
|
Cache.for(CACHE_INTEGRATIONS).clear();
|
|
|
|
return {}; // 200 OK
|
2017-12-24 09:02:57 +00:00
|
|
|
}
|
|
|
|
|
2018-03-24 03:01:56 +00:00
|
|
|
|
2017-12-24 09:02:57 +00:00
|
|
|
@POST
|
|
|
|
@Path(":category/:type/enabled")
|
2018-03-24 03:01:56 +00:00
|
|
|
public async setEnabled(@QueryParam("scalar_token") scalarToken: string, @PathParam("category") category: string, @PathParam("type") type: string, body: SetEnabledRequest): Promise<any> {
|
|
|
|
await DimensionAdminService.validateAndGetAdminTokenOwner(scalarToken);
|
|
|
|
|
|
|
|
if (category === "widget") await WidgetStore.setEnabled(type, body.enabled);
|
|
|
|
else throw new ApiError(400, "Unrecognized category");
|
|
|
|
|
|
|
|
Cache.for(CACHE_INTEGRATIONS).clear();
|
|
|
|
return {}; // 200 OK
|
2017-12-24 09:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@Path("all")
|
2018-03-24 03:01:56 +00:00
|
|
|
public async getAllIntegrations(@QueryParam("scalar_token") scalarToken: string): Promise<IntegrationsResponse> {
|
|
|
|
await DimensionAdminService.validateAndGetAdminTokenOwner(scalarToken);
|
|
|
|
return DimensionIntegrationsService.getIntegrations(null);
|
2017-12-24 09:02:57 +00:00
|
|
|
}
|
|
|
|
}
|