From dfe43c0ba4db59f414433b0ac287a848a49985e8 Mon Sep 17 00:00:00 2001 From: Luke Carr Date: Thu, 21 May 2020 19:58:08 +0100 Subject: [PATCH] feat(modules): added core_user_set_user_preferences function --- src/modules/core/user/index.ts | 17 +++++++ src/modules/core/user/set-user-preferences.ts | 46 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/modules/core/user/set-user-preferences.ts diff --git a/src/modules/core/user/index.ts b/src/modules/core/user/index.ts index fe09219..6365572 100644 --- a/src/modules/core/user/index.ts +++ b/src/modules/core/user/index.ts @@ -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"; @@ -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 { + return (await this.get("core_user_set_user_preferences", { + preferences, + })) as SetUserPreferencesResponse; + } + /** * Searches for users on the Moodle site that match * the provided crtieria. diff --git a/src/modules/core/user/set-user-preferences.ts b/src/modules/core/user/set-user-preferences.ts new file mode 100644 index 0000000..dea107c --- /dev/null +++ b/src/modules/core/user/set-user-preferences.ts @@ -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[]; +}