Skip to content

Commit

Permalink
Add the computed device.should_be_running__release field
Browse files Browse the repository at this point in the history
Change-type: minor
  • Loading branch information
thgreasi committed Aug 29, 2024
1 parent ce93620 commit 22e54d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/models/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ const getDeviceModel = function (
* you have to explicitly define them in a `$select` in the extra options:
* * `overall_status`
* * `overall_progress`
* * `should_be_running__release`
*
* @param {String|Number} slugOrUuidOrId - application slug (string), uuid (string) or id (number)
* @param {Object} [options={}] - extra pine options to use
Expand Down Expand Up @@ -511,6 +512,7 @@ const getDeviceModel = function (
* you have to explicitly define them in a `$select` in the extra options:
* * `overall_status`
* * `overall_progress`
* * `should_be_running__release`
*
* @param {String|Number} handleOrId - organization handle (string) or id (number).
* @param {Object} [options={}] - extra pine options to use
Expand Down Expand Up @@ -577,6 +579,7 @@ const getDeviceModel = function (
* you have to explicitly define them in a `$select` in the extra options:
* * `overall_status`
* * `overall_progress`
* * `should_be_running__release`
*
* @param {String|Number} uuidOrId - device uuid (string) or id (number)
* @param {Object} [options={}] - extra pine options to use
Expand Down Expand Up @@ -1974,29 +1977,17 @@ const getDeviceModel = function (
const deviceOptions = {
$select: 'id',
$expand: {
is_pinned_on__release: {
should_be_running__release: {
$select: 'commit',
},
belongs_to__application: {
$select: 'id',
$expand: { should_be_running__release: { $select: 'commit' } },
},
},
} as const;

const { is_pinned_on__release, belongs_to__application } =
(await exports.get(uuidOrId, deviceOptions)) as PineTypedResult<
Device,
typeof deviceOptions
>;
if (is_pinned_on__release.length > 0) {
return is_pinned_on__release[0]!.commit;
}
const targetRelease =
belongs_to__application[0].should_be_running__release[0];
if (targetRelease) {
return targetRelease.commit;
}
const { should_be_running__release } = (await exports.get(
uuidOrId,
deviceOptions,
)) as PineTypedResult<Device, typeof deviceOptions>;
return should_be_running__release[0]?.commit;
},

/**
Expand Down
3 changes: 3 additions & 0 deletions src/types/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ export interface Device {
should_be_operated_by__release: OptionalNavigationResource<Release>;
should_be_managed_by__release: OptionalNavigationResource<Release>;

/** This is a computed term that works like: `device.is_pinned_on__release ?? device.belongs_to__application[0].should_be_running__release` */
should_be_running__release: OptionalNavigationResource<Release>;

device_config_variable: ReverseNavigationResource<DeviceVariable>;
device_environment_variable: ReverseNavigationResource<DeviceVariable>;
device_tag: ReverseNavigationResource<DeviceTag>;
Expand Down

0 comments on commit 22e54d6

Please sign in to comment.