Skip to content

web-backend


Class: CollabController

Defined in: packages/web-backend/src/collab/collab.controller.ts:33

Controller for collaboration (users) endpoints. Handles user listing, creation, validation and preferences.

Constructors

Constructor

new CollabController(collabService): CollabController

Defined in: packages/web-backend/src/collab/collab.controller.ts:39

Instantiate the collaboration controller.

Parameters

collabService

CollabService

Service providing collaboration (user) operations.

Returns

CollabController

Methods

createNewUser()

createNewUser(body): Promise<string | User>

Defined in: packages/web-backend/src/collab/collab.controller.ts:88

Create a new user in the system.

Parameters

body

CreateNewUserSchemaDto

Request body containing new user fields.

Returns

Promise<string | User>

A mongoose document of the new user

Examples

ts
Request body sample:
{
  "first_name": "Edward",
  "last_name": "Elric",
  "email": "fullmetal_alchemist@gmail.com",
  "username": "Ed",
  "password": "WinryRockbell"
}
ts
POST request: https://staging.app.openpra.org/api/collab/user/

getUserById()

getUserById(user_id): Promise<User>

Defined in: packages/web-backend/src/collab/collab.controller.ts:182

Fetch a particular user by ID.

Parameters

user_id

string

User ID of the member to find

Returns

Promise<User>

The user document when found.


getUserPreferences()

getUserPreferences(user_id): Promise<Document<unknown, { }, UserDocument, { }, { }> & User & Document<unknown, any, any, Record<string, any>, { }> & Required<{ }> & object>

Defined in: packages/web-backend/src/collab/collab.controller.ts:142

Get preferences for a user.

Parameters

user_id

string

ID of the user

Returns

Promise<Document<unknown, { }, UserDocument, { }, { }> & User & Document<unknown, any, any, Record<string, any>, { }> & Required<{ }> & object>

Preferences of the user

Example

ts
GET request: https://staging.app.openpra.org/api/collab/user/1/preferences/

getUsersList()

getUsersList(req, query): Promise<PaginationDto>

Defined in: packages/web-backend/src/collab/collab.controller.ts:53

Retrieve a paginated list of users.

Parameters

req

Request

Express request object. See https://expressjs.com/en/api.html#req.

query

Query string parameters.

limit?

number

offset?

number

role?

string

Returns

Promise<PaginationDto>

List of all users

Examples

ts
GET request: https://staging.app.openpra.org/api/collab/user/
ts
GET request with pagination: https://staging.app.openpra.org/api/collab/user/?limit=10&offset=0

isValidEmail()

isValidEmail(body): Promise<boolean>

Defined in: packages/web-backend/src/collab/collab.controller.ts:115

Check whether an email address is unique.

Parameters

body

EmailValidationForm

The request body containing the email to validate.

Returns

Promise<boolean>

True if the email is available; false otherwise.

Example

ts
Request body example: { "email": "xyz@gmail.com" }

isValidUsername()

isValidUsername(body): Promise<boolean>

Defined in: packages/web-backend/src/collab/collab.controller.ts:129

Check whether a username is unique.

Parameters

body

UsernameValidationForm

The request body containing the username to validate.

Returns

Promise<boolean>

True if the username is available; false otherwise.

Example

ts
Request body example: { "username": "sampleUsername123" }

updateUserById()

updateUserById(body): Promise<void>

Defined in: packages/web-backend/src/collab/collab.controller.ts:193

Update a user with the provided details.

Parameters

body

MemberResult

The UpdateUserDto object which contains the id of the user to be updated and the updated details

Returns

Promise<void>

Resolves when the update completes.


updateUserPreferences()

updateUserPreferences(user_id, body): Promise<Document<unknown, { }, UserDocument, { }, { }> & User & Document<unknown, any, any, Record<string, any>, { }> & Required<{ }> & object>

Defined in: packages/web-backend/src/collab/collab.controller.ts:171

Update preferences for a user.

Parameters

user_id

string

ID of the user

body

UserPreferencesDto

Request body containing the updated preferences.

Returns

Promise<Document<unknown, { }, UserDocument, { }, { }> & User & Document<unknown, any, any, Record<string, any>, { }> & Required<{ }> & object>

Updated preferences of the user

Examples

Request body sample:

json
{
  "preferences": {
    "theme": "Light",
    "nodeIdsVisible": false,
    "outlineVisible": false,
    "node_value_visible": true,
    "nodeDescriptionEnabled": true,
    "pageBreaksVisible": false
  }
}
ts
PUT request: https://staging.app.openpra.org/api/collab/user/1/preferences/