Skip to content

Commit

Permalink
fix request
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio1988 committed Dec 15, 2023
1 parent cb656b7 commit 1441e86
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 3 additions & 0 deletions packages/client/src/app/jobs/executeJobModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1441e86

Please sign in to comment.