Skip to content

Commit

Permalink
Merge branch 'dev' into search-page-alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Jun 25, 2024
2 parents 9c8536b + 2447dd7 commit a3cd58d
Show file tree
Hide file tree
Showing 47 changed files with 186 additions and 3,929 deletions.
1 change: 1 addition & 0 deletions InReach.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
"**/zod-schemas/**": true,
"**/.turbo/**": true,
"**/generated/**": true,
"_queries/**": true,
},
"search.exclude": {
"**/node_modules": true,
Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/types/nextjs-routes.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
// This file will be automatically regenerated when your Next.js server is running.
// nextjs-routes version: 2.2.0
// nextjs-routes version: 2.2.1
/* eslint-disable */

// prettier-ignore
Expand Down
52 changes: 52 additions & 0 deletions packages/api/router/location/lib.formatAddressVisibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { PrismaEnums } from '@weareinreach/db'

export const formatAddressVisiblity = (location: ProvidedAddress) => {
const address: ReformattedAddress = {
street1: location.street1,
street2: location.street2,
city: location.city,
postCode: location.postCode,
govDist: location.govDist,
latitude: location.latitude,
longitude: location.longitude,
}
switch (location.addressVisibility) {
case PrismaEnums.AddressVisibility.FULL: {
return address
}
case PrismaEnums.AddressVisibility.PARTIAL: {
address.street1 = null
address.street2 = null
return address
}
case PrismaEnums.AddressVisibility.HIDDEN:
default: {
address.street1 = null
address.street2 = null
address.city = null
address.postCode = null
address.govDist = null
address.latitude = null
address.longitude = null
return address
}
}
}

type ReformattedAddress = {
street1: string | null
street2: string | null
city: string | null
postCode: string | null
govDist: {
tsKey: string
tsNs: string
abbrev: string | null
} | null
latitude: number | null
longitude: number | null
}
type ProvidedAddress = Omit<ReformattedAddress, 'city'> & {
city: string
addressVisibility: PrismaEnums.AddressVisibility
} & Record<string, unknown>
5 changes: 3 additions & 2 deletions packages/api/router/location/mutation.create.schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from 'zod'

import { PrismaEnums } from '@weareinreach/db'
import { prefixedId } from '~api/schemas/idPrefix'

export const ZCreateSchema = z.object({
Expand All @@ -18,9 +19,9 @@ export const ZCreateSchema = z.object({
countryId: z.string(),
})
.partial()
.required({ countryId: true }),
.required({ countryId: true, city: true }),
primary: z.boolean().optional(),
notVisitable: z.boolean().default(false),
addressVisibility: z.nativeEnum(PrismaEnums.AddressVisibility),
published: z.boolean().default(false),
emails: prefixedId('orgEmail').array().optional(),
phones: prefixedId('orgPhone').array().optional(),
Expand Down
6 changes: 3 additions & 3 deletions packages/api/router/location/mutation.update.schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from 'zod'

import { Geometry, Prisma } from '@weareinreach/db'
import { Geometry, Prisma, PrismaEnums } from '@weareinreach/db'
import { allAttributes } from '@weareinreach/db/generated/allAttributes'
import { prefixedId } from '~api/schemas/idPrefix'

Expand All @@ -12,7 +12,7 @@ export const ZUpdateSchema = z
name: z.string(),
street1: z.string().nullish(),
street2: z.string().nullish(),
city: z.string().nullish(),
city: z.string(),
postCode: z.string().nullable(),
primary: z.boolean(),
mailOnly: z.boolean(),
Expand All @@ -30,7 +30,7 @@ export const ZUpdateSchema = z
countryId: prefixedId('country').nullable(),
govDistId: prefixedId('govDist').nullable(),
services: z.string().array(),
notVisitable: z.boolean(),
addressVisibility: z.nativeEnum(PrismaEnums.AddressVisibility),
})
.partial(),
})
Expand Down
12 changes: 10 additions & 2 deletions packages/api/router/location/query.forGoogleMaps.handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TRPCError } from '@trpc/server'
import { getBounds, getCenterOfBounds } from 'geolib'

import { prisma } from '@weareinreach/db'
import { prisma, PrismaEnums } from '@weareinreach/db'
import { handleError } from '~api/lib'
import { globalWhere } from '~api/selects/global'
import { type TRPCHandlerParams } from '~api/types/handler'
Expand Down Expand Up @@ -30,7 +30,15 @@ const forGoogleMaps = async ({ input, ctx }: TRPCHandlerParams<TForGoogleMapsSch
where: {
...(!canSeeAll && globalWhere.isPublic()),
id: { in: locationIds },
AND: [{ latitude: { not: 0 } }, { longitude: { not: 0 } }],
AND: [
{ latitude: { not: 0 } },
{ longitude: { not: 0 } },
{
addressVisibility: {
in: [PrismaEnums.AddressVisibility.FULL, PrismaEnums.AddressVisibility.PARTIAL],
},
},
],
},
select: {
id: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { handleError } from '~api/lib/errorHandler'
import { globalWhere } from '~api/selects/global'
import { type TRPCHandlerParams } from '~api/types/handler'

import { formatAddressVisiblity } from './lib.formatAddressVisibility'
import { type TForLocationCardSchema } from './query.forLocationCard.schema'

const forLocationCard = async ({ input, ctx }: TRPCHandlerParams<TForLocationCardSchema>) => {
Expand All @@ -25,7 +26,7 @@ const forLocationCard = async ({ input, ctx }: TRPCHandlerParams<TForLocationCar
postCode: true,
latitude: true,
longitude: true,
notVisitable: true,
addressVisibility: true,
published: true,
deleted: true,
country: { select: { cca2: true } },
Expand All @@ -49,6 +50,7 @@ const forLocationCard = async ({ input, ctx }: TRPCHandlerParams<TForLocationCar

const transformed = {
...result,
...formatAddressVisiblity(result),
country: result.country.cca2,
phones: result.phones.map(({ phone }) => ({ ...phone, country: phone.country.cca2 })),
attributes: result.attributes.map(({ attribute }) => attribute),
Expand Down
8 changes: 5 additions & 3 deletions packages/api/router/location/query.forLocationPage.handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { prisma } from '@weareinreach/db'
import { prisma, PrismaEnums } from '@weareinreach/db'
import { attributes } from '~api/schemas/selects/common'
import { globalSelect, globalWhere } from '~api/selects/global'
import { type TRPCHandlerParams } from '~api/types/handler'

import { formatAddressVisiblity } from './lib.formatAddressVisibility'
import { type TForLocationPageSchema } from './query.forLocationPage.schema'

const forLocationPage = async ({ input }: TRPCHandlerParams<TForLocationPageSchema>) => {
Expand All @@ -24,14 +25,15 @@ const forLocationPage = async ({ input }: TRPCHandlerParams<TForLocationPageSche
longitude: true,
latitude: true,
description: globalSelect.freeText(),
notVisitable: true,
addressVisibility: true,
reviews: {
where: { visible: true, deleted: false },
select: { id: true },
},
attributes,
},
})
return location

return { ...location, ...formatAddressVisiblity(location) }
}
export default forLocationPage
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const forLocationPageEdits = async ({ input }: TRPCHandlerParams<TForLocationPag
longitude: true,
latitude: true,
description: globalSelect.freeText(),
notVisitable: true,
addressVisibility: true,
attributes: {
select: {
attribute: {
Expand Down
5 changes: 4 additions & 1 deletion packages/api/router/location/query.forVisitCard.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { handleError } from '~api/lib/errorHandler'
import { globalWhere } from '~api/selects/global'
import { type TRPCHandlerParams } from '~api/types/handler'

import { formatAddressVisiblity } from './lib.formatAddressVisibility'
import { type TForVisitCardSchema } from './query.forVisitCard.schema'

const forVisitCard = async ({ input }: TRPCHandlerParams<TForVisitCardSchema>) => {
Expand All @@ -11,7 +12,7 @@ const forVisitCard = async ({ input }: TRPCHandlerParams<TForVisitCardSchema>) =
where: {
...globalWhere.isPublic(),
id: input,
notVisitable: { not: true },
addressVisibility: { in: ['FULL'] },
},
select: {
id: true,
Expand All @@ -28,6 +29,7 @@ const forVisitCard = async ({ input }: TRPCHandlerParams<TForVisitCardSchema>) =
},
latitude: true,
longitude: true,
addressVisibility: true,
},
})
if (!result) {
Expand All @@ -36,6 +38,7 @@ const forVisitCard = async ({ input }: TRPCHandlerParams<TForVisitCardSchema>) =
const { attributes, ...rest } = result
const transformed = {
...rest,
...formatAddressVisiblity(rest),
remote: attributes.find(({ attribute }) => attribute.tsKey === 'additional.offers-remote-services')
?.attribute,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/router/location/query.getAddress.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const getAddress = async ({ input }: TRPCHandlerParams<TGetAddressSchema>) => {
longitude: true,
mailOnly: true,
published: true,
notVisitable: true,
addressVisibility: true,
services: { select: { serviceId: true } },
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const forOrgPage = async ({ input }: TRPCHandlerParams<TForOrgPageSchema>) => {
postCode: true,
country: { select: { cca2: true } },
govDist: { select: { abbrev: true, tsKey: true, tsNs: true } },
notVisitable: true,
addressVisibility: true,
},
},
attributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const forOrgPageEdits = async ({ input }: TRPCHandlerParams<TForOrgPageEditsSche
postCode: true,
country: { select: { cca2: true } },
govDist: { select: { abbrev: true, tsKey: true, tsNs: true } },
notVisitable: true,
addressVisibility: true,
},
orderBy: [{ deleted: 'asc' }, { published: 'desc' }, { createdAt: 'desc' }],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/db/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ if (process.env.NODE_ENV !== 'production') {
}
export { prisma }
export type * from '@prisma/client'
export { Prisma } from '@prisma/client'
export { Prisma, $Enums as PrismaEnums } from '@prisma/client'

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit a3cd58d

Please sign in to comment.