Skip to content

Commit

Permalink
Fix README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Jun 25, 2024
1 parent 33b80ac commit 79de5bc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ That will add two routes:
- POST .../api/v1/push/*passTypeIdentifier*/*passBarcode* (Sends notifications)
- GET .../api/v1/push/*passTypeIdentifier*/*passBarcode* (Retrieves a list of push tokens which would be sent a notification)

Whether you include the routes or not, you'll want to add a middleware that sends push notifications when your pass data updates. You can implement it like so:
Whether you include the routes or not, you'll want to add a model middleware that sends push notifications and updates the `updatedAt` field when your pass data updates. The model middleware could also create and link the `PKPass` during the creation of the pass data, depending on your requirements. You can implement it like so:

```swift
import Vapor
Expand All @@ -233,8 +233,11 @@ struct PassDataMiddleware: AsyncModelMiddleware {
}

func update(model: PassData, on db: Database, next: AnyAsyncModelResponder) async throws {
let pkPass = try await model.$pass.get(on: db)
pkPass.updatedAt = Date()
try await pkPass.save(on: db)
try await next.update(model, on: db)
try await Passes.sendPushNotifications(for: model.$pass.get(on: db), on: db, app: self.app)
try await Passes.sendPushNotifications(for: pkPass, on: db, app: self.app)
}
}
```
Expand Down

0 comments on commit 79de5bc

Please sign in to comment.