-
Notifications
You must be signed in to change notification settings - Fork 4
/
employee_service.go
83 lines (75 loc) · 3.81 KB
/
employee_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package moysklad
import (
"context"
"fmt"
"github.com/go-resty/resty/v2"
"github.com/google/uuid"
"net/http"
)
// EmployeeService
// Сервис для работы с сотрудниками.
type EmployeeService struct {
Endpoint
endpointGetList[Employee]
endpointCreate[Employee]
endpointCreateUpdateDeleteMany[Employee]
endpointDelete
endpointMetadata[MetadataAttributeShared]
endpointAttributes
endpointGetById[Employee]
endpointUpdate[Employee]
}
func NewEmployeeService(client *Client) *EmployeeService {
e := NewEndpoint(client, "entity/employee")
return &EmployeeService{
Endpoint: e,
endpointGetList: endpointGetList[Employee]{e},
endpointCreate: endpointCreate[Employee]{e},
endpointCreateUpdateDeleteMany: endpointCreateUpdateDeleteMany[Employee]{e},
endpointDelete: endpointDelete{e},
endpointMetadata: endpointMetadata[MetadataAttributeShared]{e},
endpointAttributes: endpointAttributes{e},
endpointGetById: endpointGetById[Employee]{e},
endpointUpdate: endpointUpdate[Employee]{e},
}
}
// GetPermissions Запрос на получение информации о правах Сотрудника.
// Документация МойСклад: https://dev.moysklad.ru/doc/api/remap/1.2/dictionaries/#suschnosti-sotrudnik-poluchit-informaciu-o-prawah-sotrudnika
func (s *EmployeeService) GetPermissions(ctx context.Context, id *uuid.UUID) (*EmployeePermission, *resty.Response, error) {
path := fmt.Sprintf("%s/%s/security", s.uri, id)
return NewRequestBuilder[EmployeePermission](s.client, path).Get(ctx)
}
// UpdatePermissions Запрос на изменение информации о правах Сотрудника.
// Документация МойСклад: https://dev.moysklad.ru/doc/api/remap/1.2/dictionaries/#suschnosti-sotrudnik-izmenit-informaciu-o-prawah-sotrudnika
func (s *EmployeeService) UpdatePermissions(ctx context.Context, id *uuid.UUID, permissions *EmployeePermission) (*EmployeePermission, *resty.Response, error) {
path := fmt.Sprintf("%s/%s/security", s.uri, id)
return NewRequestBuilder[EmployeePermission](s.client, path).Put(ctx, permissions)
}
// Activate Активация Сотрудника.
// Документация МойСклад: https://dev.moysklad.ru/doc/api/remap/1.2/dictionaries/#suschnosti-sotrudnik-aktiwaciq-sotrudnika
func (s *EmployeeService) Activate(ctx context.Context, id *uuid.UUID, permissions *EmployeePermission) (*MailActivationRequired, *resty.Response, error) {
path := fmt.Sprintf("%s/%s/access/activate", s.uri, id)
return NewRequestBuilder[MailActivationRequired](s.client, path).Put(ctx, permissions)
}
// Deactivate Деактивация Сотрудника.
// Документация МойСклад: https://dev.moysklad.ru/doc/api/remap/1.2/dictionaries/#suschnosti-sotrudnik-deaktiwaciq-sotrudnika
func (s *EmployeeService) Deactivate(ctx context.Context, id *uuid.UUID) (bool, *resty.Response, error) {
path := fmt.Sprintf("%s/%s/access/deactivate", s.uri, id)
response, err := s.client.client.R().SetContext(ctx).Put(path)
if err != nil {
return false, response, err
}
ok := response.StatusCode() == http.StatusNoContent
return ok, response, nil
}
// ResetPassword Сброс пароля Сотрудника.
// Документация МойСклад: https://dev.moysklad.ru/doc/api/remap/1.2/dictionaries/#suschnosti-sotrudnik-sbros-parolq-sotrudnika
func (s *EmployeeService) ResetPassword(ctx context.Context, id *uuid.UUID) (bool, *resty.Response, error) {
path := fmt.Sprintf("%s/access/resetpassword", id)
response, err := s.client.client.R().SetContext(ctx).Put(path)
if err != nil {
return false, response, err
}
ok := response.StatusCode() == http.StatusNoContent
return ok, response, nil
}