Skip to content

Commit

Permalink
feat(modules): added core_user_set_user_preferences function
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Carr committed May 21, 2020
1 parent d4fb49f commit dfe43c0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/modules/core/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {
} from "./get-course-user-profiles";
import { GetPrivateFilesInfoResponse } from "./get-private-files-info";
import { GetUserPreferencesResponse } from "./get-user-preferences";
import {
NewPreference,
SetUserPreferencesResponse,
} from "./set-user-preferences";
import { SearchCriteria, GetUsersResponse } from "./get-users";
import { GetUsersByFieldResponse } from "./get-users-by-field";

Expand Down Expand Up @@ -124,6 +128,19 @@ export default class UserModule extends Module {
})) as GetUserPreferencesResponse;
}

/**
* Sets user preferences for Moodle users.
*
* @param preferences The preferences to set.
*/
public async setUserPreferences(
...preferences: NewPreference[]
): Promise<SetUserPreferencesResponse> {
return (await this.get("core_user_set_user_preferences", {
preferences,
})) as SetUserPreferencesResponse;
}

/**
* Searches for users on the Moodle site that match
* the provided crtieria.
Expand Down
46 changes: 46 additions & 0 deletions src/modules/core/user/set-user-preferences.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { FunctionResponse } from "../../../functions";
import { Warning } from "../../shared";

export interface NewPreference {
/**
* The name of the preference
* to set.
*/
name: string;

/**
* The preference's new value.
*/
value: string;

/**
* The ID of the user to set
* the preference of.
*/
userid: number;
}

interface SavedPreference {
/**
* The name of the saved
* preference.
*/
name: string;

/**
* The ID of the user who the
* preference was set for.
*/
userid: number;
}

export interface SetUserPreferencesResponse extends FunctionResponse {
/**
* The preferences that were
* saved as a result of this
* function call.
*/
saved: SavedPreference[];

warnings: Warning[];
}

0 comments on commit dfe43c0

Please sign in to comment.