Skip to content

Commit

Permalink
add request object to method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
eadmundo committed Oct 10, 2023
1 parent 9cf125c commit a904546
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
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

0 comments on commit a904546

Please sign in to comment.