Skip to content

Commit

Permalink
application.get: Add support for retrieving applications by uuid
Browse files Browse the repository at this point in the history
Resolves: #1016
Change-type: minor
Signed-off-by: Thodoris Greasidis <thodoris@balena.io>
  • Loading branch information
thgreasi committed Apr 7, 2021
1 parent 572c548 commit 4324a30
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 154 deletions.
14 changes: 7 additions & 7 deletions lib/models/application-invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const getApplicationInviteModel = function (
deps: InjectedDependenciesParam,
opts: InjectedOptionsParam,
getApplication: (
nameOrSlugOrId: string | number,
nameOrSlugOrUuidOrId: string | number,
options?: PineOptions<Application>,
) => Promise<Application>,
) {
Expand Down Expand Up @@ -89,7 +89,7 @@ const getApplicationInviteModel = function (
* @description
* This method returns all invites for a specific application.
*
* @param {String|Number} nameOrSlugOrId - application name (string), slug (string) or id (number)
* @param {String|Number} nameOrSlugOrUuidOrId - application name (string), slug (string), uuid (string) or id (number)
* @param {Object} [options={}] - extra pine options to use
* @fulfil {Object[]} - invites
* @returns {Promise}
Expand All @@ -110,10 +110,10 @@ const getApplicationInviteModel = function (
* });
*/
async getAllByApplication(
nameOrSlugOrId: number | string,
nameOrSlugOrUuidOrId: number | string,
options: PineOptions<ApplicationInvite> = {},
): Promise<ApplicationInvite[]> {
const { id } = await getApplication(nameOrSlugOrId, {
const { id } = await getApplication(nameOrSlugOrUuidOrId, {
$select: 'id',
});
return await exports.getAll(
Expand All @@ -133,7 +133,7 @@ const getApplicationInviteModel = function (
*
* @description This method invites a user by their email to an application.
*
* @param {String|Number} nameOrSlugOrId - application name (string), slug (string) or id (number)
* @param {String|Number} nameOrSlugOrUuidOrId - application name (string), slug (string), uuid (string) or id (number)
* @param {Object} options - invite creation parameters
* @param {String} options.invitee - the email/balena_username of the invitee
* @param {String} [options.roleName="developer"] - the role name to be granted to the invitee
Expand All @@ -153,11 +153,11 @@ const getApplicationInviteModel = function (
* });
*/
async create(
nameOrSlugOrId: string | number,
nameOrSlugOrUuidOrId: string | number,
{ invitee, roleName, message }: ApplicationInviteOptions,
): Promise<ApplicationInvite> {
const [{ id }, roles] = await Promise.all([
getApplication(nameOrSlugOrId, { $select: 'id' }),
getApplication(nameOrSlugOrUuidOrId, { $select: 'id' }),
roleName
? pine.get({
resource: 'application_membership_role',
Expand Down
8 changes: 4 additions & 4 deletions lib/models/application-membership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface ApplicationMembershipCreationOptions {
const getApplicationMembershipModel = function (
deps: InjectedDependenciesParam,
getApplication: (
nameOrSlugOrId: string | number,
nameOrSlugOrUuidOrId: string | number,
options?: PineOptions<Application>,
) => Promise<Application>,
) {
Expand Down Expand Up @@ -161,7 +161,7 @@ const getApplicationMembershipModel = function (
* @description
* This method returns all application memberships for a specific application.
*
* @param {String|Number} nameOrSlugOrId - application name (string), slug (string) or id (number)
* @param {String|Number} nameOrSlugOrUuidOrId - application name (string), slug (string), uuid (string) or id (number)
* @param {Object} [options={}] - extra pine options to use
* @fulfil {Object[]} - application memberships
* @returns {Promise}
Expand All @@ -182,10 +182,10 @@ const getApplicationMembershipModel = function (
* });
*/
async getAllByApplication(
nameOrSlugOrId: number | string,
nameOrSlugOrUuidOrId: number | string,
options: PineOptions<ApplicationMembership> = {},
): Promise<ApplicationMembership[]> {
const { id } = await getApplication(nameOrSlugOrId, {
const { id } = await getApplication(nameOrSlugOrUuidOrId, {
$select: 'id',
});
return await exports.getAll(
Expand Down
Loading

0 comments on commit 4324a30

Please sign in to comment.