Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add request object to method calls #55

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ Star Micronics provides a [Star Document Markup Designer](https://star-document-
_@autotelic/fastify-cloudprnt_ exports a fastify plugin. When registered the plugin expects a configuration object:

* `queueJob: (token, jobData) => any`: method that takes a url-safe string `token` and an object of data `jobData`, to be passed to [point-of-view](https://github.com/fastify/point-of-view#quick-start) for template rendering, and adds the job to the print queue.
* `getJob: () => token`: method that returns the url-safe string `token` for the next available print job on the queue.
* `getJobData: (token) => object`: method that returns the data object for the job enqueued with the url-safe string `token`.
* `deleteJob: (token) => any`: method that deletes the job enqueued with the url-safe string `token` from the print queue.
* `getJob: (request) => token`: method that returns the url-safe string `token` for the next available print job on the queue. `request` is the fastify request object.
* `getJobData: (token, request) => object`: method that returns the data object for the job enqueued with the url-safe string `token`. `request` is the fastify request object.
* `deleteJob: (token, request) => any`: method that deletes the job enqueued with the url-safe string `token` from the print queue. `request` is the fastify request object.
* `routePrefix: string`: string which will configure a prefix for all cloudprnt routes.
* `defaultTemplate`: string which will configure the default template to be joined with `templatesDir` and used by [`@fastify/point-of-view`](https://github.com/fastify/point-of-view/tree/v3.x) to render the template (default to `receipt.stm`). If `jobData` contains a `template` value, it will be used instead of the `defaultTemplate`.
* `templatesDir`: string which will configure the directory to be joined with either the `defaultTemplate` or `jobData.template` and used by [`@fastify/point-of-view`](https://github.com/fastify/point-of-view/tree/v3.x) to render the template (default to an empty string).
Expand All @@ -74,4 +74,4 @@ An [example](./examples/basic/) fastify app using [node-cache](https://github.co
An [example](./examples/redis/) fastify app using [redis](https://www.npmjs.com/package/redis). To run the redis example, use the following command:
```sh
npm run example:redis
```
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autotelic/fastify-cloudprnt",
"version": "0.3.2-rc.1",
"version": "0.5.0",
"description": "Fastify plugin to run a server following the Star Micronics CloudPRNT protocol.",
"keywords": [
"fastify",
Expand Down
2 changes: 1 addition & 1 deletion routes/main/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
},
handler: async function queueJobHandler (request, reply) {
const { token } = request.query
const deleted = await this.cloudPrnt.deleteJob(token)
const deleted = await this.cloudPrnt.deleteJob(token, request)
const code = deleted
? 200
: 404
Expand Down
2 changes: 1 addition & 1 deletion routes/main/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
formatPrntCommandData
} = this.cloudPrnt

const jobData = await getJobData(token)
const jobData = await getJobData(token, request)
if (jobData === null) {
return reply.code(404).send('Job not found')
}
Expand Down
2 changes: 1 addition & 1 deletion routes/main/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
}
},
handler: async function pollHandler (request, reply) {
const jobToken = await this.cloudPrnt.getJob()
const jobToken = await this.cloudPrnt.getJob(request)
const jobReady = jobToken !== null

let jobReadyResponse = {}
Expand Down