MOBILE-3594 core: Add group ws params and rename response types

main
Pau Ferrer Ocaña 2020-11-19 12:05:39 +01:00
parent bb0881f7e9
commit 7ae3c9c3dc
1 changed files with 36 additions and 12 deletions

View File

@ -66,12 +66,12 @@ export class CoreGroupsProvider {
userId?: number, userId?: number,
siteId?: string, siteId?: string,
ignoreCache?: boolean, ignoreCache?: boolean,
): Promise<CoreGroupGetActivityAllowedGroupsResponse> { ): Promise<CoreGroupGetActivityAllowedGroupsWSResponse> {
const site = await CoreSites.instance.getSite(siteId); const site = await CoreSites.instance.getSite(siteId);
userId = userId || site.getUserId(); userId = userId || site.getUserId();
const params = { const params: CoreGroupGetActivityAllowedGroupsWSParams = {
cmid: cmId, cmid: cmId,
userid: userId, userid: userId,
}; };
@ -85,7 +85,7 @@ export class CoreGroupsProvider {
preSets.emergencyCache = false; preSets.emergencyCache = false;
} }
const response: CoreGroupGetActivityAllowedGroupsResponse = const response: CoreGroupGetActivityAllowedGroupsWSResponse =
await site.read('core_group_get_activity_allowed_groups', params, preSets); await site.read('core_group_get_activity_allowed_groups', params, preSets);
if (!response || !response.groups) { if (!response || !response.groups) {
@ -116,7 +116,7 @@ export class CoreGroupsProvider {
* @return Promise resolved when the groups are retrieved. If not allowed, empty array will be returned. * @return Promise resolved when the groups are retrieved. If not allowed, empty array will be returned.
*/ */
async getActivityAllowedGroupsIfEnabled(cmId: number, userId?: number, siteId?: string, ignoreCache?: boolean): async getActivityAllowedGroupsIfEnabled(cmId: number, userId?: number, siteId?: string, ignoreCache?: boolean):
Promise<CoreGroupGetActivityAllowedGroupsResponse> { Promise<CoreGroupGetActivityAllowedGroupsWSResponse> {
siteId = siteId || CoreSites.instance.getCurrentSiteId(); siteId = siteId || CoreSites.instance.getCurrentSiteId();
// Get real groupmode, in case it's forced by the course. // Get real groupmode, in case it's forced by the course.
@ -158,7 +158,7 @@ export class CoreGroupsProvider {
groupInfo.separateGroups = groupMode === CoreGroupsProvider.SEPARATEGROUPS; groupInfo.separateGroups = groupMode === CoreGroupsProvider.SEPARATEGROUPS;
groupInfo.visibleGroups = groupMode === CoreGroupsProvider.VISIBLEGROUPS; groupInfo.visibleGroups = groupMode === CoreGroupsProvider.VISIBLEGROUPS;
let result: CoreGroupGetActivityAllowedGroupsResponse; let result: CoreGroupGetActivityAllowedGroupsWSResponse;
if (groupInfo.separateGroups || groupInfo.visibleGroups) { if (groupInfo.separateGroups || groupInfo.visibleGroups) {
result = await this.getActivityAllowedGroups(cmId, userId, siteId, ignoreCache); result = await this.getActivityAllowedGroups(cmId, userId, siteId, ignoreCache);
} else { } else {
@ -196,7 +196,7 @@ export class CoreGroupsProvider {
*/ */
async getActivityGroupMode(cmId: number, siteId?: string, ignoreCache?: boolean): Promise<number> { async getActivityGroupMode(cmId: number, siteId?: string, ignoreCache?: boolean): Promise<number> {
const site = await CoreSites.instance.getSite(siteId); const site = await CoreSites.instance.getSite(siteId);
const params = { const params: CoreGroupGetActivityGroupmodeWSParams = {
cmid: cmId, cmid: cmId,
}; };
const preSets: CoreSiteWSPreSets = { const preSets: CoreSiteWSPreSets = {
@ -209,7 +209,7 @@ export class CoreGroupsProvider {
preSets.emergencyCache = false; preSets.emergencyCache = false;
} }
const response: CoreGroupGetActivityGroupModeResponse = const response: CoreGroupGetActivityGroupModeWSResponse =
await site.read('core_group_get_activity_groupmode', params, preSets); await site.read('core_group_get_activity_groupmode', params, preSets);
if (!response || typeof response.groupmode == 'undefined') { if (!response || typeof response.groupmode == 'undefined') {
@ -275,7 +275,7 @@ export class CoreGroupsProvider {
async getUserGroupsInCourse(courseId: number, siteId?: string, userId?: number): Promise<CoreGroup[]> { async getUserGroupsInCourse(courseId: number, siteId?: string, userId?: number): Promise<CoreGroup[]> {
const site = await CoreSites.instance.getSite(siteId); const site = await CoreSites.instance.getSite(siteId);
userId = userId || site.getUserId(); userId = userId || site.getUserId();
const data = { const data: CoreGroupGetCourseUserGroupsWSParams = {
userid: userId, userid: userId,
courseid: courseId, courseid: courseId,
}; };
@ -284,7 +284,7 @@ export class CoreGroupsProvider {
updateFrequency: CoreSite.FREQUENCY_RARELY, updateFrequency: CoreSite.FREQUENCY_RARELY,
}; };
const response: CoreGroupGetCourseUserGroupsResponse = const response: CoreGroupGetCourseUserGroupsWSResponse =
await site.read('core_group_get_course_user_groups', data, preSets); await site.read('core_group_get_course_user_groups', data, preSets);
if (!response || !response.groups) { if (!response || !response.groups) {
@ -475,24 +475,48 @@ export type CoreGroupInfo = {
/** /**
* WS core_group_get_activity_allowed_groups response type. * WS core_group_get_activity_allowed_groups response type.
*/ */
export type CoreGroupGetActivityAllowedGroupsResponse = { export type CoreGroupGetActivityAllowedGroupsWSResponse = {
groups: CoreGroup[]; // List of groups. groups: CoreGroup[]; // List of groups.
canaccessallgroups?: boolean; // Whether the user will be able to access all the activity groups. canaccessallgroups?: boolean; // Whether the user will be able to access all the activity groups.
warnings?: CoreWSExternalWarning[]; warnings?: CoreWSExternalWarning[];
}; };
/**
* Params of core_group_get_activity_groupmode WS.
*/
type CoreGroupGetActivityGroupmodeWSParams = {
cmid: number; // Course module id.
};
/** /**
* Result of WS core_group_get_activity_groupmode. * Result of WS core_group_get_activity_groupmode.
*/ */
export type CoreGroupGetActivityGroupModeResponse = { export type CoreGroupGetActivityGroupModeWSResponse = {
groupmode: number; // Group mode: 0 for no groups, 1 for separate groups, 2 for visible groups. groupmode: number; // Group mode: 0 for no groups, 1 for separate groups, 2 for visible groups.
warnings?: CoreWSExternalWarning[]; warnings?: CoreWSExternalWarning[];
}; };
/**
* Params of core_group_get_activity_allowed_groups WS.
*/
type CoreGroupGetActivityAllowedGroupsWSParams = {
cmid: number; // Course module id.
userid?: number; // Id of user, empty for current user.
};
/**
* Params of core_group_get_course_user_groups WS.
*/
type CoreGroupGetCourseUserGroupsWSParams = {
courseid?: number; // Id of course (empty or 0 for all the courses where the user is enrolled).
userid?: number; // Id of user (empty or 0 for current user).
groupingid?: number; // Returns only groups in the specified grouping.
};
/** /**
* Result of WS core_group_get_course_user_groups. * Result of WS core_group_get_course_user_groups.
*/ */
export type CoreGroupGetCourseUserGroupsResponse = { export type CoreGroupGetCourseUserGroupsWSResponse = {
groups: { groups: {
id: number; // Group record id. id: number; // Group record id.
name: string; // Multilang compatible name, course unique. name: string; // Multilang compatible name, course unique.