Skip to content

Commit

Permalink
refactor(config): Simplify attributes length check in listenQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
csulit committed Oct 24, 2024
1 parent 330ae9c commit a3bc7a1
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions config/deno-kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,17 @@ export async function listenQueue(kv: Deno.Kv) {
case "CREATE_LISTING":
if (msg.source === "LAMUDI" && msg.data.listingUrl && msg.data) {
const handleCondominium = async () => {
let transaction;
let transaction: Transaction | null = null;
const client_1 = await dbPool.connect();
const client_2 = await dbPool.connect();

try {
const attributesLength = Object.keys(
msg.data.dataLayer.attributes
).length;

console.log("attributesLength:", attributesLength);

transaction = client_1.createTransaction("create-listing");

await transaction.begin();
Expand All @@ -129,12 +135,9 @@ export async function listenQueue(kv: Deno.Kv) {
throw new Error("DataLayer is missing or undefined");
}

if (
!msg.data.dataLayer.attributes ||
Object.keys(msg.data.dataLayer.attributes).length < 5
) {
if (!msg.data.dataLayer.attributes || attributesLength < 3) {
throw new Error(
"Attributes are missing, undefined, or have fewer than 5 properties"
"Attributes are missing, undefined, or have fewer than 3 properties"
);
}

Expand Down

0 comments on commit a3bc7a1

Please sign in to comment.