mirror of
https://github.com/sergeyyarkov/educt-server.git
synced 2026-10-11 18:29:15 +03:00
refactor: descriptions of funcs
This commit is contained in:
parent
f8e3417f1f
commit
7ef12795d9
@ -11,7 +11,7 @@ export default class ContactRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates user contacts in database
|
* Create user contacts in database
|
||||||
*
|
*
|
||||||
* @param user User for associate the contacts
|
* @param user User for associate the contacts
|
||||||
* @param data Data contacts
|
* @param data Data contacts
|
||||||
@ -27,12 +27,16 @@ export default class ContactRepository {
|
|||||||
return contacts;
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update user contacts
|
||||||
|
*
|
||||||
|
* @param user User
|
||||||
|
* @param data Data to update
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
public async update(user: User, data: Pick<UpdateUserValidator['schema']['props'], 'email'>) {
|
public async update(user: User, data: Pick<UpdateUserValidator['schema']['props'], 'email'>) {
|
||||||
const contacts = await this.Contact.query().where('user_id', user.id).first();
|
const contacts = await this.Contact.query().where('user_id', user.id).first();
|
||||||
|
|
||||||
/**
|
|
||||||
* Update user contacts
|
|
||||||
*/
|
|
||||||
if (contacts) {
|
if (contacts) {
|
||||||
contacts.email = data.email;
|
contacts.email = data.email;
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,12 @@ export default class RoleRepository {
|
|||||||
this.Role = Role;
|
this.Role = Role;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list of roles
|
||||||
|
*
|
||||||
|
* @param params Params to find roles
|
||||||
|
* @returns Array of roles
|
||||||
|
*/
|
||||||
public async getAll(params?: any) {
|
public async getAll(params?: any) {
|
||||||
const { roles }: any = params || {};
|
const { roles }: any = params || {};
|
||||||
const query = this.Role.query();
|
const query = this.Role.query();
|
||||||
@ -19,8 +25,14 @@ export default class RoleRepository {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get role by slug
|
||||||
|
*
|
||||||
|
* @param slug Role slug
|
||||||
|
* @returns Role or null
|
||||||
|
*/
|
||||||
public async getBySlug(slug: string) {
|
public async getBySlug(slug: string) {
|
||||||
const role = await this.Role.query().where('slug', slug);
|
const role = await this.Role.query().where('slug', slug).first();
|
||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,11 +10,23 @@ export default class UserRepository {
|
|||||||
this.User = User;
|
this.User = User;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get user by id
|
||||||
|
*
|
||||||
|
* @param id User id
|
||||||
|
* @returns User or null
|
||||||
|
*/
|
||||||
public async getById(id: string | number) {
|
public async getById(id: string | number) {
|
||||||
const data = await this.User.query().preload('contacts').preload('roles').where('id', id).first();
|
const data = await this.User.query().preload('contacts').preload('roles').where('id', id).first();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get users by role
|
||||||
|
*
|
||||||
|
* @param role Role
|
||||||
|
* @returns Array of users with role
|
||||||
|
*/
|
||||||
public async getAllByRole(role: string) {
|
public async getAllByRole(role: string) {
|
||||||
const data = await this.User.query()
|
const data = await this.User.query()
|
||||||
.preload('contacts')
|
.preload('contacts')
|
||||||
@ -23,6 +35,12 @@ export default class UserRepository {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list users
|
||||||
|
*
|
||||||
|
* @param params Params to find
|
||||||
|
* @returns Array of users
|
||||||
|
*/
|
||||||
public async getAll(params?: any) {
|
public async getAll(params?: any) {
|
||||||
const { email, login, first_name, last_name, role }: any = params || {};
|
const { email, login, first_name, last_name, role }: any = params || {};
|
||||||
const query = this.User.query();
|
const query = this.User.query();
|
||||||
@ -51,6 +69,12 @@ export default class UserRepository {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create user
|
||||||
|
*
|
||||||
|
* @param data Data for create user
|
||||||
|
* @returns Created user
|
||||||
|
*/
|
||||||
public async create(data: CreateUserValidator['schema']['props']) {
|
public async create(data: CreateUserValidator['schema']['props']) {
|
||||||
const createdUser = await this.User.create({
|
const createdUser = await this.User.create({
|
||||||
first_name: data.first_name,
|
first_name: data.first_name,
|
||||||
|
|||||||
@ -71,7 +71,7 @@ export default class UserService {
|
|||||||
* Create new user
|
* Create new user
|
||||||
*
|
*
|
||||||
* @param data Input for create new user
|
* @param data Input for create new user
|
||||||
* @returns Response data
|
* @returns Response
|
||||||
*/
|
*/
|
||||||
public async createUser(data: CreateUserValidator['schema']['props']): Promise<IResponse> {
|
public async createUser(data: CreateUserValidator['schema']['props']): Promise<IResponse> {
|
||||||
const user = await this.userRepository.create(data);
|
const user = await this.userRepository.create(data);
|
||||||
@ -87,6 +87,13 @@ export default class UserService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update user
|
||||||
|
*
|
||||||
|
* @param id User id
|
||||||
|
* @param data Data to update
|
||||||
|
* @returns Response
|
||||||
|
*/
|
||||||
public async updateUser(id: string | number, data: UpdateUserValidator['schema']['props']): Promise<IResponse> {
|
public async updateUser(id: string | number, data: UpdateUserValidator['schema']['props']): Promise<IResponse> {
|
||||||
const user = await this.userRepository.update(id, data);
|
const user = await this.userRepository.update(id, data);
|
||||||
|
|
||||||
@ -115,6 +122,12 @@ export default class UserService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete user
|
||||||
|
*
|
||||||
|
* @param id User id
|
||||||
|
* @returns Response
|
||||||
|
*/
|
||||||
public async deleteUser(id: string | number): Promise<IResponse> {
|
public async deleteUser(id: string | number): Promise<IResponse> {
|
||||||
const user = await this.userRepository.delete(id);
|
const user = await this.userRepository.delete(id);
|
||||||
|
|
||||||
@ -143,7 +156,7 @@ export default class UserService {
|
|||||||
*
|
*
|
||||||
* @param id User id
|
* @param id User id
|
||||||
* @param input Roles
|
* @param input Roles
|
||||||
* @returns Result
|
* @returns Response
|
||||||
*/
|
*/
|
||||||
public async attachRolesToUser(id: string | number, input: string[]): Promise<IResponse> {
|
public async attachRolesToUser(id: string | number, input: string[]): Promise<IResponse> {
|
||||||
const user = await this.userRepository.getById(id);
|
const user = await this.userRepository.getById(id);
|
||||||
@ -204,7 +217,7 @@ export default class UserService {
|
|||||||
*
|
*
|
||||||
* @param id User id
|
* @param id User id
|
||||||
* @param input Roles
|
* @param input Roles
|
||||||
* @returns Result
|
* @returns Response
|
||||||
*/
|
*/
|
||||||
public async detachRolesFromUser(id: string | number, input: string[]): Promise<IResponse> {
|
public async detachRolesFromUser(id: string | number, input: string[]): Promise<IResponse> {
|
||||||
const user = await this.userRepository.getById(id);
|
const user = await this.userRepository.getById(id);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user