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

Tracks companies for which the privacy policy was accepted by guest #13

Merged
merged 10 commits into from
May 20, 2020
2 changes: 2 additions & 0 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type UpdateCheckin = {

type TicketResponse = {
id?: string
companyId: string
companyName: string
enteredAt?: Date
leftAt?: Date
Expand Down Expand Up @@ -277,6 +278,7 @@ export async function createCheckin({
const checkin = await db.addCheckin({
areaId: ticket.areaId,
id: ticket.id,
companyId: response.companyId,
business: response.companyName,
enteredAt: ticket.enteredAt,
})
Expand Down
12 changes: 12 additions & 0 deletions lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { subDays } from 'date-fns'

export interface Checkin {
id?: string
companyId: string
business: string
enteredAt: Date
areaId: string
Expand All @@ -21,6 +22,7 @@ export interface Guest {
name: string
phone: string
address: string
acceptedPrivacy: string[]
salimhb marked this conversation as resolved.
Show resolved Hide resolved
}

export interface GuestChangeset {
Expand Down Expand Up @@ -176,3 +178,13 @@ export async function updateCheckin(
const checkin = await getCheckin(id)
return checkin
}

export async function setAcceptedPrivacy(companyId: string): Promise<Guest> {
let guest = await db.guests.toCollection().first()
salimhb marked this conversation as resolved.
Show resolved Hide resolved
if (!guest.acceptedPrivacy) guest.acceptedPrivacy = []
if (guest.acceptedPrivacy.indexOf(companyId) < 0)
guest.acceptedPrivacy.push(companyId)
await db.guests.update(guest.id, guest)
guest = await getGuest()
return guest
}
3 changes: 2 additions & 1 deletion pages/checkin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const CheckingPage: React.FC<{}> = () => {
await doCheckout({ id: lastCheckin.id, leftAt: enteredAt.current })
}

await doCheckin({
const checkin = await doCheckin({
ticket: {
publicKey,
areaId,
Expand All @@ -41,6 +41,7 @@ const CheckingPage: React.FC<{}> = () => {
},
guest,
})
await db.setAcceptedPrivacy(checkin.companyId)
router.replace('/my-checkins')
},
[doCheckin, doCheckout, publicKey, areaId, router]
Expand Down