Skip to main content

Class: Otp

Defined in: models/otp.ts:30

The OTP class handles all the methods/properties of the OTP

Extends

Constructors

Constructor

new Otp(props): Otp

Defined in: models/otp.ts:35

Parameters

props

OtpProps

Returns

Otp

Overrides

Model.constructor

Properties

attributes

attributes: OtpProps = {}

Defined in: models/model.ts:34

Inherited from

Model.attributes


emailAddress?

optional emailAddress: string

Defined in: models/otp.ts:32


otp?

optional otp: string

Defined in: models/otp.ts:33


uuid

uuid: string

Defined in: models/model.ts:35

Inherited from

Model.uuid


id

static id: string = 'otp'

Defined in: models/otp.ts:31

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

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


deleteRecord()

deleteRecord(data): Promise<boolean>

Defined in: models/otp.ts:84

Deletes an OTP. In the application, used once an OTP has been validated.

Parameters

data

IKeyValue

The record data needed to be deleted

Returns

Promise<boolean>


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


hashOtp()

hashOtp(otp, salt): Promise<any>

Defined in: models/otp.ts:52

Parameters

otp

string = ...

The OTP that is getting hashed

salt

string = ''

The salt that is usd for hashing the OTP. If none provided, a new salt will be generated. Hashes an OTP using a provided or generated salt string.

Returns

Promise<any>

A new hash object is returned

    hash: string,
salt: string
}```

***

### save()

> **save**(): `Promise`\<`boolean`\>

Defined in: [models/model.ts:206](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/model.ts#L206)

Save a record in DB

#### Returns

`Promise`\<`boolean`\>

true if the record was saved in the DB

#### Inherited from

[`Model`](Model.md).[`save`](Model.md#save)

***

### saveOtp()

> **saveOtp**(`props`): `Promise`\<`boolean`\>

Defined in: [models/otp.ts:125](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/otp.ts#L125)

Saves an OTP into a new container for storing the OTPs.
Will also override OTPs that have been previously stored by same user.

#### Parameters

##### props

The object used to save the OTP record

###### hash

`string`

The hashed OTP

###### salt

`string`

The OTP SALT that was used to generate the OTP

#### Returns

`Promise`\<`boolean`\>

A boolean indicating if the record was saved or not

***

### serialize()

> **serialize**(): `IKeyValue`

Defined in: [models/model.ts:285](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/model.ts#L285)

Create a response safe representation of the model's attributes
Should normally be overridden in subclasses

#### Returns

`IKeyValue`

The attribute properties from the model + the uuid.

#### Inherited from

[`Model`](Model.md).[`serialize`](Model.md#serialize)

***

### set()

> **set**(`name`, `value`): `void`

Defined in: [models/model.ts:276](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/model.ts#L276)

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`](Model.md).[`set`](Model.md#set)

***

### update()

> **update**(`attrs`): `Promise`\<`boolean`\>

Defined in: [models/model.ts:231](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/model.ts#L231)

#### Parameters

##### attrs

[`ModelProps`](../type-aliases/ModelProps.md)

The attributes provided to update the record.

#### Returns

`Promise`\<`boolean`\>

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

#### Inherited from

[`Model`](Model.md).[`update`](Model.md#update)

***

### validateOtp()

> **validateOtp**(`otp`): `Promise`\<`boolean`\>

Defined in: [models/otp.ts:157](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/otp.ts#L157)

Validates an OTP provided by the user with `this.otp` value. It will use the same
SALT value to assess if the OTP values match.

#### Parameters

##### otp

`string`

An OTP provided by the user

#### Returns

`Promise`\<`boolean`\>

`true` if the OTP is valid, `false` if the OTP is not valid.

***

### checkValidWindow()

> `static` **checkValidWindow**(`token`): `boolean`

Defined in: [models/otp.ts:145](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/otp.ts#L145)

This method checks if the OTP is within the valid 15 minute timeframe.

#### Parameters

##### token

`string`

The OTP token

#### Returns

`boolean`

`true` if the OTP is within 15 minutes, `false` if outside that window.

***

### create()

> `static` **create**(`attrs`): `Promise`\<`any`\>

Defined in: [models/model.ts:58](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/model.ts#L58)

Creates a new model & save the record

#### Parameters

##### attrs

[`ModelProps`](../type-aliases/ModelProps.md)

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`](Model.md).[`create`](Model.md#create)

***

### find()

> `static` **find**(`uuid`): `Promise`\<`any`\>

Defined in: [models/model.ts:88](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/model.ts#L88)

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`](Model.md).[`find`](Model.md#find)

***

### findAll()

> `static` **findAll**(): `Promise`\<`any`[]\>

Defined in: [models/model.ts:134](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/model.ts#L134)

Load all records by type

#### Returns

`Promise`\<`any`[]\>

A list of all records that match a particular model id

#### Inherited from

[`Model`](Model.md).[`findAll`](Model.md#findall)

***

### findAllBy()

> `static` **findAllBy**(`params`): `Promise`\<`any`\>

Defined in: [models/model.ts:125](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/model.ts#L125)

Alias for query

#### Parameters

##### params

[`QueryProps`](../type-aliases/QueryProps.md)

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`](Model.md).[`findAllBy`](Model.md#findallby)

***

### findBy()

> `static` **findBy**(`params`): `Promise`\<`any`\>

Defined in: [models/model.ts:107](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/model.ts#L107)

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

#### Parameters

##### params

[`QueryProps`](../type-aliases/QueryProps.md)

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`](Model.md).[`findBy`](Model.md#findby)

***

### findOrCreate()

> `static` **findOrCreate**(`attrs`): `Promise`\<`any`\>

Defined in: [models/model.ts:154](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/model.ts#L154)

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

#### Parameters

##### attrs

[`ModelProps`](../type-aliases/ModelProps.md)

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`](Model.md).[`findOrCreate`](Model.md#findorcreate)

***

### findOrCreateBy()

> `static` **findOrCreateBy**(`attrs`): `Promise`\<`any`\>

Defined in: [models/model.ts:171](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/model.ts#L171)

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`](Model.md).[`findOrCreateBy`](Model.md#findorcreateby)

***

### findOtp()

> `static` **findOtp**(`props`): `Promise`\<`Otp`\>

Defined in: [models/otp.ts:95](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/otp.ts#L95)

Finds an OTP based on the provided properties.
In the application, will use "emailAddress"

#### Parameters

##### props

`IKeyValue`

The properties used to find the OTP record. In the app, the emailAddress typically.

#### Returns

`Promise`\<`Otp`\>

A new OTP class is returned

***

### generateOtp()

> `static` **generateOtp**(): `string`

Defined in: [models/otp.ts:111](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/otp.ts#L111)

Generates an OTP

#### Returns

`string`

An OTP with 8 digits.

***

### query()

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

Defined in: [models/model.ts:190](https://github.com/turnaroundfactor/adapt_media_presence/blob/bf7905deb8d25d5572726c3a773c930529b55114/src/models/model.ts#L190)

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`](Model.md).[`query`](Model.md#query)