Services module providing access to the Things database table
- Source:
Example
import { things as thingsService } from '/src/services';
Methods
(async, static) createOne(thingData) → {Object}
Create a thing in the database
Parameters:
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
thingData |
Object | Thing object data to create Properties
|
- Source:
Throws:
-
Will throw an error if there is no thingData to create with
-
Will throw an error if a create thing instance is not created
Returns:
A created thing instance
- Type
- Object
Example
import { things as thingsService } from 'src/services';
const thingData = {
name: 'A new thing name',
description: 'A description of the new thing is awesome',
price: 99.99,
};
const createdThing = await thingsService.createOne(thingData);
(async, static) destroyAll() → {Int}
Destroy all things in the database
Throws:
Will throw an error if no destroy count is created
Returns:
A count of the thing rows destroyed
- Type
- Int
Example
import { things as thingsService } from '/src/services'
const count = await thingsService.destroyAll()
(async, static) destroyOneByPk(id) → {Int}
Destroy a thing with the primary key id in the database table
Parameters:
| Name | Type | Description |
|---|---|---|
id |
Int | Primary key id of thing to destroy |
Throws:
-
Will throw an error if no id is passed in
-
Will throw an error if a thing count is not created
Returns:
Number of things deleted
- Type
- Int
Example
import { things as thingsService } from '/src/services'
const id = 1;
const count = await thingsService.destroyOneByPk(id)
(async, static) findAll(offsetopt, limitopt, whereopt) → {Array}
Find and return all things in the database table
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
offset |
Int |
<optional> |
Number of limit pages to offset the query |
limit |
Int |
<optional> |
Limit of query length |
where |
String |
<optional> |
Filter the query by where |
Throws:
Throws error if found things instance isn't created
Returns:
A JSON array of found things
- Type
- Array
Example
import { things as thingsService } from '/src/services';
const allThings = await thingsService.findAll();
(async, static) findAndCountAll(offsetopt, limitopt, whereopt) → {Object}
Find and return all things in database table with a count
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
offset |
Int |
<optional> |
Number of limit pages to offset the query |
limit |
Int |
<optional> |
Limit of query length |
where |
String |
<optional> |
Filter the query by where |
Throws:
Throws error if findAndCountAll is not returned
Returns:
A count of things found and a JSON array of found things
- Type
- Object
Example
import { things as thingsService } from '/src/services'
const { count, rows } = await thingsService.findAndCount();
(async, static) findOneByPk(id) → {Object}
Find and return a thing with primary key id in database table
Parameters:
| Name | Type | Description |
|---|---|---|
id |
Int | Primary key id of thing to find |
Throws:
-
Will throw an error if no user id is passed in
-
Will throw an error if thing instance is not returned
Returns:
A found thing instance
- Type
- Object
Example
import { things as thingsService } from '/src/services';
const id = 1;
const thing = await thingsService.findOneByPk(id);
(async, static) updateOneByPk(id, updatedThingData) → {Object}
Update and return thing with id in database table
Parameters:
| Name | Type | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
Int | The primary key id to update. |
||||||||||||||||
updatedThingData |
Object | The thing data to update. Properties
|
- Source:
Throws:
Will throw an error if no id and/or data passed in.
Returns:
Updated thing instance.
- Type
- Object
Example
import { resetTokens as resetTokensService } from 'src/services';
const id = 1;
const data = { isUsed: false };
const updatedResetToken = await resetTokensService.updateOneByPk(id, data)