Services module providing access to the ResetToken database table
Example
import { resetTokens as resetTokensService } from '/src/services';
Methods
(async, static) destroyExpiredTokens()
Destroy all tokens that have expired past now.
Throws:
Will throw an error if destroyedCount is not created
Returns:
- Return the number of database rows destroyed.
Example
import { confirmEmailToken as confirmEmailTokenService } from '/src/services';
const destroyedCount = await confirmEmailTokenService.destroyExpiredTokens();
(async, static) destroyOneByPk(id) → {Number}
Destroy email confirmation token for a given primary key ID
Parameters:
| Name | Type | Description |
|---|---|---|
id |
Number | Primary key id of token to destroy. |
Throws:
-
- Will throw an error if no primary key id is passed in.
-
- Will throw an error if no destroyedCount is created.
Returns:
- Number of records destroyed or error.
- Type
- Number
Example
import { confirmEmailToken as confirmEmailTokenService } from '/src/services';
const id = 1;
const destroyedCount = await confirmEmailTokenService.destroyOneByPk(id);
(async, static) findAll(offsetopt, limitopt, whereopt)
Find and return all email confirmation tokens in the database table based on offset, limit and where.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
offset |
Number |
<optional> |
Number of pages to offset query, based on limit. |
limit |
Number |
<optional> |
Limit the number of rows the query returns. |
where |
String |
<optional> |
Filter records where. |
Throws:
- Will throw an error if foundResetTokens is not created.
Returns:
- Returns a JSON array of found tokens.
Example
import { confirmEmailToken as confirmEmailTokenService } from '/src/services';
const foundTokens = await confirmEmailTokenService.findAll();
(async, static) findOneByPk(id)
Find a reset token with a given primary key (ID)
Parameters:
| Name | Type | Description |
|---|---|---|
id |
Number | The primary key for token row. |
Throws:
-
- Will throw an error if no primary key id passed in.
-
- Will throw an error if no foundToken is created.
Returns:
- Will return the found token record.
Example
import { confirmEmailToken as confirmEmailTokenService } from '/src/services';
const id = 1;
const foundToken = await confirmEmailTokenService.findOneByPk(id);
(async, static) findOneByToken(token)
Find a token record with a given token value
Parameters:
| Name | Type | Description |
|---|---|---|
token |
String | Token string to search table. |
Throws:
-
- Will throw an error if no token string is passed in.
-
- Will throw an error if no foundToken is created.
Returns:
- Will return a JSON array of first found record.
Example
import { confirmEmailToken as confirmEmailTokenService } from '/src/services';
const token = kljkDSOIJndkfo98u34nlkndio8dfknkjdf09ujkl;
const foundToken = await confirmEmailTokenService.findOneByPk(token);
(async, static) updateOneByPk(id, updateData)
Find and update reset token record
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
id |
Number | Primary key of token to update. |
|
updateData |
Object | JSON object of token data to update. |
|
resetTokenData.UserId |
Integer |
<optional> |
Foreign key for associated user. |
resetTokenData.expiration |
Date |
<optional> |
Token expiration date. |
Throws:
-
- Will throw an error if now primary key id or token data is passed in.
-
- Will throw an error if no updatedToken is created
Returns:
- Will return a SON token object.
Example
import { confirmEmailToken as confirmEmailTokenService } from '/src/services';
const id = 1;
const data = {
UserId: 1,
expiration: 342342
}
const updatedToken = await confirmEmailTokenService.updateOneByPk(id,data);