This commit is contained in:
@@ -78,4 +78,21 @@ export async function registerAdminExportRoutes(app, options) {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/exports/jobs/:id/download', async (request, reply) => {
|
||||
const job = await adminExportService.getExportJob({
|
||||
sellerId: request.admin.sellerId,
|
||||
jobId: request.params.id,
|
||||
});
|
||||
if (!job) {
|
||||
throw createApplicationError('EXPORT_JOB_NOT_FOUND', 'Export job was not found.', 404);
|
||||
}
|
||||
if (job.status !== 'COMPLETED' || !Array.isArray(job.output)) {
|
||||
throw createApplicationError('EXPORT_NOT_READY', 'Export is not ready for download.', 409);
|
||||
}
|
||||
return reply
|
||||
.type('application/json; charset=utf-8')
|
||||
.header('content-disposition', 'attachment; filename="inventory.json"')
|
||||
.send(JSON.stringify(job.output));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user