Skip to content

Commit

Permalink
refactor(modules): separated module responses into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Carr committed May 21, 2020
1 parent ebbcdd1 commit 3eb3b25
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 76 deletions.
18 changes: 18 additions & 0 deletions src/modules/auth/email/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Module from "../..";
import { SignUpSettingsResponse } from "./sign-up-settings";

/**
* Functions relating to Moodle's email-based self-registration.
*
* This module's function calls may throw errors if self registration is disabled.
*/
export default class AuthEmailModule extends Module {
/**
* Get the sign-up required settings and profile fields.
*/
public async getSignUpSettings(): Promise<SignUpSettingsResponse> {
return (await this.get(
"auth_email_get_signup_settings"
)) as SignUpSettingsResponse;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Module from "..";
import { FunctionResponse } from "../../functions";
import { Warning } from "../shared";
import { FunctionResponse } from "../../../functions";
import { Warning } from "../../shared";

interface ProfileField {
/**
Expand Down Expand Up @@ -191,19 +190,3 @@ export interface SignUpSettingsResponse extends FunctionResponse {

warnings?: Warning[];
}

/**
* Functions relating to Moodle's email-based self-registration.
*
* This module's function calls may throw errors if self registration is disabled.
*/
export default class AuthEmailModule extends Module {
/**
* Get the sign-up required settings and profile fields.
*/
public async getSignUpSettings(): Promise<SignUpSettingsResponse> {
return (await this.get(
"auth_email_get_signup_settings"
)) as SignUpSettingsResponse;
}
}
10 changes: 10 additions & 0 deletions src/modules/core/user/get-users-by-field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { FunctionResponse } from "../../../functions";
import { User } from "../../shared";

export interface GetUsersByFieldResponse extends FunctionResponse {
/**
* The array of users that match the provided field
* crtieria.
*/
users: User[];
}
26 changes: 26 additions & 0 deletions src/modules/core/user/get-users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { FunctionResponse } from "../../../functions";
import { User, Warning } from "../../shared";

export interface SearchCriteria {
/**
* The name of the field used to search
* for users.
*/
key: string;

/**
* The field value to match when searching
* for users.
*/
value: string | number;
}

export interface GetUsersResponse extends FunctionResponse {
/**
* The array of users that match the provided search
* crtieria.
*/
users: User[];

warnings?: Warning[];
}
39 changes: 4 additions & 35 deletions src/modules/core/user.ts → src/modules/core/user/index.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,7 @@
import Module from "..";
import { FunctionResponse } from "../../functions";
import { Warning, User } from "../shared";

interface SearchCriteria {
/**
* The name of the field used to search
* for users.
*/
key: string;

/**
* The field value to match when searching
* for users.
*/
value: string | number;
}

export interface GetUsersResponse extends FunctionResponse {
/**
* The array of users that match the provided search
* crtieria.
*/
users: User[];

warnings?: Warning[];
}

export interface GetUsersByFieldResponse extends FunctionResponse {
/**
* The array of users that match the provided field
* crtieria.
*/
users: User[];
}
import Module from "../..";
import { FunctionResponse } from "../../../functions";
import { SearchCriteria, GetUsersResponse } from "./get-users";
import { GetUsersByFieldResponse } from "./get-users-by-field";

/**
* Functions for user-related actions.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Module from "..";
import { FunctionResponse } from "../../functions";
import { FunctionResponse } from "../../../functions";

interface WebServiceFunction {
/**
Expand Down Expand Up @@ -182,19 +181,3 @@ export interface SiteInfoResponse extends FunctionResponse {
*/
theme: string;
}

/**
* Functions relating to system actions.
*/
export default class WebServiceModule extends Module {
/**
* Returns information about the Moodle site and the Web Services API.
* This function's response also contains information relating to the
* web service user, such as capabilities and authorized API actions.
*/
public async getSiteInfo(): Promise<SiteInfoResponse> {
return (await this.get(
"core_webservice_get_site_info"
)) as SiteInfoResponse;
}
}
18 changes: 18 additions & 0 deletions src/modules/core/webservice/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Module from "../..";
import { SiteInfoResponse } from "./get-site-info";

/**
* Functions relating to system actions.
*/
export default class WebServiceModule extends Module {
/**
* Returns information about the Moodle site and the Web Services API.
* This function's response also contains information relating to the
* web service user, such as capabilities and authorized API actions.
*/
public async getSiteInfo(): Promise<SiteInfoResponse> {
return (await this.get(
"core_webservice_get_site_info"
)) as SiteInfoResponse;
}
}
4 changes: 2 additions & 2 deletions src/modules/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as User } from "./user";
export { default as Warning } from "./warning";
export * from "./user";
export * from "./warning";
2 changes: 1 addition & 1 deletion src/modules/shared/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface Preference {
value: string;
}

export default interface User {
export interface User {
/**
* The unique identifier of the user.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/modules/shared/warning.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface Warning {
export interface Warning {
/**
* @todo Add documentation. Moodle's
* documentation does not provide an
Expand Down

0 comments on commit 3eb3b25

Please sign in to comment.