Skip to main content

Class: User

Defined in: models/user.ts:64

User class contains information and methods needed to get, create, update, and delete a User in cosmos.

Extends

Constructors

Constructor

new User(props): User

Defined in: models/user.ts:70

Parameters

props

UserProps

Returns

User

Overrides

Model.constructor

Properties

attributes

attributes: UserProps = {}

Defined in: models/model.ts:34

Inherited from

Model.attributes


name?

optional name: string

Defined in: models/user.ts:66


socketId?

optional socketId: string

Defined in: models/user.ts:67


uid?

optional uid: string

Defined in: models/user.ts:68


uuid

uuid: string

Defined in: models/model.ts:35

Inherited from

Model.uuid


id

static id: string = 'member'

Defined in: models/user.ts:65

Overrides

Model.id

Accessors

id

Get Signature

get id(): string

Defined in: models/model.ts:249

Gets the ID

Returns

string

The ID property. Options include: "room" | "user" | "userRoom" | "invite" | "otp"

Inherited from

Model.id


isNew

Get Signature

get isNew(): boolean

Defined in: models/model.ts:258

Checks if model is new

Returns

boolean

Returns boolean if uuid is missing from record

Inherited from

Model.isNew

Methods

addToRoom()

addToRoom(uuid): Promise<boolean>

Defined in: models/user.ts:82

Adds a user to a room by updating their room property.

Parameters

uuid

string

The UUID of the room a user is joining.

Returns

Promise<boolean>

A boolean indicating if a user's record has been updated with the new room information.


delete()

delete(): Promise<boolean>

Defined in: models/model.ts:78

Deletes a record

Returns

Promise<boolean>

a boolean: true if the record was deleted, false if it was not deleted

Inherited from

Model.delete


get()

get(name): any

Defined in: models/model.ts:267

Gets an attribute's value

Parameters

name

Name of the attribute that is being retrieved

string | number

Returns

any

The attribute value being retrieved

Inherited from

Model.get


isApprovedForRoom()

isApprovedForRoom(roomId): Promise<boolean>

Defined in: models/user.ts:112

Checks if a user is approved for a room. This method queries the DB for an existing UserRoom record. If the user is of type 'Tool`, then it will automatically be truthy.

Parameters

roomId

string

The roomID used to query for whether a user is approved for that room.

Returns

Promise<boolean>

A boolean indicating if a user has been approved for the room, else it will return false.


isPreApprovedForRoom()

isPreApprovedForRoom(roomId): Promise<boolean>

Defined in: models/user.ts:127

Uses a room UUID to check if a user has an existing invitation for a room. If an invitation exists, the user is approved for a room and the invite is deleted. In the application, this is typically called in the roomRequest event.

Parameters

roomId

string

The room UUID to search for an invitation.

Returns

Promise<boolean>

A boolean. If there is no invitation, it returns false. If there is & the invite was deleted, it returns true.


kickFromRoom()

kickFromRoom(): Promise<boolean>

Defined in: models/user.ts:150

Kicks a user from a room. This method also removes a user's UserRoom record.

Returns

Promise<boolean>

true if a user was successfully removed/kicked from a room.


removeFromRoom()

removeFromRoom(): Promise<boolean>

Defined in: models/user.ts:170

Remove a user from a room by changing their room property to null

Returns

Promise<boolean>

true if a user record was updated to show that they were removed from the room.


roomIds()

roomIds(): Promise<string[]>

Defined in: models/user.ts:179

Fetches a list of room UUIDs that a user has been previously approved for. This method is often used in conjunction with getting a list of rooms.

Returns

Promise<string[]>

A list of room UUIDs if a user has existing room approvals, or an empty array if none.


save()

save(): Promise<boolean>

Defined in: models/model.ts:206

Save a record in DB

Returns

Promise<boolean>

true if the record was saved in the DB

Inherited from

Model.save


serialize()

serialize(): IKeyValue

Defined in: models/user.ts:195

Serializes the user data for the front end user.

Returns

IKeyValue

An object with specific user properties such as: uuid, name, device, type, created, modified, method, room, and parentUuid. The uid is not provided.

Overrides

Model.serialize


set()

set(name, value): void

Defined in: models/model.ts:276

Sets an attribute value

Parameters

name

Key of the attribute's value being set

string | number

value

any

Value of the attribute being set

Returns

void

Inherited from

Model.set


update()

update(attrs): Promise<boolean>

Defined in: models/model.ts:231

Parameters

attrs

ModelProps

The attributes provided to update the record.

Returns

Promise<boolean>

a boolean: True if successfully updated | False if not updated

Inherited from

Model.update


create()

static create(attrs): Promise<any>

Defined in: models/model.ts:58

Creates a new model & save the record

Parameters

attrs

ModelProps

The attributes passing to the model.

Returns

Promise<any>

either the saved model or null, if the model could not be saved.

Inherited from

Model.create


find()

static find(uuid): Promise<any>

Defined in: models/model.ts:88

Finds a record

Parameters

uuid

string

The unique ID of the record being found

Returns

Promise<any>

a new instance of the found record

Inherited from

Model.find


findAll()

static findAll(): Promise<any[]>

Defined in: models/model.ts:134

Load all records by type

Returns

Promise<any[]>

A list of all records that match a particular model id

Inherited from

Model.findAll


findAllBy()

static findAllBy(params): Promise<any>

Defined in: models/model.ts:125

Alias for query

Parameters

params

QueryProps

The query properties used to filter & find a record

Returns

Promise<any>

A list of found records that match the params, may be an empty []

Inherited from

Model.findAllBy


findBy()

static findBy(params): Promise<any>

Defined in: models/model.ts:107

Finds a single record based on props (essentially limits query to a single result)

Parameters

params

QueryProps

The query properties used to filter & find a record

Returns

Promise<any>

null if no record found, or a new instance of the record

Inherited from

Model.findBy


findOldUserRecords()

static findOldUserRecords(): Promise<any[]>

Defined in: models/user.ts:93

Finds all the old user records

Returns

Promise<any[]>

an array of User records


findOrCreate()

static findOrCreate(attrs): Promise<any>

Defined in: models/model.ts:154

Finds a record by given UUID, if it doesn't exist, creates a new record instead

Parameters

attrs

ModelProps

The attributes provided to query the record. Only UUID will be used

Returns

Promise<any>

Either the existing record or newly created one

Inherited from

Model.findOrCreate


findOrCreateBy()

static findOrCreateBy(attrs): Promise<any>

Defined in: models/model.ts:171

Finds a record by a query, if it doesn't exist, creates a new record instead

Parameters

attrs

IKeyValue

The attributes provided to query the record.

Returns

Promise<any>

Either the existing record or newly created one

Inherited from

Model.findOrCreateBy


query()

static query(params): Promise<any[]>

Defined in: models/model.ts:190

Query for resources using an object of properties/filters

Parameters

params

IKeyValue

The attributes provided to query the record.

Returns

Promise<any[]>

An array of the found records (created as new instances of model)

Inherited from

Model.query