From 74d999a9b8cba961de52838cce310eeaf26e653e Mon Sep 17 00:00:00 2001 From: devthejo Date: Wed, 23 Jul 2025 14:15:30 +0200 Subject: [PATCH] feat: add phoneOS field to device (+ reapply hasura convention) --- .../v1/operations/auth/login/token.patch.js | 8 ++++- .../auth/login/token.patch.spec.yaml | 2 ++ .../src/api/v1/services/auth-token-handler.js | 9 ++--- .../default/tables/public_archived_alert.yaml | 36 +++++++++++++++++++ .../default/tables/public_device.yaml | 5 +++ .../default/tables/public_enum_phone_os.yaml | 19 ++++++++++ .../databases/default/tables/tables.yaml | 1 + .../down.sql | 4 +++ .../up.sql | 2 ++ .../down.sql | 1 + .../up.sql | 1 + .../down.sql | 1 + .../up.sql | 1 + .../down.sql | 1 + .../up.sql | 1 + .../down.sql | 1 + .../up.sql | 5 +++ 17 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 services/hasura/metadata/databases/default/tables/public_enum_phone_os.yaml create mode 100644 services/hasura/migrations/default/1753272680821_alter_table_public_device_add_column_phone_os/down.sql create mode 100644 services/hasura/migrations/default/1753272680821_alter_table_public_device_add_column_phone_os/up.sql create mode 100644 services/hasura/migrations/default/1753272720168_create_table_public_enum_phone_os/down.sql create mode 100644 services/hasura/migrations/default/1753272720168_create_table_public_enum_phone_os/up.sql create mode 100644 services/hasura/migrations/default/1753272730188_insert_into_public_enum_phone_os/down.sql create mode 100644 services/hasura/migrations/default/1753272730188_insert_into_public_enum_phone_os/up.sql create mode 100644 services/hasura/migrations/default/1753272736197_insert_into_public_enum_phone_os/down.sql create mode 100644 services/hasura/migrations/default/1753272736197_insert_into_public_enum_phone_os/up.sql create mode 100644 services/hasura/migrations/default/1753272817567_set_fk_public_device_phone_os/down.sql create mode 100644 services/hasura/migrations/default/1753272817567_set_fk_public_device_phone_os/up.sql diff --git a/services/api/src/api/v1/operations/auth/login/token.patch.js b/services/api/src/api/v1/operations/auth/login/token.patch.js index a0d1cef..cd8a2a1 100644 --- a/services/api/src/api/v1/operations/auth/login/token.patch.js +++ b/services/api/src/api/v1/operations/auth/login/token.patch.js @@ -1,6 +1,11 @@ module.exports = async function ({ services: { authTokenHandler } }) { async function doAuthLoginToken(req) { - const { authTokenJwt, phoneModel = null, deviceUuid = null } = req.body + const { + authTokenJwt, + phoneModel = null, + phoneOS = null, + deviceUuid = null, + } = req.body // Validate the auth token JWT and extract the auth token const authToken = authTokenHandler.decodeAuthToken(authTokenJwt) @@ -10,6 +15,7 @@ module.exports = async function ({ services: { authTokenHandler } }) { await authTokenHandler.getOrCreateUserSession( authToken, phoneModel, + phoneOS, deviceUuid ) diff --git a/services/api/src/api/v1/operations/auth/login/token.patch.spec.yaml b/services/api/src/api/v1/operations/auth/login/token.patch.spec.yaml index c4e648a..4548867 100644 --- a/services/api/src/api/v1/operations/auth/login/token.patch.spec.yaml +++ b/services/api/src/api/v1/operations/auth/login/token.patch.spec.yaml @@ -11,6 +11,8 @@ requestBody: format: apiJwt phoneModel: type: string + phoneOS: + type: string deviceUuid: type: string format: uuid diff --git a/services/api/src/api/v1/services/auth-token-handler.js b/services/api/src/api/v1/services/auth-token-handler.js index 533cf19..22abe43 100644 --- a/services/api/src/api/v1/services/auth-token-handler.js +++ b/services/api/src/api/v1/services/auth-token-handler.js @@ -22,6 +22,7 @@ module.exports = ({ services }) => { async function getOrCreateUserSession( authToken, phoneModel = null, + phoneOS = null, deviceUuid = null ) { let userId @@ -54,8 +55,8 @@ module.exports = ({ services }) => { id ` ;[{ id: deviceId }] = await sql` - INSERT INTO "device" ("user_id", "phone_model", "uuid") - VALUES (${userId}, ${phoneModel}, ${deviceUuid}) + INSERT INTO "device" ("user_id", "phone_model", "phone_os", "uuid") + VALUES (${userId}, ${phoneModel}, ${phoneOS}, ${deviceUuid}) RETURNING id ` @@ -104,8 +105,8 @@ module.exports = ({ services }) => { if (!deviceId) { // Only create new device if UUID doesn't exist ;[{ id: deviceId }] = await sql` - INSERT INTO "device" ("user_id", "phone_model", "uuid") - VALUES (${userId}, ${phoneModel}, ${deviceUuid}) + INSERT INTO "device" ("user_id", "phone_model", "phone_os", "uuid") + VALUES (${userId}, ${phoneModel}, ${phoneOS}, ${deviceUuid}) RETURNING id ` diff --git a/services/hasura/metadata/databases/default/tables/public_archived_alert.yaml b/services/hasura/metadata/databases/default/tables/public_archived_alert.yaml index 310d2c9..4d59dfa 100644 --- a/services/hasura/metadata/databases/default/tables/public_archived_alert.yaml +++ b/services/hasura/metadata/databases/default/tables/public_archived_alert.yaml @@ -3,10 +3,22 @@ table: schema: public configuration: column_config: + acknowledged_around_count: + custom_name: acknowledgedAroundCount + acknowledged_connect_count: + custom_name: acknowledgedConnectCount + acknowledged_relative_count: + custom_name: acknowledgedRelativeCount alert_id: custom_name: alertId alert_tag: custom_name: alertTag + alerting_around_count: + custom_name: alertingAroundCount + alerting_connect_count: + custom_name: alertingConnectCount + alerting_relative_count: + custom_name: alertingRelativeCount altitude_accuracy: custom_name: altitudeAccuracy archive_created_at: @@ -21,8 +33,20 @@ configuration: custom_name: createdAt device_id: custom_name: deviceId + emergency_calling_notification_sent: + custom_name: emergencyCallingNotificationSent + follow_location: + custom_name: followLocation + initial_location: + custom_name: initialLocation keep_open_at: custom_name: keepOpenAt + last_address: + custom_name: lastAddress + last_nearest_place: + custom_name: lastNearestPlace + last_what3words: + custom_name: lastWhat3Words nearest_place: custom_name: nearestPlace notified_count: @@ -44,8 +68,14 @@ configuration: what3words: custom_name: what3Words custom_column_names: + acknowledged_around_count: acknowledgedAroundCount + acknowledged_connect_count: acknowledgedConnectCount + acknowledged_relative_count: acknowledgedRelativeCount alert_id: alertId alert_tag: alertTag + alerting_around_count: alertingAroundCount + alerting_connect_count: alertingConnectCount + alerting_relative_count: alertingRelativeCount altitude_accuracy: altitudeAccuracy archive_created_at: archiveCreatedAt call_emergency: callEmergency @@ -53,7 +83,13 @@ configuration: closed_by: closedBy created_at: createdAt device_id: deviceId + emergency_calling_notification_sent: emergencyCallingNotificationSent + follow_location: followLocation + initial_location: initialLocation keep_open_at: keepOpenAt + last_address: lastAddress + last_nearest_place: lastNearestPlace + last_what3words: lastWhat3Words nearest_place: nearestPlace notified_count: notifiedCount notify_around: notifyAround diff --git a/services/hasura/metadata/databases/default/tables/public_device.yaml b/services/hasura/metadata/databases/default/tables/public_device.yaml index 819379d..a200c3b 100644 --- a/services/hasura/metadata/databases/default/tables/public_device.yaml +++ b/services/hasura/metadata/databases/default/tables/public_device.yaml @@ -15,6 +15,8 @@ configuration: custom_name: notificationAlertLevel phone_model: custom_name: phoneModel + phone_os: + custom_name: phoneOs preferred_emergency_call: custom_name: preferredEmergencyCall radius_all: @@ -32,6 +34,7 @@ configuration: follow_location: followLocation notification_alert_level: notificationAlertLevel phone_model: phoneModel + phone_os: phoneOs preferred_emergency_call: preferredEmergencyCall radius_all: radiusAll radius_reach: radiusReach @@ -59,6 +62,7 @@ insert_permissions: user_id: X-Hasura-User-Id columns: - phone_model + - phone_os - uuid select_permissions: - role: owner @@ -73,6 +77,7 @@ select_permissions: - location - notification_alert_level - phone_model + - phone_os - preferred_emergency_call - radius_all - radius_reach diff --git a/services/hasura/metadata/databases/default/tables/public_enum_phone_os.yaml b/services/hasura/metadata/databases/default/tables/public_enum_phone_os.yaml new file mode 100644 index 0000000..730d2ae --- /dev/null +++ b/services/hasura/metadata/databases/default/tables/public_enum_phone_os.yaml @@ -0,0 +1,19 @@ +table: + name: enum_phone_os + schema: public +is_enum: true +configuration: + column_config: {} + custom_column_names: {} + custom_root_fields: + delete: deleteManyEnumPhoneOs + delete_by_pk: deleteOneEnumPhoneOs + insert: insertManyEnumPhoneOs + insert_one: insertOneEnumPhoneOs + select: selectManyEnumPhoneOs + select_aggregate: selectAggEnumPhoneOs + select_by_pk: selectOneEnumPhoneOs + select_stream: selectStreamEnumPhoneOs + update: updateManyEnumPhoneOs + update_by_pk: updateOneEnumPhoneOs + update_many: updateBatchEnumPhoneOs diff --git a/services/hasura/metadata/databases/default/tables/tables.yaml b/services/hasura/metadata/databases/default/tables/tables.yaml index 5596289..fddb64f 100644 --- a/services/hasura/metadata/databases/default/tables/tables.yaml +++ b/services/hasura/metadata/databases/default/tables/tables.yaml @@ -19,6 +19,7 @@ - "!include public_enum_content_type.yaml" - "!include public_enum_emergency_call.yaml" - "!include public_enum_notification_type.yaml" +- "!include public_enum_phone_os.yaml" - "!include public_enum_user_login_request_type.yaml" - "!include public_enum_user_role.yaml" - "!include public_external_public_config.yaml" diff --git a/services/hasura/migrations/default/1753272680821_alter_table_public_device_add_column_phone_os/down.sql b/services/hasura/migrations/default/1753272680821_alter_table_public_device_add_column_phone_os/down.sql new file mode 100644 index 0000000..f93abf0 --- /dev/null +++ b/services/hasura/migrations/default/1753272680821_alter_table_public_device_add_column_phone_os/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."device" add column "phone_os" text +-- null; diff --git a/services/hasura/migrations/default/1753272680821_alter_table_public_device_add_column_phone_os/up.sql b/services/hasura/migrations/default/1753272680821_alter_table_public_device_add_column_phone_os/up.sql new file mode 100644 index 0000000..8557754 --- /dev/null +++ b/services/hasura/migrations/default/1753272680821_alter_table_public_device_add_column_phone_os/up.sql @@ -0,0 +1,2 @@ +alter table "public"."device" add column "phone_os" text + null; diff --git a/services/hasura/migrations/default/1753272720168_create_table_public_enum_phone_os/down.sql b/services/hasura/migrations/default/1753272720168_create_table_public_enum_phone_os/down.sql new file mode 100644 index 0000000..d0e6320 --- /dev/null +++ b/services/hasura/migrations/default/1753272720168_create_table_public_enum_phone_os/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."enum_phone_os"; diff --git a/services/hasura/migrations/default/1753272720168_create_table_public_enum_phone_os/up.sql b/services/hasura/migrations/default/1753272720168_create_table_public_enum_phone_os/up.sql new file mode 100644 index 0000000..0162a9a --- /dev/null +++ b/services/hasura/migrations/default/1753272720168_create_table_public_enum_phone_os/up.sql @@ -0,0 +1 @@ +CREATE TABLE "public"."enum_phone_os" ("value" text NOT NULL, PRIMARY KEY ("value") ); diff --git a/services/hasura/migrations/default/1753272730188_insert_into_public_enum_phone_os/down.sql b/services/hasura/migrations/default/1753272730188_insert_into_public_enum_phone_os/down.sql new file mode 100644 index 0000000..d8a6b3a --- /dev/null +++ b/services/hasura/migrations/default/1753272730188_insert_into_public_enum_phone_os/down.sql @@ -0,0 +1 @@ +DELETE FROM "public"."enum_phone_os" WHERE "value" = 'ios'; diff --git a/services/hasura/migrations/default/1753272730188_insert_into_public_enum_phone_os/up.sql b/services/hasura/migrations/default/1753272730188_insert_into_public_enum_phone_os/up.sql new file mode 100644 index 0000000..b9f8892 --- /dev/null +++ b/services/hasura/migrations/default/1753272730188_insert_into_public_enum_phone_os/up.sql @@ -0,0 +1 @@ +INSERT INTO "public"."enum_phone_os"("value") VALUES (E'ios'); diff --git a/services/hasura/migrations/default/1753272736197_insert_into_public_enum_phone_os/down.sql b/services/hasura/migrations/default/1753272736197_insert_into_public_enum_phone_os/down.sql new file mode 100644 index 0000000..39b9a07 --- /dev/null +++ b/services/hasura/migrations/default/1753272736197_insert_into_public_enum_phone_os/down.sql @@ -0,0 +1 @@ +DELETE FROM "public"."enum_phone_os" WHERE "value" = 'android'; diff --git a/services/hasura/migrations/default/1753272736197_insert_into_public_enum_phone_os/up.sql b/services/hasura/migrations/default/1753272736197_insert_into_public_enum_phone_os/up.sql new file mode 100644 index 0000000..3f1cbd3 --- /dev/null +++ b/services/hasura/migrations/default/1753272736197_insert_into_public_enum_phone_os/up.sql @@ -0,0 +1 @@ +INSERT INTO "public"."enum_phone_os"("value") VALUES (E'android'); diff --git a/services/hasura/migrations/default/1753272817567_set_fk_public_device_phone_os/down.sql b/services/hasura/migrations/default/1753272817567_set_fk_public_device_phone_os/down.sql new file mode 100644 index 0000000..e530491 --- /dev/null +++ b/services/hasura/migrations/default/1753272817567_set_fk_public_device_phone_os/down.sql @@ -0,0 +1 @@ +alter table "public"."device" drop constraint "device_phone_os_fkey"; diff --git a/services/hasura/migrations/default/1753272817567_set_fk_public_device_phone_os/up.sql b/services/hasura/migrations/default/1753272817567_set_fk_public_device_phone_os/up.sql new file mode 100644 index 0000000..1008c93 --- /dev/null +++ b/services/hasura/migrations/default/1753272817567_set_fk_public_device_phone_os/up.sql @@ -0,0 +1,5 @@ +alter table "public"."device" + add constraint "device_phone_os_fkey" + foreign key ("phone_os") + references "public"."enum_phone_os" + ("value") on update restrict on delete restrict;