feat: add phoneOS field to device (+ reapply hasura convention)
This commit is contained in:
parent
74430f63ba
commit
74d999a9b8
17 changed files with 93 additions and 5 deletions
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ requestBody:
|
|||
format: apiJwt
|
||||
phoneModel:
|
||||
type: string
|
||||
phoneOS:
|
||||
type: string
|
||||
deviceUuid:
|
||||
type: string
|
||||
format: uuid
|
||||
|
|
|
@ -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
|
||||
`
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
|
@ -0,0 +1,2 @@
|
|||
alter table "public"."device" add column "phone_os" text
|
||||
null;
|
|
@ -0,0 +1 @@
|
|||
DROP TABLE "public"."enum_phone_os";
|
|
@ -0,0 +1 @@
|
|||
CREATE TABLE "public"."enum_phone_os" ("value" text NOT NULL, PRIMARY KEY ("value") );
|
|
@ -0,0 +1 @@
|
|||
DELETE FROM "public"."enum_phone_os" WHERE "value" = 'ios';
|
|
@ -0,0 +1 @@
|
|||
INSERT INTO "public"."enum_phone_os"("value") VALUES (E'ios');
|
|
@ -0,0 +1 @@
|
|||
DELETE FROM "public"."enum_phone_os" WHERE "value" = 'android';
|
|
@ -0,0 +1 @@
|
|||
INSERT INTO "public"."enum_phone_os"("value") VALUES (E'android');
|
|
@ -0,0 +1 @@
|
|||
alter table "public"."device" drop constraint "device_phone_os_fkey";
|
|
@ -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;
|
Loading…
Add table
Reference in a new issue