diff --git a/package-lock.json b/package-lock.json index 14c6b5bd..55d77a3b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2639,9 +2639,9 @@ } }, "node_modules/@isaacs/fs-minipass/node_modules/minipass": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.1.tgz", - "integrity": "sha512-UZ7eQ+h8ywIRAW1hIEl2AqdwzJucU/Kp59+8kkZeSvafXhZjul247BvIJjEVFVeON6d7lM46XX1HXCduKAS8VA==", + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", + "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", "dev": true, "engines": { "node": ">=16 || 14 >=14.17" @@ -8781,9 +8781,9 @@ "dev": true }, "node_modules/jackspeak": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.3.6.tgz", - "integrity": "sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.3.0.tgz", + "integrity": "sha512-glPiBfKguqA7v8JsXO3iLjJWZ9FV1vNpoI0I9hI9Mnk5yetO9uPLSpiCEmiVijAssv2f54HpvtzvAHfhPieiDQ==", "dev": true, "dependencies": { "@isaacs/cliui": "^8.0.2" @@ -12509,16 +12509,16 @@ } }, "node_modules/supabase": { - "version": "1.167.4", - "resolved": "https://registry.npmjs.org/supabase/-/supabase-1.167.4.tgz", - "integrity": "sha512-DTaTsYQ48FdOPvTTl3H1cQnGDHvm4kQdBakeI5qbs7BFZgu2SRJDYRrCcSgH9sbZReOKrQdJCPfNpoy/Z359gA==", + "version": "1.172.2", + "resolved": "https://registry.npmjs.org/supabase/-/supabase-1.172.2.tgz", + "integrity": "sha512-h2J6kKEikXnZyurUcCYg215qkQpINOhdWkiclHcWAuVeqXsNrfrYaf1s0qbbcdRyMtrVW48I+VdVTw71Cnn20Q==", "dev": true, "hasInstallScript": true, "dependencies": { "bin-links": "^4.0.3", "https-proxy-agent": "^7.0.2", "node-fetch": "^3.3.2", - "tar": "7.1.0" + "tar": "7.2.0" }, "bin": { "supabase": "bin/supabase" @@ -12567,16 +12567,16 @@ } }, "node_modules/supabase/node_modules/glob": { - "version": "10.3.15", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.15.tgz", - "integrity": "sha512-0c6RlJt1TICLyvJYIApxb8GsXoai0KUP7AxKKAtsYXdgJR1mGEUa7DgwShbdk1nly0PYoZj01xd4hzbq3fsjpw==", + "version": "10.4.1", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.1.tgz", + "integrity": "sha512-2jelhlq3E4ho74ZyVLN03oKdAZVUa6UDZzFLVH1H7dnoax+y9qyaq8zBkfDIggjniU19z0wU18y16jMB2eyVIw==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", - "jackspeak": "^2.3.6", - "minimatch": "^9.0.1", - "minipass": "^7.0.4", - "path-scurry": "^1.11.0" + "jackspeak": "^3.1.2", + "minimatch": "^9.0.4", + "minipass": "^7.1.2", + "path-scurry": "^1.11.1" }, "bin": { "glob": "dist/esm/bin.mjs" @@ -12617,9 +12617,9 @@ } }, "node_modules/supabase/node_modules/minipass": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.1.tgz", - "integrity": "sha512-UZ7eQ+h8ywIRAW1hIEl2AqdwzJucU/Kp59+8kkZeSvafXhZjul247BvIJjEVFVeON6d7lM46XX1HXCduKAS8VA==", + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", + "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", "dev": true, "engines": { "node": ">=16 || 14 >=14.17" @@ -12690,9 +12690,9 @@ } }, "node_modules/supabase/node_modules/tar": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/tar/-/tar-7.1.0.tgz", - "integrity": "sha512-ENhg4W6BmjYxl8GTaE7/h99f0aXiSWv4kikRZ9n2/JRxypZniE84ILZqimAhxxX7Zb8Px6pFdheW3EeHfhnXQQ==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/tar/-/tar-7.2.0.tgz", + "integrity": "sha512-hctwP0Nb4AB60bj8WQgRYaMOuJYRAPMGiQUAotms5igN8ppfQM+IvjQ5HcKu1MaZh2Wy2KWVTe563Yj8dfc14w==", "dev": true, "dependencies": { "@isaacs/fs-minipass": "^4.0.0", diff --git a/src/server/helpers/parse-message.test.ts b/src/server/helpers/parse-message.test.ts index 06a89f8f..f5da3794 100644 --- a/src/server/helpers/parse-message.test.ts +++ b/src/server/helpers/parse-message.test.ts @@ -21,7 +21,7 @@ describe("parseMessageAruba", () => { })).toMatchInlineSnapshot(` { "access_point_name": "A-23-0-007", - "building_number": 23, + "building_number": "23", "device_count": 3, "updated_at": "2023-03-21T12:01:20.000Z", } @@ -41,7 +41,22 @@ describe("parseMessageAruba", () => { "from name with dashes" ) .toContain({ - "building_number": 66, + "building_number": "66", + }); + + expect( + parseMessageAruba({ + timestamp: "1679400080000", + decodedValue: { + name: "AP-08-00-01-350-03", + site: "", + status: "Up", + } + }), + "start single digits with zero" + ) + .toContain({ + "building_number": "08", }); expect( diff --git a/src/server/helpers/parse-message.ts b/src/server/helpers/parse-message.ts index 7d11ae60..161a459c 100644 --- a/src/server/helpers/parse-message.ts +++ b/src/server/helpers/parse-message.ts @@ -10,7 +10,13 @@ export function parseMessageAruba( "updated_at": new Date(Number(timestamp)).toISOString(), "access_point_name": decodedValue.name, "device_count": decodedValue.client_count, - "building_number": Number(String(decodedValue.name).split("-").at(1)) || null, + "building_number": parseBuildingNumber({ name: decodedValue.name as string }), }; } +function parseBuildingNumber({ name }: { name: string }) { + const rawBuildingNumber = Number(name.split("-").at(1)); + return rawBuildingNumber + ? String(rawBuildingNumber).padStart(2, "0") + : null; +} diff --git a/supabase/migrations/20240605091301_building-number-string-views.sql b/supabase/migrations/20240605091301_building-number-string-views.sql new file mode 100644 index 00000000..e75eda67 --- /dev/null +++ b/supabase/migrations/20240605091301_building-number-string-views.sql @@ -0,0 +1,20 @@ +do $$ + declare buildings_latest_states_def text; + declare spaces_latest_states_def text; + declare exec_text_one text; + declare exec_text_two text; +begin + buildings_latest_states_def := pg_get_viewdef('buildings_latest_states'); + drop materialized view buildings_latest_states; + spaces_latest_states_def := pg_get_viewdef('spaces_latest_states'); + drop materialized view spaces_latest_states; + + alter table "public"."access_points_latest_states" alter column "building_number" set data type text using "building_number"::text; + + exec_text_one := format('create view buildings_latest_states as %s', + buildings_latest_states_def); + execute exec_text_one; + exec_text_two := format('create view spaces_latest_states as %s', + spaces_latest_states_def); + execute exec_text_two; +end $$; diff --git a/supabase/seed.sql b/supabase/seed.sql index c20d162a..8d62fff3 100644 --- a/supabase/seed.sql +++ b/supabase/seed.sql @@ -7,7 +7,7 @@ insert into device_count ) values - (now(), 'A-21-0-034', 21, '21.01', 78), - (now(), 'A-32-0-043', 32, '32.02', 58), - (now(), 'A-36-0-025', 36, null, 54), - (now(), 'A-32-0-029', 32, null, 46); + (now(), 'A-21-0-034', '21', '21.01', 78), + (now(), 'A-32-0-043', '32', '32.02', 58), + (now(), 'A-36-0-025', '36', null, 54), + (now(), 'A-32-0-029', '32', null, 46);