|
| 1 | +import domainGroup from "../../domain_group.app.mjs"; |
| 2 | +import { COMMERCIAL_TYPES } from "../../common/property-types.mjs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "domain_group-create-commercial-listing", |
| 6 | + name: "Create Commercial Listing", |
| 7 | + description: "Creates a new commercial listing. [See the documentation](https://developer.domain.com.au/docs/latest/apis/pkg_listing_management/references/listings_upsertcommerciallisting/).", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + props: { |
| 11 | + domainGroup, |
| 12 | + agencyId: { |
| 13 | + propDefinition: [ |
| 14 | + domainGroup, |
| 15 | + "agencyId", |
| 16 | + ], |
| 17 | + }, |
| 18 | + providerAdId: { |
| 19 | + propDefinition: [ |
| 20 | + domainGroup, |
| 21 | + "providerAdId", |
| 22 | + ], |
| 23 | + }, |
| 24 | + propertyType: { |
| 25 | + propDefinition: [ |
| 26 | + domainGroup, |
| 27 | + "propertyType", |
| 28 | + ], |
| 29 | + options: COMMERCIAL_TYPES, |
| 30 | + }, |
| 31 | + listingAction: { |
| 32 | + propDefinition: [ |
| 33 | + domainGroup, |
| 34 | + "listingAction", |
| 35 | + ], |
| 36 | + reloadProps: true, |
| 37 | + }, |
| 38 | + underOfferOrContract: { |
| 39 | + propDefinition: [ |
| 40 | + domainGroup, |
| 41 | + "underOfferOrContract", |
| 42 | + ], |
| 43 | + }, |
| 44 | + nabers: { |
| 45 | + propDefinition: [ |
| 46 | + domainGroup, |
| 47 | + "nabers", |
| 48 | + ], |
| 49 | + }, |
| 50 | + description: { |
| 51 | + propDefinition: [ |
| 52 | + domainGroup, |
| 53 | + "description", |
| 54 | + ], |
| 55 | + }, |
| 56 | + features: { |
| 57 | + propDefinition: [ |
| 58 | + domainGroup, |
| 59 | + "features", |
| 60 | + ], |
| 61 | + }, |
| 62 | + streetNumber: { |
| 63 | + propDefinition: [ |
| 64 | + domainGroup, |
| 65 | + "streetNumber", |
| 66 | + ], |
| 67 | + }, |
| 68 | + unitNumber: { |
| 69 | + propDefinition: [ |
| 70 | + domainGroup, |
| 71 | + "unitNumber", |
| 72 | + ], |
| 73 | + }, |
| 74 | + street: { |
| 75 | + propDefinition: [ |
| 76 | + domainGroup, |
| 77 | + "street", |
| 78 | + ], |
| 79 | + }, |
| 80 | + state: { |
| 81 | + propDefinition: [ |
| 82 | + domainGroup, |
| 83 | + "state", |
| 84 | + ], |
| 85 | + }, |
| 86 | + suburb: { |
| 87 | + propDefinition: [ |
| 88 | + domainGroup, |
| 89 | + "suburb", |
| 90 | + ], |
| 91 | + }, |
| 92 | + postcode: { |
| 93 | + propDefinition: [ |
| 94 | + domainGroup, |
| 95 | + "postcode", |
| 96 | + ], |
| 97 | + }, |
| 98 | + areaValue: { |
| 99 | + type: "string", |
| 100 | + label: "Area Value", |
| 101 | + description: "The size of the area in the commercial listing", |
| 102 | + }, |
| 103 | + areaUnit: { |
| 104 | + type: "string", |
| 105 | + label: "Area Unit", |
| 106 | + description: "The unit of measure of the area value", |
| 107 | + options: [ |
| 108 | + "squareMetres", |
| 109 | + "acres", |
| 110 | + "hectares", |
| 111 | + "squareFeet", |
| 112 | + "squareYards", |
| 113 | + "squares", |
| 114 | + ], |
| 115 | + }, |
| 116 | + receiveEmailsToDefaultAddress: { |
| 117 | + propDefinition: [ |
| 118 | + domainGroup, |
| 119 | + "receiveEmailsToDefaultAddress", |
| 120 | + ], |
| 121 | + }, |
| 122 | + isRural: { |
| 123 | + propDefinition: [ |
| 124 | + domainGroup, |
| 125 | + "isRural", |
| 126 | + ], |
| 127 | + }, |
| 128 | + occupancyType: { |
| 129 | + type: "string", |
| 130 | + label: "Occupancy Type", |
| 131 | + description: "The occupancy type of the listing", |
| 132 | + options: [ |
| 133 | + "tenanted", |
| 134 | + "vacant", |
| 135 | + ], |
| 136 | + optional: true, |
| 137 | + }, |
| 138 | + }, |
| 139 | + additionalProps() { |
| 140 | + const props = {}; |
| 141 | + if (!this.listingAction) { |
| 142 | + return props; |
| 143 | + } |
| 144 | + |
| 145 | + const saleFromPrice = { |
| 146 | + type: "integer", |
| 147 | + label: "Sale - From Price", |
| 148 | + description: "Lowest price the property is expected to sell for to set search price. For a fixed price, set this value the same as To Price", |
| 149 | + }; |
| 150 | + const saleToPrice = { |
| 151 | + type: "integer", |
| 152 | + label: "Sale - To Price", |
| 153 | + description: "Highest price the property is expected to sell for to set search price. For a fixed price, set this value the same as From Price", |
| 154 | + }; |
| 155 | + const leaseFromPrice = { |
| 156 | + type: "integer", |
| 157 | + label: "Lease - From Price", |
| 158 | + description: "Lowest price the property is expected to rent for to set search price. For a fixed price, set this value the same as To Price", |
| 159 | + }; |
| 160 | + const leaseToPrice = { |
| 161 | + type: "integer", |
| 162 | + label: "Lease - To Price", |
| 163 | + description: "Highest price the property is expected to rent for to set search price. For a fixed price, set this value the same as From Price", |
| 164 | + }; |
| 165 | + |
| 166 | + if (this.listingAction === "sale") { |
| 167 | + props.saleFromPrice = saleFromPrice; |
| 168 | + props.saleToPrice = saleToPrice; |
| 169 | + } |
| 170 | + if (this.listingAction === "rent") { |
| 171 | + props.leaseFromPrice = leaseFromPrice; |
| 172 | + props.leaseToPrice = leaseToPrice; |
| 173 | + } |
| 174 | + if (this.listingAction === "saleAndLease") { |
| 175 | + props.saleFromPrice = saleFromPrice; |
| 176 | + props.saleToPrice = saleToPrice; |
| 177 | + props.leaseFromPrice = leaseFromPrice; |
| 178 | + props.leaseToPrice = leaseToPrice; |
| 179 | + } |
| 180 | + |
| 181 | + return props; |
| 182 | + }, |
| 183 | + async run({ $ }) { |
| 184 | + const response = await this.domainGroup.createCommercialListing({ |
| 185 | + $, |
| 186 | + data: { |
| 187 | + domainAgencyID: this.agencyId, |
| 188 | + providerAdId: this.providerAdId, |
| 189 | + nabers: this.nabers, |
| 190 | + listingAction: this.listingAction, |
| 191 | + underOfferOrContract: this.underOfferOrContract, |
| 192 | + salePrice: this.saleFromPrice |
| 193 | + ? { |
| 194 | + from: this.saleFromPrice, |
| 195 | + to: this.saleToPrice, |
| 196 | + } |
| 197 | + : undefined, |
| 198 | + leasePrice: this.leaseFromPrice |
| 199 | + ? { |
| 200 | + from: this.leaseFromPrice, |
| 201 | + to: this.leaseToPrice, |
| 202 | + } |
| 203 | + : undefined, |
| 204 | + description: this.description, |
| 205 | + features: this.features, |
| 206 | + propertyDetails: { |
| 207 | + propertyType: [ |
| 208 | + this.propertyType, |
| 209 | + ], |
| 210 | + address: { |
| 211 | + streetNumber: this.streetNumber, |
| 212 | + unitNumber: this.unitNumber, |
| 213 | + street: this.street, |
| 214 | + state: this.state, |
| 215 | + suburb: this.suburb, |
| 216 | + postcode: this.postcode, |
| 217 | + }, |
| 218 | + area: { |
| 219 | + value: +this.areaValue, |
| 220 | + unit: this.areaUnit, |
| 221 | + }, |
| 222 | + }, |
| 223 | + receiveEmailsToDefaultAddress: this.receiveEmailsToDefaultAddress, |
| 224 | + isRural: this.isRural, |
| 225 | + occupancyType: this.occupancyType, |
| 226 | + }, |
| 227 | + }); |
| 228 | + $.export("$summary", `Created commercial listing with ID: ${response.id}`); |
| 229 | + return response; |
| 230 | + }, |
| 231 | +}; |
0 commit comments