Skip to content

Commit

Permalink
Merge branch 'dev' into l10n_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Feb 9, 2024
2 parents a9e0f4b + ec03496 commit e7b8c03
Show file tree
Hide file tree
Showing 17 changed files with 411 additions and 49 deletions.
10 changes: 8 additions & 2 deletions packages/api/router/location/query.getById.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ export const getById = async ({ ctx, input }: TRPCHandlerParams<TGetByIdSchema>)
...select.attributes(),
},
emails: { where: { email: globalWhere.isPublic() }, ...select.orgEmail() },
websites: { where: globalWhere.isPublic(), ...globalSelect.orgWebsite() },
websites: {
where: { website: globalWhere.isPublic() },
select: { website: globalSelect.orgWebsite() },
},
phones: { where: { phone: globalWhere.isPublic() }, ...select.orgPhone() },
photos: { where: globalWhere.isPublic(), ...globalSelect.orgPhoto() },
hours: globalSelect.hours(),
reviews: { where: { visible: true, deleted: false }, select: { id: true } },
services: { where: { service: globalWhere.isPublic() }, ...select.service(ctx) },
serviceAreas: globalSelect.serviceArea(),
socialMedia: { where: globalWhere.isPublic(), ...globalSelect.socialMedia() },
socialMedia: {
where: { socialMedia: globalWhere.isPublic() },
select: { socialMedia: globalSelect.socialMedia() },
},
description: globalSelect.freeText(),
name: true,
street1: true,
Expand Down
10 changes: 8 additions & 2 deletions packages/api/router/location/query.getByOrgId.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@ export const getByOrgId = async ({ ctx, input }: TRPCHandlerParams<TGetByOrgIdSc
...select.attributes(),
},
emails: { where: { email: globalWhere.isPublic() }, ...select.orgEmail() },
websites: { where: globalWhere.isPublic(), ...globalSelect.orgWebsite() },
websites: {
where: { website: globalWhere.isPublic() },
select: { website: globalSelect.orgWebsite() },
},
phones: { where: { phone: globalWhere.isPublic() }, ...select.orgPhone() },
photos: { where: globalWhere.isPublic(), ...globalSelect.orgPhoto() },
hours: globalSelect.hours(),
reviews: { where: { visible: true, deleted: false }, select: { id: true } },
services: { where: { service: globalWhere.isPublic() }, ...select.service(ctx) },
serviceAreas: globalSelect.serviceArea(),
socialMedia: { where: globalWhere.isPublic(), ...globalSelect.socialMedia() },
socialMedia: {
where: { socialMedia: globalWhere.isPublic() },
select: { socialMedia: globalSelect.socialMedia() },
},
description: globalSelect.freeText(),
name: true,
street1: true,
Expand Down
6 changes: 3 additions & 3 deletions packages/api/router/misc/query.hasContactInfo.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const whereId = (
const phoneEmailLoc = {
locations: { some: { location: { organization: { id: input, ...isPublic } } } },
}
const smWebLoc = { orgLocation: { organization: { id: input, ...isPublic } } }
const smWebLoc = { locations: { some: { location: { organization: { id: input, ...isPublic } } } } }

return isSingleLoc
? {
Expand Down Expand Up @@ -74,8 +74,8 @@ const whereId = (
locations: { some: { location: { id: input, ...isPublic } } },
...isPublic,
},
socialMedia: { orgLocation: { id: input, ...isPublic }, ...isPublic },
website: { orgLocation: { id: input, ...isPublic }, ...isPublic },
socialMedia: { locations: { every: { location: { id: input, ...isPublic }, ...isPublic } } },
website: { locations: { every: { location: { id: input, ...isPublic }, ...isPublic } } },
}
}
case isIdFor('orgService', input): {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const update = async ({ ctx, input }: TRPCHandlerParams<TUpdateSchema, 'p
published: true,
serviceId: true,
organizationId: true,
orgLocationId: true,
locations: { select: { orgLocationId: true } },
orgLocationOnly: true,
service: {
select: { id: true, name: true, logoIcon: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const whereId = (input: TForContactInfoSchema, isSingleLoc?: boolean): Prisma.Or
? {
OR: [
{ organization: { id: input.parentId, ...isPublic } },
{ orgLocation: { organization: { id: input.parentId, ...isPublic } } },
{ locations: { every: { location: { organization: { id: input.parentId, ...isPublic } } } } },
],
}
: { organization: { id: input.parentId, ...isPublic } }
}
case isIdFor('orgLocation', input.parentId): {
return { orgLocation: { id: input.parentId, ...isPublic } }
return { locations: { some: { location: { id: input.parentId, ...isPublic } } } }
}
default: {
return {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const whereId = (input: TForContactInfoEditsSchema): Prisma.OrgSocialMediaWhereI
return { organization: { id: input.parentId } }
}
case isIdFor('orgLocation', input.parentId): {
return { orgLocation: { id: input.parentId } }
return { locations: { some: { location: { id: input.parentId } } } }
}
default: {
return {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type TRPCHandlerParams } from '~api/types/handler'

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

export const forEditDrawer = async ({ ctx, input }: TRPCHandlerParams<TForEditDrawerSchema>) => {
export const forEditDrawer = async ({ input }: TRPCHandlerParams<TForEditDrawerSchema>) => {
try {
const result = await prisma.orgSocialMedia.findUnique({
where: input,
Expand All @@ -16,7 +16,7 @@ export const forEditDrawer = async ({ ctx, input }: TRPCHandlerParams<TForEditDr
published: true,
serviceId: true,
organizationId: true,
orgLocationId: true,
locations: { select: { orgLocationId: true } },
orgLocationOnly: true,
service: {
select: { id: true, name: true, logoIcon: true },
Expand Down
2 changes: 1 addition & 1 deletion packages/api/router/orgWebsite/mutation.create.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const ZCreateSchema = z
orgLocationOnly,
description,
organization: connectOneId(organizationId),
orgLocation: connectOneId(orgLocationId),
locations: orgLocationId ? { create: { orgLocationId } } : undefined,
})
})
export type TCreateSchema = z.infer<typeof ZCreateSchema>
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const whereId = (input: TForContactInfoSchema, isSingleLoc?: boolean): Prisma.Or
? {
OR: [
{ organization: { id: input.parentId, ...isPublic } },
{ orgLocation: { organization: { id: input.parentId, ...isPublic } } },
{ locations: { every: { location: { organization: { id: input.parentId, ...isPublic } } } } },
],
}
: { organization: { id: input.parentId, ...isPublic } }
}
case isIdFor('orgLocation', input.parentId): {
return { orgLocation: { id: input.parentId, ...isPublic } }
return { locations: { some: { location: { id: input.parentId, ...isPublic } } } }
}

default: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ const whereId = (input: TForContactInfoEditSchema): Prisma.OrgWebsiteWhereInput
return { organization: { id: input.parentId } }
}
case isIdFor('orgLocation', input.parentId): {
return { orgLocation: { id: input.parentId } }
return { locations: { some: { location: { id: input.parentId } } } }
}

default: {
return {}
}
}
}
export const forContactInfoEdit = async ({ ctx, input }: TRPCHandlerParams<TForContactInfoEditSchema>) => {
export const forContactInfoEdit = async ({ input }: TRPCHandlerParams<TForContactInfoEditSchema>) => {
try {
const result = await prisma.orgWebsite.findMany({
where: {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/schemas/create/orgSocialMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const CreateNestedOrgSocialMediaSchema = z
.transform((data) =>
Prisma.validator<
Prisma.Enumerable<
Prisma.OrgSocialMediaCreateManyOrganizationInput | Prisma.OrgSocialMediaCreateManyOrgLocationInput
Prisma.OrgSocialMediaCreateManyOrganizationInput | Prisma.OrgSocialMedia$locationsArgs
>
>()(data)
)
Expand Down
6 changes: 2 additions & 4 deletions packages/api/schemas/create/orgWebsite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const CreateOrgWebsiteSchema = z
orgLocationOnly,
description,
organization: connectOneId(organizationId),
orgLocation: connectOneId(orgLocationId),
locations: orgLocationId ? { create: { orgLocationId } } : undefined,
})
})

Expand All @@ -43,9 +43,7 @@ export const CreateNestedOrgWebsiteSchema = z
.array()
.transform((data) =>
Prisma.validator<
Prisma.Enumerable<
Prisma.OrgWebsiteCreateManyOrganizationInput | Prisma.OrgWebsiteCreateManyOrgLocationInput
>
Prisma.Enumerable<Prisma.OrgWebsiteCreateManyOrganizationInput | Prisma.OrgWebsite$locationsArgs>
>()(data)
)

Expand Down
7 changes: 4 additions & 3 deletions packages/api/schemas/selects/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const orgWebsiteInclude = {
languages: { select: { language: languageSelect } },
url: true,
isPrimary: true,
orgLocationId: true,
locations: { select: { orgLocationId: true } },
orgLocationOnly: true,
},
} satisfies Prisma.Organization$websitesArgs
Expand Down Expand Up @@ -241,14 +241,15 @@ export const orgLocationInclude = (ctx: Omit<Context, 'prisma'>) =>
country: countryWithoutGeo,
attributes: attributeInclude,
emails: orgEmailInclude,
websites: orgWebsiteInclude,
// websites: orgWebsiteInclude,
websites: { select: { website: orgWebsiteInclude } },
phones: phoneSelectPublic,
photos: photoSelect,
hours: hoursSelect,
reviews: reviewIds,
services: orgLocationServiceInclude(ctx),
serviceAreas: serviceAreaInclude,
socialMedia: orgSocialMediaInclude,
socialMedia: { select: { socialMedia: orgSocialMediaInclude } },
description: freeText,
name: true,
street1: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/selects/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const globalSelect = {
languages: { select: { language: this.language() } },
url: true,
isPrimary: true,
orgLocationId: true,
locations: { select: { orgLocationId: true } },
orgLocationOnly: true,
},
} satisfies Prisma.OrgWebsiteDefaultArgs
Expand Down
23 changes: 16 additions & 7 deletions packages/db/lib/idGen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { type Prisma } from '@prisma/client'
import { Ulid } from 'id128'

/**
* Tables that are not in the idPrefix or excludedTables
*
* If the type resolves to `never`, then everything is good. Otherwise, it will resolve to the missing table
* name(s)
*
* This is for utility purposes.
*/
type _TablesNotInIdPrefix = Exclude<
Prisma.ModelName,
Capitalize<keyof typeof idPrefix> | (typeof excludedTables)[number]
>

export const idPrefix = {
account: 'acct',
attribute: 'attr',
Expand Down Expand Up @@ -114,23 +127,16 @@ const excludedTables = [
'OrgServiceTag',
'ServiceAreaCountry',
'ServiceAreaDist',
'OrganizationAttribute',
'LocationAttribute',
'ServiceAttribute',
'ServiceAccessAttribute',
'AttributeToCategory',
'ServiceCategoryDefaultAttribute',
'ServiceTagDefaultAttribute',
'orgsearchresults',
'attributeandcategory',
'servicetagcategory',
'VerificationToken',
'TranslationNamespace',
'TranslationKey',
'OutsideAPIService',
'OrganizationPhone',
'OrganizationEmail',
'UserAttribute',
'AttributeNesting',
'ServiceTagNesting',
'ServiceTagCountry',
Expand All @@ -139,4 +145,7 @@ const excludedTables = [
'user_access_token',
'AuditTrail',
'ServiceTagToCategory',
'OrgLocationSocialMedia',
'OrgLocationWebsite',
'OrgServiceWebsite',
] as const // satisfies Prisma.ModelName[]
Loading

0 comments on commit e7b8c03

Please sign in to comment.