import { schema } from 'nexus' // uncomment when error is solved // import * as PropertyController from '../../controllers/property' export const Property = schema.objectType({ name: 'Property', definition(t) { t.model.id() t.model.createdAt() t.model.updatedAt() t.model.accessKey() t.model.intercomCode() t.model.parking() t.model.locker() t.model.remote() t.model.hasDog() t.model.rentAmount() t.model.rentStart() t.model.rentEnd() t.model.buzzCode() t.model.garageRemote() t.model.floor() t.model.squareFeet() t.model.squareFeetBalcony() t.model.type() t.model.percentageSquareFootage() t.model.residentCanEditRoomsModels() t.model.rooms() t.model.wifiPassword() t.model.condoManagerNoCompteReel() t.model.copropertyDueAmount() t.model.hasAlarmSystem() t.model.currentlyPaysCondoFeesViaEFT() t.model.condoFeeEFTPaymentsPausedDueToPriceChange() t.model.usingPaymentAccountId() t.model.monthlyCondoFeeAmount() t.model.note() t.model.proportionateShare() t.model.referencePropertyId() t.model.address() t.model.building() t.model.lease() t.model.plan() t.model.referenceProperty() t.model.accessKeys() t.model.accountStatements() t.model.cars() t.model.meetingParticipantsIsRepresentedByPropertyToProperty() t.model.meetingParticipantsPropertyToProperty() t.model.meetingParticipantUnit() t.model.receivedOffenses() t.model.proxies() t.model.remotes() t.model.serviceRequests() t.model.tasks() t.model.users() t.model.annexes() t.model.chosenModels() t.model.issues() t.model.lockers() t.model.meetingParticipantsProperties() t.model.notes() t.model.owners() t.model.parkings() t.model.EFTPayments() t.model.EFTRefunds() t.model.previousOwners() t.model.previousUsers() t.model.segments() t.model.tenants() }, }) export const Proxy = schema.objectType({ name: 'Proxy', definition(t) { t.model.id() t.model.createdAt() t.model.updatedAt() t.model.representativeName() t.model.pdfId() t.model.propertyId() t.model.signeeId() t.model.pdf() t.model.property() t.model.signee() t.model.meetingParticipants() t.model.posts() }, }) export const PropertyQueries = schema.extendType({ type: 'Query', definition(t) { t.crud.property() t.crud.properties({ filtering: true, ordering: true }) }, }) export const PropertyMutation = schema.extendType({ type: 'Mutation', definition: (t) => { t.crud.deleteOneProperty({ alias: 'deleteProperty' }) t.crud.updateOneProperty({ alias: 'updateProperty' }) t.crud.createOneProperty({ alias: 'createProperty' }) t.field('createProperty', { type: 'Property', args: { data: schema.arg({ type: 'PropertyCreateInput' }), }, resolve: async (parent, { data }, ctx: NexusContext) => { // Make sure we don't create a unit that already exists const propertiesOfBuilding = await ctx.prisma.property.findMany({ where: { building: { id: data.building.connect.id, }, address: { apartmentNumber: data.address.create.apartmentNumber, }, }, }) if (propertiesOfBuilding.length) { throw new Error( `There's already a unit created for #${data.address.create.apartmentNumber}` ) } if (!data.building) { throw new Error('Property needs to be attached to a building') } // Add the building address to the unit if not existing if (data?.address?.create && data.building?.connect?.id) { const buildingAddress = await ctx.prisma.building .findOne({ where: { id: data.building.connect.id } }) .address({ select: { address1: true, zip: true, city: true, state: true, country: true, countryCode: true, provinceCode: true, }, }) data = { ...data, address: { ...data.address, create: { ...buildingAddress, ...data.address.create, }, }, } } return ctx.prisma.property.create({ data }) }, }) // t.field('updateProperty', { // ...t.prismaType.updateProperty, // resolve: async (parent, { where, data }) => { // return PropertyController.property.update({ where, data }) // } // }) }, })