Users services module providing access to the User database table.
- Source:
Example
import { users as usersService } from '/src/services';
Methods
(async, static) createOne(userData) → {Object}
Create one user in the database table
Parameters:
| Name | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
userData |
Object | User data object used to create. Properties
|
- Source:
Throws:
-
Will throw an error if there is no userData to create with.
-
Will throw an error if a createdUser instance is not created
Returns:
A created user instance.
- Type
- Object
Example
import { users as usersService } from 'src/services';
const userDate = {
firstName: 'Jane',
lastName: 'Doe',
email: 'jane.doe@hotmail.com',
password: 'password123',
};
const createdUser = await usersService.createOne(userDate);
(async, static) destroyByPk(id) → {Int}
Delete user with primary key id in the database table and return number of rows deleted
Parameters:
| Name | Type | Description |
|---|---|---|
id |
Int | Primary key id from database table to destroy |
- Source:
Throws:
-
Will throw an error if no id is passed in
-
Will throw an error if a destroyedUserCount is not created
Returns:
Number of users deleted
- Type
- Int
Example
import { users as usersService } from '/src/services'
const id = 1;
const count = await usersService.destroyOneByPk(id)
(async, static) findAll(id) → {Object}
Find and return all USERS in the database table
Parameters:
| Name | Type | Description |
|---|---|---|
id |
Int | Primary key id of user to find |
Throws:
Throws error if foundUsers array isn't created
Returns:
A found user instance
- Type
- Object
Example
import { users as usersService } from '/src/services';
const foundUsers = await usersService.findAll();
(async, static) findAndCountAll(offsetopt, limitopt, whereopt) → {Object}
Find and return all users 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 and error if findAndCountAll is not returned
Returns:
A count of users found and a JSON array of found things
- Type
- Object
Example
import { users as usersService } from '/src/services'
const { count, rows } = await usersService.findAndCount();
(async, static) findOneByEmail(email) → {Object}
Find and return user instance for a given email address.
Parameters:
| Name | Type | Description |
|---|---|---|
email |
String | Email address of user to find. |
- Source:
Throws:
-
Will throw an error if no user email is passed in
-
Will throw an error if user instance is not returned
Returns:
A found user instance.
- Type
- Object
Example
import { users as usersService } from '/src/services';
const email = 'joe.blogs@hottmail.com';
const user = await usersService.findOneByEmail(id);
(async, static) findOneByPk(id) → {Object}
Find and return user instance with id in database table
Parameters:
| Name | Type | Description |
|---|---|---|
id |
Int | Primary key id of user to find |
Throws:
-
Will throw an error if no primary key id is not passed in
-
Will throw an error if user instance is not returned
Returns:
A found user instance
- Type
- Object
Example
import { users as usersService } from '/src/services';
const id = 1;
const thing = await usersService.findOneByPk(id);
(async, static) updateOneByEmail(email, userUpdateData) → {Object}
Update user with unique email and return user data
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
email |
String | Unique email of user to update. |
||||||||||||||||||||||||||||||||
userUpdateData |
Object | User data to update. Properties
|
- Source:
Throws:
Will throw an error if no email or userUpdateData passed in.
Returns:
Update user data JSON object
- Type
- Object
Example
import { users as usersService } from 'src/services';
const id = 1;
const userUpdateData = {
firstName: 'Jonathan',
lastName: 'Doer',
email: 'Jonathan.Doer@hotmail.com',
password: 'newPassword123',
};
const updatedResetToken = await usersService.updateOneByEmail(id, data)
(async, static) updateOneByPk(id, userUpdateData) → {Object}
Update user with primary key id and return user data
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
Int | Database primary key ids |
||||||||||||||||||||||||||||||||
userUpdateData |
Object | User data JSON object Properties
|
- Source:
Throws:
Will throw an error if no id or userUpdateData passed in.
Returns:
Update user data JSON object
- Type
- Object
Example
import { users as usersService } from 'src/services';
const id = 1;
const userUpdateData = {
firstName: 'Jonathan',
lastName: 'Doer',
email: 'Jonathan.Doer@hotmail.com',
password: 'newPassword123',
};
const updatedResetToken = await usersService.updateOneByPk(id, data)