Skip to content

Commit

Permalink
fix: #7266 fix all entities (#7409)
Browse files Browse the repository at this point in the history
* fix developername not showing

* filter out non-top-level entities from typelist

* appointment update & fixing stuff up

* gql fix appointment updating

* fix applicant updating

* fix up filters

* property image list & update

* property image creation works

* clean up

* update snaps
  • Loading branch information
joshbalfour authored Aug 2, 2022
1 parent bf580a4 commit 804898a
Show file tree
Hide file tree
Showing 20 changed files with 704 additions and 185 deletions.
3 changes: 2 additions & 1 deletion packages/app-builder-backend/src/ddb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const ensureTables = async () => {
export type DDBApp = Omit<App, 'name'>

const ddbItemToApp = (item: { [key: string]: AttributeValue }): DDBApp => {
const { id, createdAt, updatedAt, pages, subdomain, navConfig, customEntities, clientId } = item
const { id, createdAt, updatedAt, pages, subdomain, navConfig, customEntities, clientId, developerName } = item

return {
id: id?.S as string,
Expand All @@ -77,6 +77,7 @@ const ddbItemToApp = (item: { [key: string]: AttributeValue }): DDBApp => {
pages: (pages?.S && (JSON.parse(pages.S as string) as Array<Page>)) || [],
customEntities: (customEntities?.S && (JSON.parse(customEntities.S as string) as Array<CustomEntity>)) || [],
navConfig: (navConfig?.S && (JSON.parse(navConfig.S as string) as Array<NavConfig>)) || [],
developerName: developerName?.S as string | undefined,
}
}

Expand Down
21 changes: 11 additions & 10 deletions packages/app-builder-backend/src/entities/appointments.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { gql } from 'apollo-server-core'
import { Field, GraphQLISODateTime, ID, InputType, ObjectType } from 'type-graphql'
import { Contact } from './contact'
import { Negotiator, NegotiatorFragment } from './negotiator'
import { Office, OfficeFragment } from './office'
import { Negotiator } from './negotiator'
import { Office } from './office'
import { Property, PropertyFragment } from './property'

@ObjectType({ description: '@labelKeys(value)' })
@ObjectType({ description: '@labelKeys(value) @notTopLevel()' })
export class AppointmentType {
@Field(() => ID)
id: string
Expand Down Expand Up @@ -42,8 +42,8 @@ export class Appointment {
@Field(() => Property, { nullable: true })
property?: Property

@Field({ nullable: true })
organiserId?: string
@Field(() => Negotiator, { nullable: true })
organiser?: Negotiator

@Field(() => [Negotiator])
negotiators?: Negotiator[]
Expand Down Expand Up @@ -88,16 +88,14 @@ export class AppointmentInput {
@Field(() => [String], { description: '@idOf(Office)' })
officeIds: string[]

@Field({ description: '@idOf(Contact)' })
attendeeId: string
@Field({ description: '@idOf(Contact)', nullable: true })
attendeeId?: string

metadata?: any
}

export const AppointmentFragment = gql`
${PropertyFragment}
${NegotiatorFragment}
${OfficeFragment}
fragment AppointmentFragment on AppointmentModel {
id
created
Expand Down Expand Up @@ -131,7 +129,7 @@ export const AppointmentFragment = gql`
negotiatorConfirmed
attendeeConfirmed
propertyConfirmed
_eTag
_embedded {
offices {
...OfficeFragment
Expand All @@ -142,6 +140,9 @@ export const AppointmentFragment = gql`
property {
...PropertyFragment
}
organiser {
...NegotiatorFragment
}
}
}
`
2 changes: 1 addition & 1 deletion packages/app-builder-backend/src/entities/company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { gql } from 'apollo-server-core'
import { Field, GraphQLISODateTime, ID, InputType, ObjectType } from 'type-graphql'
import { ContactAddressType } from './contact'

@ObjectType({ description: '@labelKeys(value)' })
@ObjectType({ description: '@labelKeys(value) @notTopLevel()' })
export class CompanyType {
@Field(() => ID)
id: string
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-backend/src/entities/department.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const DepartmentFragment = gql`
}
`

@ObjectType({ description: '@labelKeys(name)' })
@ObjectType({ description: '@labelKeys(name) @notTopLevel()' })
export class Department {
@Field(() => ID)
id: string
Expand Down
31 changes: 18 additions & 13 deletions packages/app-builder-backend/src/entities/property-image.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { gql } from 'apollo-server-core'
import { Field, GraphQLISODateTime, InputType, ObjectType } from 'type-graphql'
import { Field, GraphQLISODateTime, InputType, ObjectType, registerEnumType } from 'type-graphql'

export const PropertyImageFragment = gql`
fragment PropertyImageFragment on PropertyImageModel {
Expand All @@ -13,6 +13,17 @@ export const PropertyImageFragment = gql`
}
`

export enum PropertyImageType {
photograph = 'photograph',
floorPlan = 'floorPlan',
epc = 'epc',
map = 'map',
}
registerEnumType(PropertyImageType, {
name: 'PropertyImageType',
description: 'The type of image',
})

@ObjectType()
export class PropertyImage {
@Field()
Expand All @@ -24,14 +35,11 @@ export class PropertyImage {
@Field(() => GraphQLISODateTime)
modified: Date

@Field()
@Field({ description: '@urlType("image")' })
url: string

@Field()
type: string

@Field({ nullable: true })
order: number
@Field(() => PropertyImageType)
type: PropertyImageType

@Field()
caption: string
Expand All @@ -42,15 +50,12 @@ export class PropertyImageInput {
@Field({ description: '@customInput(image-upload)' })
data: string

@Field({ nullable: true })
@Field()
caption: string

@Field({ description: '@idOf(Property)' })
propertyId: string

@Field({ nullable: true })
type: string

@Field({ nullable: true })
order: number
@Field(() => PropertyImageType, { nullable: true })
type: PropertyImageType
}
1 change: 1 addition & 0 deletions packages/app-builder-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const start = async () => {

app.disable('x-powered-by')
app.use(cors())
app.use(express.json({ limit: '50mb' }))

const httpServer = http.createServer(app)
const server = new ExtendedApolloServerExpress({
Expand Down
120 changes: 56 additions & 64 deletions packages/app-builder-backend/src/resolvers/app-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ enum Access {
}

const getObjectScopes = (objectName: string, access: Access) => {
return `agencyCloud/${Pluralize.plural(objectName.toLowerCase())}.${access}`
let on = objectName
if (on.toLowerCase() === 'propertyimage') {
on = 'image'
}
return `agencyCloud/${Pluralize.plural(on)}.${access}`
}

// compare array of strings
Expand Down Expand Up @@ -114,74 +118,61 @@ const ensureScopes = async (app: DDBApp, accessToken: string) => {
const name = node.type.resolvedName
const props = node.props
const objectName = node.props?.typeName as string | undefined

if (!objectName || !props) {
return null
}
if (name === 'Form') {
const childNodes = node.nodes.map((nodeId) => nodes.find(({ nodeId: id }) => id === nodeId)).filter(notEmpty)

const fieldNames = childNodes
.map((node) => node.props.name)
.filter(notEmpty)
.filter(isString)

const subtypes = fieldNames
.filter((name) => name.endsWith('Id') || name.endsWith('Ids'))
.map((name) => name.replace('Ids', '').replace('Id', ''))
.map((name) => {
if (name.endsWith('y')) {
return name.replace(/y$/, 'ies')
}
return name
})
.map((name) => {
if (name.toLowerCase().includes('attendee')) {
return 'contact'
}
return name
})
.filter((fieldName) => acEntities.find((entityName) => entityName.includes(fieldName)))

return [
{
objectName,
access: [Access.read, Access.write],
},
...subtypes.map((subtype) => ({
objectName: subtype,
access: [Access.read],
})),
]
}
if (name === 'Table') {
if (isArray(props.includedFields)) {
const subtypes = props.includedFields.filter((fieldName) =>
acEntities.find((entityName) => entityName.includes(fieldName)),
)

return [
{
objectName,
access: props.showControls ? [Access.read, Access.write] : [Access.write],
},
...subtypes.map((subtype) => ({
objectName: subtype,
access: [Access.read],
})),
]
}
return [
{
objectName,
access: props.showControls ? [Access.read, Access.write] : [Access.write],
},
]

const fieldNames =
name === 'Form'
? node.nodes
.map((nodeId) => nodes.find(({ nodeId: id }) => id === nodeId))
.filter(notEmpty)
.map((node) => node.props.name)
.filter(notEmpty)
.filter(isString)
: isArray(props.includedFields)
? props.includedFields
: []

const subtypes = fieldNames
.map((name) => name.replace('Ids', '').replace('Id', ''))
.map((name) => {
if (name.endsWith('y')) {
return name.replace(/y$/, 'ies')
}
return name
})
.map((name) => {
if (name.toLowerCase().includes('attendee')) {
return 'contact'
}
return name
})
.filter((fieldName) => acEntities.find((entityName) => entityName.includes(fieldName)))

const scopes = [
{
objectName,
access: props.showControls || name === 'Form' ? [Access.read, Access.write] : [Access.read],
},
...subtypes.map((subtype) => ({
objectName: subtype,
access: [Access.read],
})),
]

if (objectName.toLowerCase() === 'propertyimage') {
scopes.push({
objectName: 'properties',
access: [Access.read, Access.write],
})
}
return null

return scopes
})
.flat()
.filter(notEmpty)

const scopes = requiredAccess
.map(({ objectName, access }) => {
return access.map((access) => getObjectScopes(objectName, access))
Expand All @@ -191,6 +182,7 @@ const ensureScopes = async (app: DDBApp, accessToken: string) => {
.filter((scope) => validScopes.includes(scope))
// unique scopes
const uniqueScopes = [...new Set(scopes)]

return updateMarketplaceAppScopes(app.id, uniqueScopes, accessToken)
}

Expand Down Expand Up @@ -274,14 +266,14 @@ export class AppResolver {
await updateApp({
...app,
clientId: externalId as string,
developerName: developer as string,
developerName: developer,
})

return {
...app,
name: name as string,
clientId: externalId as string,
developerName: developer as string,
developerName: developer,
}
}

Expand Down
Loading

0 comments on commit 804898a

Please sign in to comment.