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 } }) {
|
module.exports = async function ({ services: { authTokenHandler } }) {
|
||||||
async function doAuthLoginToken(req) {
|
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
|
// Validate the auth token JWT and extract the auth token
|
||||||
const authToken = authTokenHandler.decodeAuthToken(authTokenJwt)
|
const authToken = authTokenHandler.decodeAuthToken(authTokenJwt)
|
||||||
|
@ -10,6 +15,7 @@ module.exports = async function ({ services: { authTokenHandler } }) {
|
||||||
await authTokenHandler.getOrCreateUserSession(
|
await authTokenHandler.getOrCreateUserSession(
|
||||||
authToken,
|
authToken,
|
||||||
phoneModel,
|
phoneModel,
|
||||||
|
phoneOS,
|
||||||
deviceUuid
|
deviceUuid
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ requestBody:
|
||||||
format: apiJwt
|
format: apiJwt
|
||||||
phoneModel:
|
phoneModel:
|
||||||
type: string
|
type: string
|
||||||
|
phoneOS:
|
||||||
|
type: string
|
||||||
deviceUuid:
|
deviceUuid:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
|
|
|
@ -22,6 +22,7 @@ module.exports = ({ services }) => {
|
||||||
async function getOrCreateUserSession(
|
async function getOrCreateUserSession(
|
||||||
authToken,
|
authToken,
|
||||||
phoneModel = null,
|
phoneModel = null,
|
||||||
|
phoneOS = null,
|
||||||
deviceUuid = null
|
deviceUuid = null
|
||||||
) {
|
) {
|
||||||
let userId
|
let userId
|
||||||
|
@ -54,8 +55,8 @@ module.exports = ({ services }) => {
|
||||||
id
|
id
|
||||||
`
|
`
|
||||||
;[{ id: deviceId }] = await sql`
|
;[{ id: deviceId }] = await sql`
|
||||||
INSERT INTO "device" ("user_id", "phone_model", "uuid")
|
INSERT INTO "device" ("user_id", "phone_model", "phone_os", "uuid")
|
||||||
VALUES (${userId}, ${phoneModel}, ${deviceUuid})
|
VALUES (${userId}, ${phoneModel}, ${phoneOS}, ${deviceUuid})
|
||||||
RETURNING
|
RETURNING
|
||||||
id
|
id
|
||||||
`
|
`
|
||||||
|
@ -104,8 +105,8 @@ module.exports = ({ services }) => {
|
||||||
if (!deviceId) {
|
if (!deviceId) {
|
||||||
// Only create new device if UUID doesn't exist
|
// Only create new device if UUID doesn't exist
|
||||||
;[{ id: deviceId }] = await sql`
|
;[{ id: deviceId }] = await sql`
|
||||||
INSERT INTO "device" ("user_id", "phone_model", "uuid")
|
INSERT INTO "device" ("user_id", "phone_model", "phone_os", "uuid")
|
||||||
VALUES (${userId}, ${phoneModel}, ${deviceUuid})
|
VALUES (${userId}, ${phoneModel}, ${phoneOS}, ${deviceUuid})
|
||||||
RETURNING
|
RETURNING
|
||||||
id
|
id
|
||||||
`
|
`
|
||||||
|
|
|
@ -3,10 +3,22 @@ table:
|
||||||
schema: public
|
schema: public
|
||||||
configuration:
|
configuration:
|
||||||
column_config:
|
column_config:
|
||||||
|
acknowledged_around_count:
|
||||||
|
custom_name: acknowledgedAroundCount
|
||||||
|
acknowledged_connect_count:
|
||||||
|
custom_name: acknowledgedConnectCount
|
||||||
|
acknowledged_relative_count:
|
||||||
|
custom_name: acknowledgedRelativeCount
|
||||||
alert_id:
|
alert_id:
|
||||||
custom_name: alertId
|
custom_name: alertId
|
||||||
alert_tag:
|
alert_tag:
|
||||||
custom_name: alertTag
|
custom_name: alertTag
|
||||||
|
alerting_around_count:
|
||||||
|
custom_name: alertingAroundCount
|
||||||
|
alerting_connect_count:
|
||||||
|
custom_name: alertingConnectCount
|
||||||
|
alerting_relative_count:
|
||||||
|
custom_name: alertingRelativeCount
|
||||||
altitude_accuracy:
|
altitude_accuracy:
|
||||||
custom_name: altitudeAccuracy
|
custom_name: altitudeAccuracy
|
||||||
archive_created_at:
|
archive_created_at:
|
||||||
|
@ -21,8 +33,20 @@ configuration:
|
||||||
custom_name: createdAt
|
custom_name: createdAt
|
||||||
device_id:
|
device_id:
|
||||||
custom_name: deviceId
|
custom_name: deviceId
|
||||||
|
emergency_calling_notification_sent:
|
||||||
|
custom_name: emergencyCallingNotificationSent
|
||||||
|
follow_location:
|
||||||
|
custom_name: followLocation
|
||||||
|
initial_location:
|
||||||
|
custom_name: initialLocation
|
||||||
keep_open_at:
|
keep_open_at:
|
||||||
custom_name: keepOpenAt
|
custom_name: keepOpenAt
|
||||||
|
last_address:
|
||||||
|
custom_name: lastAddress
|
||||||
|
last_nearest_place:
|
||||||
|
custom_name: lastNearestPlace
|
||||||
|
last_what3words:
|
||||||
|
custom_name: lastWhat3Words
|
||||||
nearest_place:
|
nearest_place:
|
||||||
custom_name: nearestPlace
|
custom_name: nearestPlace
|
||||||
notified_count:
|
notified_count:
|
||||||
|
@ -44,8 +68,14 @@ configuration:
|
||||||
what3words:
|
what3words:
|
||||||
custom_name: what3Words
|
custom_name: what3Words
|
||||||
custom_column_names:
|
custom_column_names:
|
||||||
|
acknowledged_around_count: acknowledgedAroundCount
|
||||||
|
acknowledged_connect_count: acknowledgedConnectCount
|
||||||
|
acknowledged_relative_count: acknowledgedRelativeCount
|
||||||
alert_id: alertId
|
alert_id: alertId
|
||||||
alert_tag: alertTag
|
alert_tag: alertTag
|
||||||
|
alerting_around_count: alertingAroundCount
|
||||||
|
alerting_connect_count: alertingConnectCount
|
||||||
|
alerting_relative_count: alertingRelativeCount
|
||||||
altitude_accuracy: altitudeAccuracy
|
altitude_accuracy: altitudeAccuracy
|
||||||
archive_created_at: archiveCreatedAt
|
archive_created_at: archiveCreatedAt
|
||||||
call_emergency: callEmergency
|
call_emergency: callEmergency
|
||||||
|
@ -53,7 +83,13 @@ configuration:
|
||||||
closed_by: closedBy
|
closed_by: closedBy
|
||||||
created_at: createdAt
|
created_at: createdAt
|
||||||
device_id: deviceId
|
device_id: deviceId
|
||||||
|
emergency_calling_notification_sent: emergencyCallingNotificationSent
|
||||||
|
follow_location: followLocation
|
||||||
|
initial_location: initialLocation
|
||||||
keep_open_at: keepOpenAt
|
keep_open_at: keepOpenAt
|
||||||
|
last_address: lastAddress
|
||||||
|
last_nearest_place: lastNearestPlace
|
||||||
|
last_what3words: lastWhat3Words
|
||||||
nearest_place: nearestPlace
|
nearest_place: nearestPlace
|
||||||
notified_count: notifiedCount
|
notified_count: notifiedCount
|
||||||
notify_around: notifyAround
|
notify_around: notifyAround
|
||||||
|
|
|
@ -15,6 +15,8 @@ configuration:
|
||||||
custom_name: notificationAlertLevel
|
custom_name: notificationAlertLevel
|
||||||
phone_model:
|
phone_model:
|
||||||
custom_name: phoneModel
|
custom_name: phoneModel
|
||||||
|
phone_os:
|
||||||
|
custom_name: phoneOs
|
||||||
preferred_emergency_call:
|
preferred_emergency_call:
|
||||||
custom_name: preferredEmergencyCall
|
custom_name: preferredEmergencyCall
|
||||||
radius_all:
|
radius_all:
|
||||||
|
@ -32,6 +34,7 @@ configuration:
|
||||||
follow_location: followLocation
|
follow_location: followLocation
|
||||||
notification_alert_level: notificationAlertLevel
|
notification_alert_level: notificationAlertLevel
|
||||||
phone_model: phoneModel
|
phone_model: phoneModel
|
||||||
|
phone_os: phoneOs
|
||||||
preferred_emergency_call: preferredEmergencyCall
|
preferred_emergency_call: preferredEmergencyCall
|
||||||
radius_all: radiusAll
|
radius_all: radiusAll
|
||||||
radius_reach: radiusReach
|
radius_reach: radiusReach
|
||||||
|
@ -59,6 +62,7 @@ insert_permissions:
|
||||||
user_id: X-Hasura-User-Id
|
user_id: X-Hasura-User-Id
|
||||||
columns:
|
columns:
|
||||||
- phone_model
|
- phone_model
|
||||||
|
- phone_os
|
||||||
- uuid
|
- uuid
|
||||||
select_permissions:
|
select_permissions:
|
||||||
- role: owner
|
- role: owner
|
||||||
|
@ -73,6 +77,7 @@ select_permissions:
|
||||||
- location
|
- location
|
||||||
- notification_alert_level
|
- notification_alert_level
|
||||||
- phone_model
|
- phone_model
|
||||||
|
- phone_os
|
||||||
- preferred_emergency_call
|
- preferred_emergency_call
|
||||||
- radius_all
|
- radius_all
|
||||||
- radius_reach
|
- 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_content_type.yaml"
|
||||||
- "!include public_enum_emergency_call.yaml"
|
- "!include public_enum_emergency_call.yaml"
|
||||||
- "!include public_enum_notification_type.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_login_request_type.yaml"
|
||||||
- "!include public_enum_user_role.yaml"
|
- "!include public_enum_user_role.yaml"
|
||||||
- "!include public_external_public_config.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