Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore host app service installs for device service env vars #1499

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 42 additions & 21 deletions src/models/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2911,7 +2911,19 @@ const getDeviceModel = function (
serviceNameOrId: string | number,
key: string,
): Promise<string | undefined> {
const { id: deviceId } = await exports.get(uuidOrId, { $select: 'id' });
const deviceOptions = {
$select: 'id',
$expand: { belongs_to__application: { $select: 'id' } },
} as const;

const {
id: deviceId,
belongs_to__application: [{ id: appId }],
} = (await sdkInstance.models.device.get(
uuidOrId,
deviceOptions,
)) as PineTypedResult<Device, typeof deviceOptions>;

const [variable] = await pine.get({
resource: 'device_service_environment_variable',
options: {
Expand All @@ -2932,6 +2944,7 @@ const getDeviceModel = function (
$expr: {
is: {
service_name: serviceNameOrId,
application: appId,
},
},
},
Expand Down Expand Up @@ -2984,31 +2997,25 @@ const getDeviceModel = function (
): Promise<void> {
value = String(value);

let deviceFilter;
if (isId(uuidOrId)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if we could preserve this optimization, since I think the UI relies on it to make less requests.
Other than that LGTM 👍

deviceFilter = uuidOrId;
} else if (isFullUuid(uuidOrId)) {
deviceFilter = {
$any: {
$alias: 'd',
$expr: {
d: {
uuid: uuidOrId,
},
},
},
};
} else {
const device = await exports.get(uuidOrId, { $select: 'id' });
deviceFilter = device.id;
}
const deviceOptions = {
$select: 'id',
$expand: { belongs_to__application: { $select: 'id' } },
} as const;

const {
id: deviceId,
belongs_to__application: [{ id: appId }],
} = (await sdkInstance.models.device.get(
uuidOrId,
deviceOptions,
)) as PineTypedResult<Device, typeof deviceOptions>;

const serviceInstalls = await pine.get({
resource: 'service_install',
options: {
$select: 'id',
$filter: {
device: deviceFilter,
device: deviceId,
installs__service:
typeof serviceNameOrId === 'number'
? serviceNameOrId
Expand All @@ -3018,6 +3025,7 @@ const getDeviceModel = function (
$expr: {
s: {
service_name: serviceNameOrId,
application: appId,
},
},
},
Expand Down Expand Up @@ -3079,7 +3087,19 @@ const getDeviceModel = function (
serviceNameOrId: string | number,
key: string,
): Promise<void> {
const { id: deviceId } = await exports.get(uuidOrId, { $select: 'id' });
const deviceOptions = {
$select: 'id',
$expand: { belongs_to__application: { $select: 'id' } },
} as const;

const {
id: deviceId,
belongs_to__application: [{ id: appId }],
} = (await sdkInstance.models.device.get(
uuidOrId,
deviceOptions,
)) as PineTypedResult<Device, typeof deviceOptions>;

await pine.delete({
resource: 'device_service_environment_variable',
options: {
Expand All @@ -3099,6 +3119,7 @@ const getDeviceModel = function (
$expr: {
is: {
service_name: serviceNameOrId,
application: appId,
},
},
},
Expand Down
Loading