Skip to content

SudoSOS Back-end API / users / UserService

Class: UserService ​

Constructors ​

Constructor ​

ts
new UserService(): UserService;

Returns ​

UserService

Methods ​

acceptToS() ​

ts
static acceptToS(userId, params): Promise<boolean>;

Accept the ToS for the user with the given ID.

Parameters ​

ParameterTypeDescription
userIdnumberID of the user to accept the ToS for.
paramsAcceptTosRequest-

Returns ​

Promise<boolean>

boolean - Whether the request has successfully been processed


addUserRole() ​

ts
static addUserRole(user, role): Promise<AssignedRole>;

Assigns a role to a user. Does not error if user does already have the role.

Parameters ​

ParameterTypeDescription
userUserUser to add role to
roleRoleRole to add

Returns ​

Promise<AssignedRole>


areInSameOrgan() ​

ts
static areInSameOrgan(left, right): Promise<boolean>;

Function that checks if the users have overlapping member authentications.

Parameters ​

ParameterTypeDescription
leftnumberUser to check
rightnumberUser to check

Returns ​

Promise<boolean>


closeUser() ​

ts
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 ​

ParameterTypeDefault valueDescription
userIdnumberundefinedThe ID of the user to close the account for.
deletedbooleanfalseWhether 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() ​

ts
static createUser(createUserRequest): Promise<User>;

Function for creating a user

Parameters ​

ParameterTypeDescription
createUserRequestCreateUserRequestThe user to create

Returns ​

Promise<User>

The created user


deleteUserRole() ​

ts
static deleteUserRole(user, role): Promise<AssignedRole>;

Removes assigned role from user. Does not error if user does not have role.

Parameters ​

ParameterTypeDescription
userUserUser to remove role from
roleRoleRole to remove

Returns ​

Promise<AssignedRole>


getOptions() ​

ts
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 ​

ParameterTypeDescription
paramsUserFilterParametersThe filter params to apply

Returns ​

FindManyOptions<User>


getRelations() ​

ts
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 ParameterDefault type
Tany

Parameters ​

ParameterTypeDescription
options{ base?: string; pos?: boolean; }Options object
options.base?stringBase relation name (default: 'user', empty string for direct User relations)
options.pos?booleanWhether to include pointOfSale relation (default: false)

Returns ​

FindOptionsRelations<T>

FindOptionsRelations for the specified entity type


getSingleUser() ​

ts
static getSingleUser(id): Promise<User>;

Function for getting a single user based on ID

Parameters ​

ParameterTypeDescription
idnumberID of the user to return

Returns ​

Promise<User>

User if exists


getUserFinancialMutations() ​

ts
static getUserFinancialMutations(
   user, 
   filters?, 
paginationParameters?): Promise<PaginatedFinancialMutationResponse>;

Combined query to return a users transfers and transactions from the database

Parameters ​

ParameterTypeDescription
userUserThe user of which to get.
filtersFinancialMutationsFilterParamsFilter parameters to adhere to
paginationParametersPaginationParametersPagination Parameters to adhere to.

Returns ​

Promise<PaginatedFinancialMutationResponse>


getUsers() ​

ts
static getUsers(filters?, pagination?): Promise<[User[], number]>;

Function for getting all Users

Parameters ​

ParameterTypeDescription
filtersUserFilterParametersQuery filters to apply
paginationPaginationParametersPagination to adhere to

Returns ​

Promise<[User[], number]>


updateUser() ​

ts
static updateUser(userId, updateUserRequest): Promise<User>;

Updates the user object with the new properties.

Parameters ​

ParameterTypeDescription
userIdnumberID of the user to update.
updateUserRequestUpdateUserRequestThe update object.

Returns ​

Promise<User>


updateUserType() ​

ts
static updateUserType(user, toType): Promise<void>;

Parameters ​

ParameterType
userUser
toTypeUserType

Returns ​

Promise<void>