SudoSOS Back-end API / users / UserService
Class: UserService ​
Constructors ​
Constructor ​
new UserService(): UserService;Returns ​
UserService
Methods ​
acceptToS() ​
static acceptToS(userId, params): Promise<boolean>;Accept the ToS for the user with the given ID.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
userId | number | ID of the user to accept the ToS for. |
params | AcceptTosRequest | - |
Returns ​
Promise<boolean>
boolean - Whether the request has successfully been processed
addUserRole() ​
static addUserRole(user, role): Promise<AssignedRole>;Assigns a role to a user. Does not error if user does already have the role.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
user | User | User to add role to |
role | Role | Role to add |
Returns ​
Promise<AssignedRole>
areInSameOrgan() ​
static areInSameOrgan(left, right): Promise<boolean>;Function that checks if the users have overlapping member authentications.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
left | number | User to check |
right | number | User to check |
Returns ​
Promise<boolean>
closeUser() ​
static closeUser(userId, deleted?): Promise<User>;Closes a user account by setting the user's status to deleted and inactive. Also, it sets canGoIntoDebt to false.
Parameters ​
| Parameter | Type | Default value | Description |
|---|---|---|---|
userId | number | undefined | The ID of the user to close the account for. |
deleted | boolean | false | Whether the user is being deleted or not. |
Returns ​
Promise<User>
- A promise that resolves when the user account has been closed.
Throws ​
Error if the user has a non-zero balance and is being deleted.
createUser() ​
static createUser(createUserRequest): Promise<User>;Function for creating a user
Parameters ​
| Parameter | Type | Description |
|---|---|---|
createUserRequest | CreateUserRequest | The user to create |
Returns ​
Promise<User>
The created user
deleteUserRole() ​
static deleteUserRole(user, role): Promise<AssignedRole>;Removes assigned role from user. Does not error if user does not have role.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
user | User | User to remove role from |
role | Role | Role to remove |
Returns ​
Promise<AssignedRole>
getOptions() ​
static getOptions(params?): FindManyOptions<User>;Returns FindManyOptions based on the given filter parameters Note: search parameter is handled separately in getUsers() via query builder
Parameters ​
| Parameter | Type | Description |
|---|---|---|
params | UserFilterParameters | The filter params to apply |
Returns ​
FindManyOptions<User>
getRelations() ​
static getRelations<T>(options?): FindOptionsRelations<T>;Returns FindOptionsRelations for loading user with nested relations When base is empty string, returns direct User relations When base is provided (default: 'user'), wraps user relations in that relation name
Type Parameters ​
| Type Parameter | Default type |
|---|---|
T | any |
Parameters ​
| Parameter | Type | Description |
|---|---|---|
options | { base?: string; pos?: boolean; } | Options object |
options.base? | string | Base relation name (default: 'user', empty string for direct User relations) |
options.pos? | boolean | Whether to include pointOfSale relation (default: false) |
Returns ​
FindOptionsRelations<T>
FindOptionsRelations for the specified entity type
getSingleUser() ​
static getSingleUser(id): Promise<User>;Function for getting a single user based on ID
Parameters ​
| Parameter | Type | Description |
|---|---|---|
id | number | ID of the user to return |
Returns ​
Promise<User>
User if exists
getUserFinancialMutations() ​
static getUserFinancialMutations(
user,
filters?,
paginationParameters?): Promise<PaginatedFinancialMutationResponse>;Combined query to return a users transfers and transactions from the database
Parameters ​
| Parameter | Type | Description |
|---|---|---|
user | User | The user of which to get. |
filters | FinancialMutationsFilterParams | Filter parameters to adhere to |
paginationParameters | PaginationParameters | Pagination Parameters to adhere to. |
Returns ​
Promise<PaginatedFinancialMutationResponse>
getUsers() ​
static getUsers(filters?, pagination?): Promise<[User[], number]>;Function for getting all Users
Parameters ​
| Parameter | Type | Description |
|---|---|---|
filters | UserFilterParameters | Query filters to apply |
pagination | PaginationParameters | Pagination to adhere to |
Returns ​
Promise<[User[], number]>
updateUser() ​
static updateUser(userId, updateUserRequest): Promise<User>;Updates the user object with the new properties.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
userId | number | ID of the user to update. |
updateUserRequest | UpdateUserRequest | The update object. |
Returns ​
Promise<User>
updateUserType() ​
static updateUserType(user, toType): Promise<void>;Parameters ​
| Parameter | Type |
|---|---|
user | User |
toType | UserType |
Returns ​
Promise<void>