Skip to content

Commit

Permalink
update api route/mock data
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Jan 9, 2024
1 parent 268f592 commit 9359e01
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
36 changes: 33 additions & 3 deletions packages/api/router/orgPhone/query.forEditDrawer.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@ import { type TRPCHandlerParams } from '~api/types/handler'

import { type TForEditDrawerSchema } from './query.forEditDrawer.schema'

const getOrgId = async (phoneId: string) => {
const result = await prisma.orgPhone.findUniqueOrThrow({
where: { id: phoneId },
select: {
organization: { select: { organizationId: true } },
locations: { select: { location: { select: { orgId: true } } } },
services: { select: { service: { select: { organizationId: true } } } },
},
})

switch (true) {
case !!result.organization?.organizationId: {
return result.organization.organizationId
}
case result.locations.length !== 0 &&
result.locations.filter((loc) => !!loc.location.orgId).length !== 0: {
const filtered = result.locations.filter((loc) => !!loc.location.orgId)
return filtered[0]!.location.orgId
}
case result.services.length !== 0 &&
result.services.filter((serv) => !!serv.service.organizationId).length !== 0: {
const filtered = result.services.filter((serv) => !!serv.service.organizationId)
return filtered[0]!.service.organizationId!
}
default: {
throw new Error('Unable to get organizationId')
}
}
}

export const forEditDrawer = async ({ input }: TRPCHandlerParams<TForEditDrawerSchema>) => {
try {
const result = await prisma.orgPhone.findUniqueOrThrow({
Expand All @@ -22,11 +52,11 @@ export const forEditDrawer = async ({ input }: TRPCHandlerParams<TForEditDrawerS
serviceOnly: true,
},
})
const orgId = await getOrgId(input.id)
const reformatted = {
...result,
description: result.description
? { id: result.description?.id, key: result.description?.key, text: result.description?.tsKey?.text }
: null,
orgId,
description: result.description ? result.description?.tsKey?.text : null,
}
return reformatted
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/mockData/json/orgPhone.forEditDrawer.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"id":"ophn_01GVH3VEVCFKT3NWQ79STYVDKR","number":"2027457000","ext":null,"primary":true,"published":true,"deleted":false,"countryId":"ctry_01GW2HHDK9M26M80SG63T21SVH","phoneTypeId":null,"description":{"id":"ftxt_01E4ENGMG2G5QN0K9DATJVDJS2","key":"orgn_01GVH3V408N0YS7CDYAH3F2BMH.ophn_01GVH3VEVCFKT3NWQ79STYVDKR.description","text":"Medical Care/ Appointments"},"locationOnly":false,"serviceOnly":true}
{"countryId":"ctry_01GW2HHDK9M26M80SG63T21SVH","deleted":false,"description":{"id":"ftxt_01E4ENGMG2G5QN0K9DATJVDJS2","key":"orgn_01GVH3V408N0YS7CDYAH3F2BMH.ophn_01GVH3VEVCFKT3NWQ79STYVDKR.description","text":"Medical Care/ Appointments"},"ext":null,"id":"ophn_01GVH3VEVCFKT3NWQ79STYVDKR","locationOnly":false,"number":"2027457000","orgId":"orgn_01GVH3V408N0YS7CDYAH3F2BMH","phoneTypeId":null,"primary":true,"published":true,"serviceOnly":true}

0 comments on commit 9359e01

Please sign in to comment.