-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!--- Please provide a general summary of your changes in the title above --> # Pull Request type <!-- Please try to limit your pull request to one type; submit multiple pull requests if needed. --> Please check the type of change your PR introduces: - [x] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no API changes) - [ ] Build-related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> Issue Number: N/A ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - - - ## Does this introduce a breaking change? - [ ] Yes - [ ] No <!-- If this does introduce a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR, such as screenshots of how the component looks before and after the change. --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a new "Edit Mode" feature to the location queries and Google Maps integration, enhancing user control over viewing and editing location-related data. - Introduced a new upsert functionality for organizational phone data management in the API, allowing for more efficient data updates. - **Bug Fixes** - Improved flow control in permission middleware functions to ensure proper access control and execution logic. - **Documentation** - Updated API documentation to reflect new features and modifications in data handling and permission checks. - **Refactor** - Enhanced error handling across various API endpoints to provide more robust and clear error feedback. - **Style** - Adjusted UI components to accommodate new features and ensure a consistent user experience. - **Tests** - Implemented additional tests to cover new functionalities and changes in API endpoints, ensuring reliability and performance. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
20 changed files
with
485 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 52 additions & 41 deletions
93
packages/api/router/location/query.forLocationCard.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,67 @@ | ||
import { prisma } from '@weareinreach/db' | ||
import { handleError } from '~api/lib/errorHandler' | ||
import { globalWhere } from '~api/selects/global' | ||
import { type TRPCHandlerParams } from '~api/types/handler' | ||
|
||
import { type TForLocationCardSchema } from './query.forLocationCard.schema' | ||
|
||
const forLocationCard = async ({ input }: TRPCHandlerParams<TForLocationCardSchema>) => { | ||
const result = await prisma.orgLocation.findUniqueOrThrow({ | ||
where: { | ||
id: input, | ||
...globalWhere.isPublic(), | ||
}, | ||
select: { | ||
id: true, | ||
name: true, | ||
street1: true, | ||
street2: true, | ||
city: true, | ||
postCode: true, | ||
latitude: true, | ||
longitude: true, | ||
notVisitable: true, | ||
country: { select: { cca2: true } }, | ||
govDist: { select: { abbrev: true, tsKey: true, tsNs: true } }, | ||
phones: { | ||
where: { phone: globalWhere.isPublic() }, | ||
select: { phone: { select: { primary: true, number: true, country: { select: { cca2: true } } } } }, | ||
const forLocationCard = async ({ input, ctx }: TRPCHandlerParams<TForLocationCardSchema>) => { | ||
try { | ||
const { id, isEditMode } = input | ||
|
||
const canSeeAll = isEditMode && !!ctx.session?.user?.permissions | ||
|
||
const result = await prisma.orgLocation.findUniqueOrThrow({ | ||
where: { | ||
id, | ||
...(!canSeeAll && globalWhere.isPublic()), | ||
}, | ||
attributes: { select: { attribute: { select: { tsNs: true, tsKey: true, icon: true } } } }, | ||
services: { | ||
select: { | ||
service: { | ||
select: { | ||
services: { select: { tag: { select: { primaryCategory: { select: { tsKey: true } } } } } }, | ||
select: { | ||
id: true, | ||
name: true, | ||
street1: true, | ||
street2: true, | ||
city: true, | ||
postCode: true, | ||
latitude: true, | ||
longitude: true, | ||
notVisitable: true, | ||
country: { select: { cca2: true } }, | ||
govDist: { select: { abbrev: true, tsKey: true, tsNs: true } }, | ||
phones: { | ||
...(!canSeeAll && { where: { phone: globalWhere.isPublic() } }), | ||
select: { phone: { select: { primary: true, number: true, country: { select: { cca2: true } } } } }, | ||
}, | ||
attributes: { select: { attribute: { select: { tsNs: true, tsKey: true, icon: true } } } }, | ||
services: { | ||
select: { | ||
service: { | ||
select: { | ||
services: { select: { tag: { select: { primaryCategory: { select: { tsKey: true } } } } } }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
}) | ||
|
||
const transformed = { | ||
...result, | ||
country: result.country.cca2, | ||
phones: result.phones.map(({ phone }) => ({ ...phone, country: phone.country.cca2 })), | ||
attributes: result.attributes.map(({ attribute }) => attribute), | ||
services: [ | ||
...new Set( | ||
result.services.flatMap(({ service }) => service.services.map(({ tag }) => tag.primaryCategory.tsKey)) | ||
), | ||
], | ||
} | ||
const transformed = { | ||
...result, | ||
country: result.country.cca2, | ||
phones: result.phones.map(({ phone }) => ({ ...phone, country: phone.country.cca2 })), | ||
attributes: result.attributes.map(({ attribute }) => attribute), | ||
services: [ | ||
...new Set( | ||
result.services.flatMap(({ service }) => | ||
service.services.map(({ tag }) => tag.primaryCategory.tsKey) | ||
) | ||
), | ||
], | ||
} | ||
|
||
return transformed | ||
return transformed | ||
} catch (err) { | ||
return handleError(err) | ||
} | ||
} | ||
export default forLocationCard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { type z } from 'zod' | ||
import { z } from 'zod' | ||
|
||
import { prefixedId } from '~api/schemas/idPrefix' | ||
|
||
export const ZForLocationCardSchema = prefixedId('orgLocation') | ||
export const ZForLocationCardSchema = z.object({ | ||
id: prefixedId('orgLocation'), | ||
isEditMode: z.boolean().optional().default(false), | ||
}) | ||
export type TForLocationCardSchema = z.infer<typeof ZForLocationCardSchema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.