Skip to content

Commit

Permalink
fix show as verified the unverifiable places that are visited (#145)
Browse files Browse the repository at this point in the history
* fix show verified unverifiable

* fix
  • Loading branch information
mauriciabad authored Nov 8, 2023
1 parent 76f6fcf commit 2cbe1c9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import { DividerWithText } from '~/components/generic/divider-with-text'
import { ExplanationCard } from '~/components/generic/explanation-card'
import { LinkButton } from '~/components/links/link-button'
import { MapPoint } from '~/helpers/spatial-data'
import {
VerificationRequirements,
isVerificationRequired,
} from '~/server/db/constants/verifications'
import { trpc } from '~/trpc'
import { useLocationValidator } from '../_hooks/useLocationValidator'

Expand All @@ -46,10 +50,7 @@ export const VerificatePlaceVisitModal: FC<
expectedLocation: MapPoint
placeId: number
isAlreadyVisited: boolean
verificationRequirements: {
isLocationRequired: boolean
maxLocationDistance: number | null
} | null
verificationRequirements: VerificationRequirements | null
}
> = ({
isOpen,
Expand Down Expand Up @@ -146,8 +147,7 @@ export const VerificatePlaceVisitModal: FC<
{session ? (
<ModalBody className="block space-y-2 pb-6 pt-0">
<>
{verificationRequirements &&
verificationRequirements.isLocationRequired ? (
{isVerificationRequired(verificationRequirements) ? (
<>
{verificationRequirements.isLocationRequired && (
<>
Expand Down
6 changes: 4 additions & 2 deletions src/server/api/router/missions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,17 @@ export const missionsRouter = router({
const hasBeenVisited = visitedPlacesIds.has(place.id)
const lastVerification =
verifications.length > 0 ? verifications[0] : null

const isVerificationRequired =
place.verificationRequirements &&
place.verificationRequirements.isLocationRequired
return {
...place,
location: getPoint(location),
categories: categories.map(({ category }) => category),
images: [],
missionStatus: {
visited: hasBeenVisited,
verified: place.verificationRequirements
verified: isVerificationRequired
? Boolean(lastVerification)
: hasBeenVisited,
},
Expand Down
6 changes: 2 additions & 4 deletions src/server/db/constants/missions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
PlaceCategoryColor,
PlaceCategoryIcon as PlaceCategoryIconType,
} from '~/server/db/constants/places'
import { VerificationRequirements } from './verifications'

export type VisitMissionPlace = {
id: number
Expand Down Expand Up @@ -30,10 +31,7 @@ export type VisitMissionPlace = {
visited: boolean
verified: boolean
}
verificationRequirements: {
isLocationRequired: boolean
maxLocationDistance: number | null
} | null
verificationRequirements: VerificationRequirements | null
}

export type VisitMission = {
Expand Down
14 changes: 14 additions & 0 deletions src/server/db/constants/verifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { InferSelectModel } from 'drizzle-orm'
import { verificationRequirements } from '../schema'

export type VerificationRequirements = InferSelectModel<
typeof verificationRequirements
>

export function isVerificationRequired<T extends VerificationRequirements>(
verificationRequirements: T | null
): verificationRequirements is T {
if (!verificationRequirements) return false

return verificationRequirements.isLocationRequired
}
2 changes: 0 additions & 2 deletions src/server/helpers/spatial-data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'server-only'

import { DriverValueMapper, sql } from 'drizzle-orm'
import { customType } from 'drizzle-orm/mysql-core'
import {
Expand Down

0 comments on commit 2cbe1c9

Please sign in to comment.