2023-06-20 15:53:27 +00:00
|
|
|
import { router } from "../../trpc/trpc-server";
|
|
|
|
|
|
|
|
import { createLogger } from "../../../lib/logger";
|
|
|
|
import { protectedClientProcedure } from "../../trpc/protected-client-procedure";
|
|
|
|
|
|
|
|
import { z } from "zod";
|
|
|
|
import { TaxJarConnectionService } from "../configuration/taxjar-connection.service";
|
|
|
|
import { TaxJarTaxCodesService } from "./taxjar-tax-codes.service";
|
|
|
|
|
|
|
|
const getAllForIdSchema = z.object({ connectionId: z.string() });
|
|
|
|
|
|
|
|
export const taxJarTaxCodesRouter = router({
|
|
|
|
getAllForId: protectedClientProcedure.input(getAllForIdSchema).query(async ({ ctx, input }) => {
|
|
|
|
const logger = createLogger({
|
|
|
|
name: "taxjarTaxCodesRouter.getAllForId",
|
|
|
|
});
|
|
|
|
|
2023-07-25 09:15:18 +00:00
|
|
|
const connectionService = new TaxJarConnectionService({
|
|
|
|
appId: ctx.appId!,
|
|
|
|
client: ctx.apiClient,
|
|
|
|
saleorApiUrl: ctx.saleorApiUrl,
|
|
|
|
});
|
2023-06-20 15:53:27 +00:00
|
|
|
|
|
|
|
const connection = await connectionService.getById(input.connectionId);
|
|
|
|
const taxCodesService = new TaxJarTaxCodesService(connection.config);
|
|
|
|
|
|
|
|
logger.debug("Returning tax codes");
|
|
|
|
|
|
|
|
return taxCodesService.getAll();
|
|
|
|
}),
|
|
|
|
});
|