Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import FormData from 'form-data';
import OAuth from './api/oauth.js';
import Locate from './api/locate.js';
import Package from './api/package.js';
import Query from './api/query.js';
import Mission from './api/mission.js';
Expand All @@ -21,6 +22,7 @@ export const CommandList: Record<string, keyof TAKAPI> = {
package: 'Package',
oauth: 'OAuth',
mission: 'Mission',
locate: 'Locate',
'mission-log': 'MissionLog',
'mission-layer': 'MissionLayer',
credential: 'Credentials',
Expand Down Expand Up @@ -53,6 +55,7 @@ export default class TAKAPI {
Injectors: Injectors;
Repeater: Repeater;
Group: Group;
Locate: Locate;
Video: Video;
Export: Export;
Query: Query;
Expand All @@ -72,6 +75,7 @@ export default class TAKAPI {
this.Credentials = new Credentials(this);
this.Contacts = new Contacts(this);
this.Subscription = new Subscription(this);
this.Locate = new Locate(this);
this.Group = new Group(this);
this.Video = new Video(this);
this.Injectors = new Injectors(this);
Expand Down
46 changes: 45 additions & 1 deletion lib/api/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,27 @@ export const GroupListInput = Type.Object({
useCache: Type.Optional(Type.Boolean())
})

export const MemberListInput = Type.Object({
groupNameFilter: Type.String()
})

export const TAKList_Group = TAKList(Group);
export const TAKList_Member = TAKList(Group);

export default class GroupCommands extends Commands {
schema = {
list: {
description: 'List Missions',
description: 'List Groups',
params: Type.Object({}),
query: Type.Object({}),
formats: [ CommandOutputFormat.JSON ]
},

'list-members': {
description: 'List Members',
params: Type.Object({}),
query: Type.Object(MemberListInput),
formats: [ CommandOutputFormat.JSON ]
}
}

Expand All @@ -40,6 +52,19 @@ export default class GroupCommands extends Commands {
return `${channel.name} - ${channel.description}`;
}).join('\n');
}
} else if (args._[3] === 'list-members') {
const list = await this.members({
groupNameFilter: args.groupNameFilter || ''
});

if (args.format === 'json') {
return list;
} else {
return list.data.map((member) => {
console.error(member);
return `${channel.name} - ${channel.description}`;
}).join('\n');
}
} else {
throw new Error('Unsupported Subcommand');
}
Expand Down Expand Up @@ -80,4 +105,23 @@ export default class GroupCommands extends Commands {
body
});
}

async members(
query: Static<typeof MemberListInput> = {}
): Promise<Static<typeof TAKList_Member>> {
const url = new URL(`/Marti/api/groups/members`, this.api.url);

let q: keyof Static<typeof MemberListInput>;
for (q in query) {
if (query[q] !== undefined) {
url.searchParams.append(q, String(query[q]));
}
}

console.error(url);

return await this.api.fetch(url, {
method: 'GET'
});
}
}