@@ -120,6 +120,10 @@ export async function listenQueue(kv: Deno.Kv) {
120
120
const client_1 = await dbPool . connect ( ) ;
121
121
122
122
try {
123
+ transaction = client_1 . createTransaction ( "create-listing" ) ;
124
+
125
+ await transaction . begin ( ) ;
126
+
123
127
if ( ! msg . data ?. dataLayer ) {
124
128
throw new Error ( "DataLayer is missing or undefined" ) ;
125
129
}
@@ -133,6 +137,27 @@ export async function listenQueue(kv: Deno.Kv) {
133
137
) ;
134
138
}
135
139
140
+ if ( ! msg . data . dataLayer . agent_name ) {
141
+ throw new Error ( "Agent name is missing or undefined" ) ;
142
+ }
143
+
144
+ if ( ! msg . data . dataLayer . product_owner ) {
145
+ throw new Error ( "Product owner is missing or undefined" ) ;
146
+ }
147
+
148
+ if ( ! msg . data . dataLayer . product_owner_name ) {
149
+ throw new Error ( "Product owner name is missing or undefined" ) ;
150
+ }
151
+
152
+ if (
153
+ ! msg . data . dataLayer . location ||
154
+ typeof msg . data . dataLayer . location !== "object"
155
+ ) {
156
+ throw new Error (
157
+ "Location is missing, undefined, or not an object"
158
+ ) ;
159
+ }
160
+
136
161
let propertyId ;
137
162
let warehouseTypeId ;
138
163
const listingUrl = msg . data . listingUrl ;
@@ -147,9 +172,6 @@ export async function listenQueue(kv: Deno.Kv) {
147
172
const isLand =
148
173
msg . data . dataLayer . attributes . subcategory === "Land" ;
149
174
150
- transaction = client_1 . createTransaction ( "create-listing" ) ;
151
- await transaction . begin ( ) ;
152
-
153
175
const listingRecord = await transaction . queryObject ( `
154
176
SELECT id, property_id
155
177
FROM Listing
@@ -203,27 +225,6 @@ export async function listenQueue(kv: Deno.Kv) {
203
225
return ;
204
226
}
205
227
206
- if ( ! msg . data . dataLayer . agent_name ) {
207
- throw new Error ( "Agent name is missing or undefined" ) ;
208
- }
209
-
210
- if ( ! msg . data . dataLayer . product_owner ) {
211
- throw new Error ( "Product owner is missing or undefined" ) ;
212
- }
213
-
214
- if ( ! msg . data . dataLayer . product_owner_name ) {
215
- throw new Error ( "Product owner name is missing or undefined" ) ;
216
- }
217
-
218
- if (
219
- ! msg . data . dataLayer . location ||
220
- typeof msg . data . dataLayer . location !== "object"
221
- ) {
222
- throw new Error (
223
- "Location is missing, undefined, or not an object"
224
- ) ;
225
- }
226
-
227
228
if ( isCondominium ) {
228
229
propertyId = 1 ;
229
230
}
0 commit comments