Skip to content

Commit

Permalink
feat(apple): store pass details during download (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
aahna-ashina committed Sep 8, 2022
1 parent 659d80c commit 90afce2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
11 changes: 11 additions & 0 deletions server/db-migrations/0.7.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
create type platform as enum ('Apple', 'Google');
create table downloads (
id bigint generated by default as identity primary key,
time_of_download timestamp without time zone default now() not null,
platform platform not null,
template_version int not null,
passport_id bigint not null,
issue_date timestamp without time zone not null,
address text not null,
ens_name text
);
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobile-passport",
"version": "0.6.0",
"version": "0.7.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
// TODO

// Populate the pass template
const platform: Platform = Platform.Apple
const templateVersion: number = config.appleTemplateVersion
const passportID: string = String(serialNumber)
const issueDateTimestamp: number = 0 // TODO
const address: string = '<address>' // TODO
const ensName: string = '<ensName>' // TODO
const filePath: string = Passes.generatePass(
Platform.Apple,
platform,
templateVersion,
passportID,
issueDateTimestamp,
Expand Down
23 changes: 21 additions & 2 deletions server/pages/api/downloadPass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import PassportIssuer from '../../abis/PassportIssuer.json'
import Passport from '../../abis/Passport.json'
import { ethers } from 'ethers'
import { config } from '../../utils/Config'
import { supabase } from '../../utils/SupabaseClient'

// req = HTTP incoming message, res = HTTP server response
export default function handler(req: NextApiRequest, res: NextApiResponse) {
Expand Down Expand Up @@ -96,10 +97,28 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {

console.log('ensName:', ensName)

// Populate the pass template
// Store pass details (needed for sending updated passes in the future)
const platform: Platform = Platform.Apple
const templateVersion: number = config.appleTemplateVersion
const download = {
platform: Platform[platform],
template_version: templateVersion,
passport_id: passportID,
issue_date: new Date(timestamp * 1000),
address: address,
ens_name: ensName
}
console.log('download:\n', download)
supabase
.from('downloads')
.insert(download)
.then((result: any) => {
console.log('then result:\n', result)
})

// Populate the pass template
const filePath: string = Passes.generatePass(
Platform.Apple,
platform,
templateVersion,
passportID,
timestamp,
Expand Down

0 comments on commit 90afce2

Please sign in to comment.