diff --git a/.gitignore b/.gitignore
index 55645c06..fb3080b9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,9 +1,10 @@
-.DS_store
+.DS_Store
.tool-versions
.history
.clj-kondo
.lsp
node_modules
.temp
+.vscode
diff --git a/backend/src/app.ts b/backend/src/app.ts
index 729ec945..e426ca2f 100644
--- a/backend/src/app.ts
+++ b/backend/src/app.ts
@@ -52,10 +52,10 @@ async function run() {
await Promise.all([
setupReportQueue(),
setupMailQueue(),
- setupSapSyncQueue(),
- setupDailySapSyncQueue(),
- setupEnvironmentCodeReportQueue(),
- setupBlanketContractReportQueue(),
+ env.enabledFeatures.sapSync ? setupSapSyncQueue() : null,
+ env.enabledFeatures.sapSync ? setupDailySapSyncQueue() : null,
+ env.enabledFeatures.sapSync ? setupEnvironmentCodeReportQueue() : null,
+ env.enabledFeatures.sapSync ? setupBlanketContractReportQueue() : null,
setupDetailPlanGeomSyncQueue(),
]);
// https://github.com/fastify/fastify/issues/4960
diff --git a/backend/src/router/index.ts b/backend/src/router/index.ts
index fd543f9c..535d1e42 100644
--- a/backend/src/router/index.ts
+++ b/backend/src/router/index.ts
@@ -2,6 +2,7 @@ import { inferAsyncReturnType, initTRPC } from '@trpc/server';
import { CreateFastifyContextOptions } from '@trpc/server/adapters/fastify';
import superjson from 'superjson';
+import { env } from '@backend/env';
import { logger } from '@backend/logging';
import { createCodeRouter } from '@backend/router/code';
import { createCompanyRouter } from '@backend/router/company';
diff --git a/backend/src/router/sapReport.ts b/backend/src/router/sapReport.ts
index ce0b2630..6712a8f1 100644
--- a/backend/src/router/sapReport.ts
+++ b/backend/src/router/sapReport.ts
@@ -1,3 +1,4 @@
+import { TRPCError } from '@trpc/server';
import { z } from 'zod';
import {
@@ -14,6 +15,7 @@ import {
import { startEnvironmentCodeReportJob } from '@backend/components/sap/environmentCodeReportQueue';
import { getLastSyncedAt } from '@backend/components/sap/syncQueue';
import { getPool, sql } from '@backend/db';
+import { env } from '@backend/env';
import { EXPLICIT_EMPTY } from '@shared/schema/code';
import {
@@ -25,60 +27,71 @@ import {
import { TRPC } from '.';
-export const createSapReportRouter = (t: TRPC) =>
- t.router({
- getLastSyncedAt: t.procedure.query(async () => {
+export const createSapReportRouter = (t: TRPC) => {
+ const baseProcedure = t.procedure.use(async (opts) => {
+ if (env.enabledFeatures.sapSync) {
+ return opts.next();
+ } else {
+ throw new TRPCError({
+ code: 'BAD_REQUEST',
+ message: 'SAP report feature is disabled',
+ });
+ }
+ });
+
+ return t.router({
+ getLastSyncedAt: baseProcedure.query(async () => {
return await getLastSyncedAt();
}),
- getEnvironmentCodeReport: t.procedure
+ getEnvironmentCodeReport: baseProcedure
.input(environmentCodeReportQuerySchema)
.query(async ({ input }) => {
return await getEnvironmentCodeReport(input);
}),
- getEnvironmentCodeReportRowCount: t.procedure
+ getEnvironmentCodeReportRowCount: baseProcedure
.input(environmentCodeReportFilterSchema)
.query(async ({ input }) => {
return await getEnvironmentCodeReportRowCount(input);
}),
- getEnvironmentCodeReportSummary: t.procedure
+ getEnvironmentCodeReportSummary: baseProcedure
.input(environmentCodeReportFilterSchema)
.query(async ({ input }) => {
return await getEnvironmentCodeReportSummary(input);
}),
- startEnvironmentCodeReportJob: t.procedure
+ startEnvironmentCodeReportJob: baseProcedure
.input(environmentCodeReportFilterSchema)
.query(async ({ input }) => {
return await startEnvironmentCodeReportJob(input);
}),
- getBlanketContractReport: t.procedure
+ getBlanketContractReport: baseProcedure
.input(blanketContractReportQuerySchema)
.query(async ({ input }) => {
return await getBlanketContractReport(input);
}),
- getBlanketContractReportRowCount: t.procedure
+ getBlanketContractReportRowCount: baseProcedure
.input(blanketContractReportFilterSchema)
.query(async ({ input }) => {
return await getBlanketContractReportRowCount(input);
}),
- getBlanketContractReportSummary: t.procedure
+ getBlanketContractReportSummary: baseProcedure
.input(blanketContractReportFilterSchema)
.query(async ({ input }) => {
return await getBlanketContractReportSummary(input);
}),
- startBlanketContractReportJob: t.procedure
+ startBlanketContractReportJob: baseProcedure
.input(blanketContractReportFilterSchema)
.query(async ({ input }) => {
return await startBlanketContractReportJob(input);
}),
- getPlants: t.procedure.query(async () => {
+ getPlants: baseProcedure.query(async () => {
const { rows } = await getPool().query(sql.type(z.object({ plant: z.string() }))`
SELECT DISTINCT plant FROM app.sap_wbs
WHERE plant IS NOT NULL
@@ -88,7 +101,7 @@ export const createSapReportRouter = (t: TRPC) =>
return [EXPLICIT_EMPTY, ...plants];
}),
- getBlanketOrderIds: t.procedure.input(z.object({})).query(async () => {
+ getBlanketOrderIds: baseProcedure.input(z.object({})).query(async () => {
const { rows } = await getPool().query(sql.type(z.object({ blanketOrderId: z.string() }))`
SELECT DISTINCT blanket_order_id AS "blanketOrderId"
FROM app.sap_wbs
@@ -102,7 +115,7 @@ export const createSapReportRouter = (t: TRPC) =>
return rows.map((row) => row.blanketOrderId);
}),
- getYears: t.procedure.query(async () => {
+ getYears: baseProcedure.query(async () => {
const { rows } = await getPool().query(
sql.type(z.object({ year: z.number() }))`
SELECT DISTINCT fiscal_year "year" FROM app.sap_actuals_item
@@ -113,7 +126,7 @@ export const createSapReportRouter = (t: TRPC) =>
return rows.map((row) => row.year);
}),
- getConsultCompanies: t.procedure.query(async () => {
+ getConsultCompanies: baseProcedure.query(async () => {
const { rows } = await getPool().query(sql.type(z.object({ name: z.string() }))`
SELECT DISTINCT consult_company AS "name" FROM app.sap_wbs
WHERE consult_company IS NOT NULL
@@ -122,3 +135,4 @@ export const createSapReportRouter = (t: TRPC) =>
return rows.map((row) => row.name);
}),
});
+};
diff --git a/frontend/.env b/frontend/.env
new file mode 100644
index 00000000..b225f173
--- /dev/null
+++ b/frontend/.env
@@ -0,0 +1,2 @@
+# No secrets etc. here. Vite build time definitions e.g. feature flags
+VITE_FEATURE_SAP_REPORTS=false
diff --git a/frontend/.gitignore b/frontend/.gitignore
index b5ec1bd8..94d788f7 100644
--- a/frontend/.gitignore
+++ b/frontend/.gitignore
@@ -1,5 +1,4 @@
node_modules
-.env
dist
build
.history
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index e058c9e1..4c281ebe 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -73,7 +73,9 @@ const router = createBrowserRouter(
path="asemakaavahanke/:projectId/kohde/:projectObjectId/:tabView"
element={}
/>
- } />
+ {import.meta.env.VITE_FEATURE_SAP_REPORTS === 'true' && (
+ } />
+ )}
} />
} />
} />
diff --git a/frontend/src/Layout.tsx b/frontend/src/Layout.tsx
index 8694c7e5..f989d7cc 100644
--- a/frontend/src/Layout.tsx
+++ b/frontend/src/Layout.tsx
@@ -109,10 +109,12 @@ function Navbar() {
{tr('pages.projectsTitle')}
-
+ {import.meta.env.VITE_FEATURE_SAP_REPORTS === 'true' && (
+
+ )}