From 1441e862b0d336d72f358fc1aaa01fb1a03faa39 Mon Sep 17 00:00:00 2001 From: Fabio1988 Date: Fri, 15 Dec 2023 12:29:58 +0100 Subject: [PATCH] fix request --- package.json | 1 + packages/client/src/app/jobs/executeJobModal.tsx | 3 +++ packages/server/src/index.ts | 9 ++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a469c7f..1179718 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dev:server": "nx run server:dev", "lint": "nx run-many --target=lint --all", "start": "node dist/packages/server/main.js", + "test": "NODE_ENV=development NX_ENABLE_MOCKS=1 nx run-many --target=dev --all", "clear-cache": "nx clear-cache" }, "volta": { diff --git a/packages/client/src/app/jobs/executeJobModal.tsx b/packages/client/src/app/jobs/executeJobModal.tsx index 2c751cf..3064289 100644 --- a/packages/client/src/app/jobs/executeJobModal.tsx +++ b/packages/client/src/app/jobs/executeJobModal.tsx @@ -17,6 +17,9 @@ export const ExecuteJobModal = ({ closeModal, devices, jobId }: ExecuteJobModalP async ({ deviceIds }: { deviceIds: string[] | number[] }) => { const promise = fetch(`/api/job/execute/${jobId}`, { method: 'POST', + headers: { + 'Content-Type': 'application/json', // Set the Content-Type header to application/json + }, body: JSON.stringify({ deviceIdsOrOrigins: deviceIds }), }).then(async (response) => { if (response.status !== 200) { diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index d86acd9..4f68229 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -537,13 +537,20 @@ const routes = async (fastifyInstance: FastifyInstance) => { jobId: string; } - fastifyInstance.post<{ Params: JobExecuteParams; Body: { deviceIdsOrOrigins?: string[] | number[] } }>( + interface DeviceIdsOrOriginsBody { + deviceIdsOrOrigins?: string[] | number[]; + } + + fastifyInstance.post<{ Params: JobExecuteParams; Body: DeviceIdsOrOriginsBody }>( '/api/job/execute/:jobId/:deviceIdsOrOrigins?', async (req, reply) => { const { deviceIdsOrOrigins, jobId } = req.params; const requestBody = req.body; const job = jobs.getById(jobId); + log.info(`${deviceIdsOrOrigins}`); + log.info(`${requestBody.deviceIdsOrOrigins}`); + log.info(`${requestBody}`); if (!job) { reply.code(404).send({ status: 'error', error: 'Job not found' }); return;