diff --git a/server/db-migrations/0.7.0.sql b/server/db-migrations/0.7.0.sql new file mode 100644 index 0000000..447ac52 --- /dev/null +++ b/server/db-migrations/0.7.0.sql @@ -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 +); diff --git a/server/package.json b/server/package.json index 46b0884..d840a0a 100644 --- a/server/package.json +++ b/server/package.json @@ -1,6 +1,6 @@ { "name": "mobile-passport", - "version": "0.6.0", + "version": "0.7.0", "private": true, "scripts": { "dev": "next dev", diff --git a/server/pages/api/apple/v1/passes/[passTypeIdentifier]/[serialNumber].ts b/server/pages/api/apple/v1/passes/[passTypeIdentifier]/[serialNumber].ts index 868e114..7c11cd5 100644 --- a/server/pages/api/apple/v1/passes/[passTypeIdentifier]/[serialNumber].ts +++ b/server/pages/api/apple/v1/passes/[passTypeIdentifier]/[serialNumber].ts @@ -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 = '
' // TODO const ensName: string = '' // TODO const filePath: string = Passes.generatePass( - Platform.Apple, + platform, templateVersion, passportID, issueDateTimestamp, diff --git a/server/pages/api/downloadPass.ts b/server/pages/api/downloadPass.ts index ec5485d..c37bbc5 100644 --- a/server/pages/api/downloadPass.ts +++ b/server/pages/api/downloadPass.ts @@ -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) { @@ -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,