ixc-orm 1.10.3 → 1.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -4
- package/README.md +13 -7
- package/dist/IXCClient.d.ts +67 -0
- package/dist/IXCClient.js +238 -0
- package/dist/IxcOrm.d.ts +81 -0
- package/dist/IxcOrm.js +186 -0
- package/dist/IxcResponse.d.ts +62 -0
- package/dist/IxcResponse.js +132 -0
- package/dist/api/Environment.d.ts +14 -0
- package/dist/api/Environment.js +66 -0
- package/dist/api/Operators.d.ts +9 -0
- package/dist/api/Operators.js +13 -0
- package/dist/api/Ordering.d.ts +13 -0
- package/dist/api/Ordering.js +40 -0
- package/dist/api/Pagination.d.ts +8 -0
- package/dist/api/Pagination.js +22 -0
- package/dist/api/Parameter.d.ts +18 -0
- package/dist/api/Parameter.js +41 -0
- package/dist/api/RequestEmitter.d.ts +90 -0
- package/dist/api/RequestEmitter.js +211 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +61 -0
- package/dist/recursos/cliente_contrato_ativar_cliente.d.ts +4 -0
- package/dist/recursos/cliente_contrato_ativar_cliente.js +28 -0
- package/dist/recursos/cliente_contrato_btn_lib_temp_24722.d.ts +4 -0
- package/dist/recursos/cliente_contrato_btn_lib_temp_24722.js +28 -0
- package/dist/recursos/desbloqueio_confianca.d.ts +4 -0
- package/dist/recursos/desbloqueio_confianca.js +28 -0
- package/dist/recursos/get_boleto.d.ts +4 -0
- package/dist/recursos/get_boleto.js +32 -0
- package/dist/recursos/index.d.ts +75 -0
- package/dist/recursos/index.js +95 -0
- package/dist/recursos/radusuarios_25452.d.ts +4 -0
- package/dist/recursos/radusuarios_25452.js +25 -0
- package/dist/recursos/recurso.d.ts +7 -0
- package/dist/recursos/recurso.js +48 -0
- package/dist/request.d.ts +20 -0
- package/dist/request.js +73 -0
- package/dist/response.d.ts +4 -0
- package/dist/response.js +14 -0
- package/dist/types.d.ts +56 -0
- package/dist/types.js +27 -0
- package/dist/utils/FileUtils.d.ts +6 -0
- package/dist/utils/FileUtils.js +27 -0
- package/dist/utils/TextUtils.d.ts +18 -0
- package/dist/utils/TextUtils.js +35 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +9 -0
- package/package.json +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# 🔄 CHANGELOG
|
|
2
|
-
- [v1.10.
|
|
2
|
+
- [v1.10.5 - 20 de dezembro de 2025](#v1105)
|
|
3
|
+
- [v1.10.4 - 20 de novembro de 2025](#v1104)
|
|
3
4
|
- [v1.9.0 - 09 de outubro de 2025](#v190)
|
|
4
5
|
- [v1.8.0 - 18 de outubro de 2025](#v180)
|
|
5
6
|
- [v1.7.1 - 18 de outubro de 2025](#v171)
|
|
@@ -10,13 +11,18 @@
|
|
|
10
11
|
- [v1.4.3 - 15 de agosto de 2025](#v143)
|
|
11
12
|
- [v1.4.1 - 14 de agosto de 2025](#v141)
|
|
12
13
|
|
|
14
|
+
|
|
13
15
|
## 🚀 Novidades
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
|
|
18
|
+
### v1.10.5
|
|
19
|
+
* **Correção:** Removida a utilização da biblioteca nativa DOMParser, que quebrava ao tentar extrair a mensagem de erro de uma resposta do IXC Provedor.
|
|
20
|
+
|
|
21
|
+
### v1.10.4
|
|
22
|
+
* **Melhoria:** O recurso `Recurso.getArquivoBoleto()`, que obtém um arquivo PDF de um boleto, passou a utilizar o 'RequestEmitter' da API para executar a requisição. A resposta desse recurso será uma Promise contendo a instância de um objeto do tipo <a href="https://github.com/SousaFelipe/ixc-orm/blob/main/src/IxcResponse.ts">IxcResponse</a>.
|
|
17
23
|
|
|
18
24
|
### v1.9.0
|
|
19
|
-
* **Melhoria:** Novo recurso para remoção de MAC de um PPPoE, através do recurso `radusuarios_25452`, que é disponibilizado pela própria API do IXC Provedor. Para utilizar o recurso, invocar o método assícrono `Recurso.limparMAC({ id_login: number });`. O método irá retornar a
|
|
25
|
+
* **Melhoria:** Novo recurso para remoção de MAC de um PPPoE, através do recurso `radusuarios_25452`, que é disponibilizado pela própria API do IXC Provedor. Para utilizar o recurso, invocar o método assícrono `Recurso.limparMAC({ id_login: number });`. O método irá retornar a instância de um <a href="https://github.com/SousaFelipe/ixc-orm/blob/main/src/IxcResponse.ts">IxcResponse</a>.
|
|
20
26
|
|
|
21
27
|
### v1.8.0
|
|
22
28
|
* **Melhoria:** O processo de carregamento do ambiente consegue detectar se as variáveis já foram carregas por um container Docker e interrompe o carregamento através do `.env`, evitando que a aplicação encerre o processo com erro..
|
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ yarn add ixc-orm
|
|
|
33
33
|
Para configurar a comunicação da biblioteca com seu servidor IXC Provedor, é necessário adicionar as seguintes variáveis de ambiente a um arquivo `.env`, que esteja localizado no diretório raiz do seu projeto.
|
|
34
34
|
|
|
35
35
|
> [!NOTE]\
|
|
36
|
-
> Versão 1.10.
|
|
36
|
+
> Versão 1.10.5 `stable`
|
|
37
37
|
|
|
38
38
|
- **IXC_ACCESS_TOKEN** Um token de API gerado dentro do IXC Provedor.
|
|
39
39
|
- **IXC_SERVER_DOMAIN** O domínio do seu servidor IXC Provedor.
|
|
@@ -60,7 +60,7 @@ services:
|
|
|
60
60
|
As classes que representarão os diferentes tipos de registros no seu **IXC Provedor**, deverão herdar da classe `IxcOrm` (nova versão), como no exemplo a seguir:
|
|
61
61
|
|
|
62
62
|
> [!NOTE]\
|
|
63
|
-
> Versão 1.10.
|
|
63
|
+
> Versão 1.10.5 `stable`
|
|
64
64
|
|
|
65
65
|
```typescript
|
|
66
66
|
import { IxcOrm } from 'ixc-orm';
|
|
@@ -76,7 +76,7 @@ class Contrato extends IxcOrm {
|
|
|
76
76
|
Após instanciar um objeto com o tipo que você criou (`Contrato, como no exemplo a cima`), você poderá acessar os métodos de construção da query de busca.
|
|
77
77
|
|
|
78
78
|
> [!NOTE]\
|
|
79
|
-
> Versão 1.10.
|
|
79
|
+
> Versão 1.10.5 `stable`
|
|
80
80
|
|
|
81
81
|
```typescript
|
|
82
82
|
import { IxcResponse, Sort } from 'ixc-orm';
|
|
@@ -104,16 +104,22 @@ const id_contrato = 45852;
|
|
|
104
104
|
const response = await Recurso.desbloqueioDeConfianca({ id_contrato });
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
|
|
108
|
+
### Recursos disponíveis:
|
|
109
|
+
|
|
110
|
+
| Recurso IXC | Método da biblioteca | Descrição
|
|
111
|
+
| :---------- | :--------- | :---------- |
|
|
112
|
+
| ativaContrato({ id_contrato }) | cliente_contrato_ativar_cliente | Ativa um contrato que esteja com o status de `pré-contrato` |
|
|
113
|
+
| desbloqueioDeConfianca({ id_contrato }) | desbloqueio_confianca | Solicita liberação de um cliente que já tenha sido desbloqueado |
|
|
114
|
+
| getArquivoBoleto({ id_fatura }) | get_boleto | Obtém uma string base64 com o conteúdo do PDF da fatura de um cliente |
|
|
115
|
+
| limparMAC({ id_login }) | radusuarios_25452 | Remove o endereço de MAC do login de um cliente |
|
|
116
|
+
| liberacaoTemporaria({ id_contrato }) | cliente_contrato_btn_lib_temp_24722 | Desbloqueia, por 72 horas, o contrato de um cliente bloqueado |
|
|
110
117
|
|
|
111
118
|
|
|
112
119
|
# Contribuições
|
|
113
120
|
|
|
114
121
|
Contribuições são sempre bem-vindas!\
|
|
115
122
|
Se você conhece uma maneira melhor de fazer algo, por favor, me avise!
|
|
116
|
-
Caso contrário, é sempre melhor fazer um PR na branch main.
|
|
117
123
|
|
|
118
124
|
At.te,\
|
|
119
125
|
<b>Felipe S. Carmo</b>.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { IXCOptions, IXCQuery, IXCResponse, IXCSortOrder } from './types';
|
|
2
|
+
export default abstract class IXCClient {
|
|
3
|
+
protected table: string;
|
|
4
|
+
protected params: IXCQuery[];
|
|
5
|
+
protected options: IXCOptions;
|
|
6
|
+
/**
|
|
7
|
+
* @param table O nome da tabela correspondente ao banco de dados do seu servidor IXC
|
|
8
|
+
* @see {@link https://wikiapiprovedor.ixcsoft.com.br/index.php}
|
|
9
|
+
*/
|
|
10
|
+
constructor(table: string);
|
|
11
|
+
/**
|
|
12
|
+
* Incrementa o array de parâmetros que serão trasformados no corpo de uma requisição
|
|
13
|
+
* e passados como filtro grid da API do IXC
|
|
14
|
+
*
|
|
15
|
+
* @param whereClauses Um array de strings, no formato [coluna, operador, valor]\
|
|
16
|
+
* `Obs`: se você passar um array no formato [coluna, valor] o operador será considerado como '='\
|
|
17
|
+
* Os operadores válidos são: =, !=, >, <, >=, <=, LIKE
|
|
18
|
+
* @returns A própria instância
|
|
19
|
+
*/
|
|
20
|
+
where(whereClauses: string[]): IXCClient;
|
|
21
|
+
/**
|
|
22
|
+
* Define como a API do IXC ordenará os dados retornados
|
|
23
|
+
*
|
|
24
|
+
* @param column A coluna que será usada para ordenar a busca
|
|
25
|
+
* @param order A ordem da busca ('asc'ou 'desc')
|
|
26
|
+
* @returns A própria instância
|
|
27
|
+
*/
|
|
28
|
+
orderBy(column: string, order: keyof typeof IXCSortOrder): IXCClient;
|
|
29
|
+
/**
|
|
30
|
+
* Envia uma requisição GET para a API do IXC, com o header `ixcsoft` definico como `listar`\
|
|
31
|
+
* A `query` dessa requisição não será enviada para o IXC com o parâmetro `grid_param`\
|
|
32
|
+
* Ou seja, esta requisição executa uma busca simples, em vez do filtro de grid
|
|
33
|
+
*
|
|
34
|
+
* @param id O identificador numérico do registro que será buscado no IXC
|
|
35
|
+
* @returns Promise<IXCResponse>
|
|
36
|
+
*/
|
|
37
|
+
find(id: any): Promise<IXCResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* Envia uma requisição GET para a API do IXC, com o header `ixcsoft` definico como `listar`
|
|
40
|
+
* Preenche o corpo da requisição com os dados passados pela função `where` no formado JSON
|
|
41
|
+
*
|
|
42
|
+
* @param pg O número da página que será solicitada ao IXC `padão = 1`
|
|
43
|
+
* @param rows A quantidade de linhas (registros) por página `padrão = 20`
|
|
44
|
+
* @returns Promise<IXCResponse>
|
|
45
|
+
*/
|
|
46
|
+
get(pg?: number, rows?: number): Promise<IXCResponse>;
|
|
47
|
+
/**
|
|
48
|
+
* Envia uma requisição do tipo `POST` para a API do IXC, com o header `ixcsoft` vazio
|
|
49
|
+
*
|
|
50
|
+
* @param body Um objeto no formado "chave: valor" contendo as informações do novo registro
|
|
51
|
+
* a ser inserido no banco de dados do seu servidor IXC
|
|
52
|
+
* @returns Promise<IXCResponse>
|
|
53
|
+
*/
|
|
54
|
+
post(body?: {
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
}): Promise<IXCResponse>;
|
|
57
|
+
/**
|
|
58
|
+
* Envia uma requisição do tipo `PUT` para a API do IXC, com o header `ixcsoft` vazio
|
|
59
|
+
*
|
|
60
|
+
* @param id O id do registro que será alterado
|
|
61
|
+
* @param body Um objeto no formado "chave : valor" contendo as colunas que serão alteradas
|
|
62
|
+
* @returns Promise<IXCResponse>
|
|
63
|
+
*/
|
|
64
|
+
put(id: number, body?: {
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
}): Promise<IXCResponse>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
const request_1 = require("./request");
|
|
24
|
+
const types_1 = require("./types");
|
|
25
|
+
const response_1 = require("./response");
|
|
26
|
+
class IXCClient {
|
|
27
|
+
/**
|
|
28
|
+
* @param table O nome da tabela correspondente ao banco de dados do seu servidor IXC
|
|
29
|
+
* @see {@link https://wikiapiprovedor.ixcsoft.com.br/index.php}
|
|
30
|
+
*/
|
|
31
|
+
constructor(table) {
|
|
32
|
+
this.table = table;
|
|
33
|
+
this.params = [];
|
|
34
|
+
this.options = {
|
|
35
|
+
page: 1,
|
|
36
|
+
rowsPerPage: 20,
|
|
37
|
+
sortName: 'id',
|
|
38
|
+
sortOrder: 'asc'
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Incrementa o array de parâmetros que serão trasformados no corpo de uma requisição
|
|
43
|
+
* e passados como filtro grid da API do IXC
|
|
44
|
+
*
|
|
45
|
+
* @param whereClauses Um array de strings, no formato [coluna, operador, valor]\
|
|
46
|
+
* `Obs`: se você passar um array no formato [coluna, valor] o operador será considerado como '='\
|
|
47
|
+
* Os operadores válidos são: =, !=, >, <, >=, <=, LIKE
|
|
48
|
+
* @returns A própria instância
|
|
49
|
+
*/
|
|
50
|
+
where(whereClauses) {
|
|
51
|
+
if (whereClauses.length > 3) {
|
|
52
|
+
throw new Error(`> As cláusulas não podem conter mais de 3 elementos.`);
|
|
53
|
+
}
|
|
54
|
+
const [alwaysColumn, operatorOrValue, valueOrUndefined] = whereClauses;
|
|
55
|
+
const availableOperators = Object.keys(types_1.IXCOperator);
|
|
56
|
+
if (whereClauses.length > 2 && !availableOperators.includes(operatorOrValue)) {
|
|
57
|
+
throw new Error(`> O operador ${operatorOrValue}, não faz parte dos operadores válidos: ${availableOperators}.`);
|
|
58
|
+
}
|
|
59
|
+
this.params.push({
|
|
60
|
+
TB: alwaysColumn,
|
|
61
|
+
OP: valueOrUndefined ? operatorOrValue : '=',
|
|
62
|
+
P: valueOrUndefined ? valueOrUndefined : operatorOrValue
|
|
63
|
+
});
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Define como a API do IXC ordenará os dados retornados
|
|
68
|
+
*
|
|
69
|
+
* @param column A coluna que será usada para ordenar a busca
|
|
70
|
+
* @param order A ordem da busca ('asc'ou 'desc')
|
|
71
|
+
* @returns A própria instância
|
|
72
|
+
*/
|
|
73
|
+
orderBy(column, order) {
|
|
74
|
+
this.options.sortName = column;
|
|
75
|
+
this.options.sortOrder = order;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Envia uma requisição GET para a API do IXC, com o header `ixcsoft` definico como `listar`\
|
|
80
|
+
* A `query` dessa requisição não será enviada para o IXC com o parâmetro `grid_param`\
|
|
81
|
+
* Ou seja, esta requisição executa uma busca simples, em vez do filtro de grid
|
|
82
|
+
*
|
|
83
|
+
* @param id O identificador numérico do registro que será buscado no IXC
|
|
84
|
+
* @returns Promise<IXCResponse>
|
|
85
|
+
*/
|
|
86
|
+
find(id) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
const params = {
|
|
90
|
+
TB: 'id',
|
|
91
|
+
OP: '=',
|
|
92
|
+
P: id
|
|
93
|
+
};
|
|
94
|
+
const opts = {
|
|
95
|
+
page: 1,
|
|
96
|
+
rowsPerPage: 1,
|
|
97
|
+
};
|
|
98
|
+
const axios = (0, request_1.createAxiosInstance)('GET');
|
|
99
|
+
const data = (0, request_1.createRequestPayload)(this.table, params, opts);
|
|
100
|
+
try {
|
|
101
|
+
const response = yield axios.get(this.table, { data });
|
|
102
|
+
if (response.status === 200) {
|
|
103
|
+
return response.data;
|
|
104
|
+
}
|
|
105
|
+
return (0, response_1.createResponse)({
|
|
106
|
+
error: true,
|
|
107
|
+
message: (_a = response.data) === null || _a === void 0 ? void 0 : _a.message
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error(error);
|
|
112
|
+
return (0, response_1.createResponse)({
|
|
113
|
+
error: true,
|
|
114
|
+
message: ((_b = error.response) === null || _b === void 0 ? void 0 : _b.statusText) || error.message || 'Erro desconhecido'
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
this.params = [];
|
|
119
|
+
this.options = {
|
|
120
|
+
page: 1,
|
|
121
|
+
rowsPerPage: 20,
|
|
122
|
+
sortName: 'id',
|
|
123
|
+
sortOrder: 'asc'
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Envia uma requisição GET para a API do IXC, com o header `ixcsoft` definico como `listar`
|
|
130
|
+
* Preenche o corpo da requisição com os dados passados pela função `where` no formado JSON
|
|
131
|
+
*
|
|
132
|
+
* @param pg O número da página que será solicitada ao IXC `padão = 1`
|
|
133
|
+
* @param rows A quantidade de linhas (registros) por página `padrão = 20`
|
|
134
|
+
* @returns Promise<IXCResponse>
|
|
135
|
+
*/
|
|
136
|
+
get(pg, rows) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
var _a, _b;
|
|
139
|
+
const _c = this.options, { page, rowsPerPage } = _c, rest = __rest(_c, ["page", "rowsPerPage"]);
|
|
140
|
+
const opts = Object.assign({ page: pg !== null && pg !== void 0 ? pg : page, rowsPerPage: rows !== null && rows !== void 0 ? rows : rowsPerPage }, rest);
|
|
141
|
+
const axios = (0, request_1.createAxiosInstance)('GET');
|
|
142
|
+
const data = (0, request_1.createRequestPayload)(this.table, this.params, opts);
|
|
143
|
+
try {
|
|
144
|
+
const response = yield axios.get(this.table, { data });
|
|
145
|
+
if (response.status === 200) {
|
|
146
|
+
return response.data;
|
|
147
|
+
}
|
|
148
|
+
return (0, response_1.createResponse)({
|
|
149
|
+
error: true,
|
|
150
|
+
message: (_a = response.data) === null || _a === void 0 ? void 0 : _a.message
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
console.error(error);
|
|
155
|
+
return (0, response_1.createResponse)({
|
|
156
|
+
error: true,
|
|
157
|
+
message: ((_b = error.response) === null || _b === void 0 ? void 0 : _b.statusText) || error.message || 'Erro desconhecido'
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
finally {
|
|
161
|
+
this.params = [];
|
|
162
|
+
this.options = {
|
|
163
|
+
page: 1,
|
|
164
|
+
rowsPerPage: 20,
|
|
165
|
+
sortName: 'id',
|
|
166
|
+
sortOrder: 'asc'
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Envia uma requisição do tipo `POST` para a API do IXC, com o header `ixcsoft` vazio
|
|
173
|
+
*
|
|
174
|
+
* @param body Um objeto no formado "chave: valor" contendo as informações do novo registro
|
|
175
|
+
* a ser inserido no banco de dados do seu servidor IXC
|
|
176
|
+
* @returns Promise<IXCResponse>
|
|
177
|
+
*/
|
|
178
|
+
post(body) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
var _a, _b;
|
|
181
|
+
const axios = (0, request_1.createAxiosInstance)('POST');
|
|
182
|
+
try {
|
|
183
|
+
const response = yield axios.post(this.table, { data: body });
|
|
184
|
+
if (response.status === 200) {
|
|
185
|
+
return response.data;
|
|
186
|
+
}
|
|
187
|
+
return (0, response_1.createResponse)({
|
|
188
|
+
error: true,
|
|
189
|
+
message: (_a = response.data) === null || _a === void 0 ? void 0 : _a.message
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
console.error(error);
|
|
194
|
+
return (0, response_1.createResponse)({
|
|
195
|
+
error: true,
|
|
196
|
+
message: ((_b = error.response) === null || _b === void 0 ? void 0 : _b.statusText) || error.message || 'Erro desconhecido'
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
this.params = [];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Envia uma requisição do tipo `PUT` para a API do IXC, com o header `ixcsoft` vazio
|
|
206
|
+
*
|
|
207
|
+
* @param id O id do registro que será alterado
|
|
208
|
+
* @param body Um objeto no formado "chave : valor" contendo as colunas que serão alteradas
|
|
209
|
+
* @returns Promise<IXCResponse>
|
|
210
|
+
*/
|
|
211
|
+
put(id, body) {
|
|
212
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
213
|
+
var _a, _b;
|
|
214
|
+
const axios = (0, request_1.createAxiosInstance)('PUT');
|
|
215
|
+
try {
|
|
216
|
+
const response = yield axios.put(`${this.table}/${id}`, { data: body });
|
|
217
|
+
if (response.status === 200) {
|
|
218
|
+
return response.data;
|
|
219
|
+
}
|
|
220
|
+
return (0, response_1.createResponse)({
|
|
221
|
+
error: true,
|
|
222
|
+
message: (_a = response.data) === null || _a === void 0 ? void 0 : _a.message
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
console.error(error);
|
|
227
|
+
return (0, response_1.createResponse)({
|
|
228
|
+
error: true,
|
|
229
|
+
message: ((_b = error.response) === null || _b === void 0 ? void 0 : _b.statusText) || error.message || 'Erro desconhecido'
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
this.params = [];
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
exports.default = IXCClient;
|
package/dist/IxcOrm.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Sort } from './api/Ordering';
|
|
2
|
+
import RequestEmitter from './api/RequestEmitter';
|
|
3
|
+
export default abstract class IxcOrm extends RequestEmitter {
|
|
4
|
+
private ordering;
|
|
5
|
+
private pagination;
|
|
6
|
+
private parameters;
|
|
7
|
+
private parameterStub;
|
|
8
|
+
/**
|
|
9
|
+
* Método construtor da classe.
|
|
10
|
+
*
|
|
11
|
+
* @param table Representa o o nome da tabela que será manipulada, no IXC Provedor.
|
|
12
|
+
*/
|
|
13
|
+
protected constructor(table: string);
|
|
14
|
+
/**
|
|
15
|
+
* Inicia um novo objeto de parâmetro de busca do filtro da grid.
|
|
16
|
+
*
|
|
17
|
+
* @param column O nome da coluna onde o filtro de busca será executado.
|
|
18
|
+
* @returns A própria instância.
|
|
19
|
+
*/
|
|
20
|
+
where(column: string): IxcOrm;
|
|
21
|
+
/**
|
|
22
|
+
* Adiciona, ao último objeto de parâmetro iniciado, um valor a ser filtrado com o operador (**L**) = LIKE.
|
|
23
|
+
*
|
|
24
|
+
* @param value O valor a ser filtrado.
|
|
25
|
+
* @returns A própria instância.
|
|
26
|
+
*/
|
|
27
|
+
like(value: string | number): IxcOrm;
|
|
28
|
+
/**
|
|
29
|
+
* Adiciona, ao último objeto de parâmetro iniciado, um valor a ser filtrado com o operador (**=**) = EQUALS.
|
|
30
|
+
*
|
|
31
|
+
* @param value O valor a ser filtrado.
|
|
32
|
+
* @returns A própria instância.
|
|
33
|
+
*/
|
|
34
|
+
exactly(value: string | number): IxcOrm;
|
|
35
|
+
/**
|
|
36
|
+
* Adiciona, ao último objeto de parâmetro iniciado, um valor a ser filtrado com o operador (**<**) = LESS_THAN.
|
|
37
|
+
*
|
|
38
|
+
* @param value O valor a ser filtrado.
|
|
39
|
+
* @returns A própria instância.
|
|
40
|
+
*/
|
|
41
|
+
lessThan(value: string | number): IxcOrm;
|
|
42
|
+
/**
|
|
43
|
+
* Adiciona, ao último objeto de parâmetro iniciado, um valor a ser filtrado com o operador (**<=**) = LESS_THAN_EQUALS.
|
|
44
|
+
*
|
|
45
|
+
* @param value O valor a ser filtrado.
|
|
46
|
+
* @returns A própria instância.
|
|
47
|
+
*/
|
|
48
|
+
lessThanEquals(value: string | number): IxcOrm;
|
|
49
|
+
/**
|
|
50
|
+
* Adiciona, ao último objeto de parâmetro iniciado, um valor a ser filtrado com o operador (**>**) = GREATER_THAN.
|
|
51
|
+
*
|
|
52
|
+
* @param value O valor a ser filtrado.
|
|
53
|
+
* @returns A própria instância.
|
|
54
|
+
*/
|
|
55
|
+
greaterThan(value: string | number): IxcOrm;
|
|
56
|
+
/**
|
|
57
|
+
* Adiciona, ao último objeto de parâmetro iniciado, um valor a ser filtrado com o operador (**>=**) = GREATER_THAN_EQUALS.
|
|
58
|
+
*
|
|
59
|
+
* @param value O valor a ser filtrado.
|
|
60
|
+
* @returns A própria instância.
|
|
61
|
+
*/
|
|
62
|
+
greaterThanEquals(value: string | number): IxcOrm;
|
|
63
|
+
/**
|
|
64
|
+
* Define o número da página e a quantidade de registros por página que serão retornados pelo IXc Provedor.
|
|
65
|
+
*
|
|
66
|
+
* @param page A página a ser buscada.
|
|
67
|
+
* @param rows A quantidade de registros por página.
|
|
68
|
+
* @returns A própria instância.
|
|
69
|
+
*/
|
|
70
|
+
paginate(page: number, rows: number): this;
|
|
71
|
+
/**
|
|
72
|
+
* Define o tipo de ordenação dos registros retornados pela API do IXC Provedor.
|
|
73
|
+
*
|
|
74
|
+
* @param sort **ASC** ou **DESC**.
|
|
75
|
+
* @param column A coluna que será utilizada para ordenar os registros.
|
|
76
|
+
* @returns A própria instância.
|
|
77
|
+
*/
|
|
78
|
+
orderBy(column: string, sort: Sort): this;
|
|
79
|
+
private createQueryObject;
|
|
80
|
+
private addParamToGridAndResetStub;
|
|
81
|
+
}
|
package/dist/IxcOrm.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const Operators_1 = __importDefault(require("./api/Operators"));
|
|
40
|
+
const Ordering_1 = __importStar(require("./api/Ordering"));
|
|
41
|
+
const Pagination_1 = __importDefault(require("./api/Pagination"));
|
|
42
|
+
const Parameter_1 = __importDefault(require("./api/Parameter"));
|
|
43
|
+
const RequestEmitter_1 = __importDefault(require("./api/RequestEmitter"));
|
|
44
|
+
class IxcOrm extends RequestEmitter_1.default {
|
|
45
|
+
/**
|
|
46
|
+
* Método construtor da classe.
|
|
47
|
+
*
|
|
48
|
+
* @param table Representa o o nome da tabela que será manipulada, no IXC Provedor.
|
|
49
|
+
*/
|
|
50
|
+
constructor(table) {
|
|
51
|
+
super(table);
|
|
52
|
+
this.ordering = Ordering_1.default.ascBy(table, "id");
|
|
53
|
+
this.pagination = Pagination_1.default.defaults();
|
|
54
|
+
this.parameters = [];
|
|
55
|
+
this.parameterStub = new Parameter_1.default(table);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Inicia um novo objeto de parâmetro de busca do filtro da grid.
|
|
59
|
+
*
|
|
60
|
+
* @param column O nome da coluna onde o filtro de busca será executado.
|
|
61
|
+
* @returns A própria instância.
|
|
62
|
+
*/
|
|
63
|
+
where(column) {
|
|
64
|
+
this.parameterStub.withType(column);
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Adiciona, ao último objeto de parâmetro iniciado, um valor a ser filtrado com o operador (**L**) = LIKE.
|
|
69
|
+
*
|
|
70
|
+
* @param value O valor a ser filtrado.
|
|
71
|
+
* @returns A própria instância.
|
|
72
|
+
*/
|
|
73
|
+
like(value) {
|
|
74
|
+
this.parameterStub.withOperator(Operators_1.default.LIKE);
|
|
75
|
+
this.parameterStub.withValue(value);
|
|
76
|
+
this.addParamToGridAndResetStub();
|
|
77
|
+
super.setupQuery(this.createQueryObject());
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Adiciona, ao último objeto de parâmetro iniciado, um valor a ser filtrado com o operador (**=**) = EQUALS.
|
|
82
|
+
*
|
|
83
|
+
* @param value O valor a ser filtrado.
|
|
84
|
+
* @returns A própria instância.
|
|
85
|
+
*/
|
|
86
|
+
exactly(value) {
|
|
87
|
+
this.parameterStub.withOperator(Operators_1.default.EQUALS);
|
|
88
|
+
this.parameterStub.withValue(value);
|
|
89
|
+
this.addParamToGridAndResetStub();
|
|
90
|
+
super.setupQuery(this.createQueryObject());
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Adiciona, ao último objeto de parâmetro iniciado, um valor a ser filtrado com o operador (**<**) = LESS_THAN.
|
|
95
|
+
*
|
|
96
|
+
* @param value O valor a ser filtrado.
|
|
97
|
+
* @returns A própria instância.
|
|
98
|
+
*/
|
|
99
|
+
lessThan(value) {
|
|
100
|
+
this.parameterStub.withOperator(Operators_1.default.LESS_THAN);
|
|
101
|
+
this.parameterStub.withValue(value);
|
|
102
|
+
this.addParamToGridAndResetStub();
|
|
103
|
+
super.setupQuery(this.createQueryObject());
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Adiciona, ao último objeto de parâmetro iniciado, um valor a ser filtrado com o operador (**<=**) = LESS_THAN_EQUALS.
|
|
108
|
+
*
|
|
109
|
+
* @param value O valor a ser filtrado.
|
|
110
|
+
* @returns A própria instância.
|
|
111
|
+
*/
|
|
112
|
+
lessThanEquals(value) {
|
|
113
|
+
this.parameterStub.withOperator(Operators_1.default.LESS_THAN_EQUALS);
|
|
114
|
+
this.parameterStub.withValue(value);
|
|
115
|
+
this.addParamToGridAndResetStub();
|
|
116
|
+
super.setupQuery(this.createQueryObject());
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Adiciona, ao último objeto de parâmetro iniciado, um valor a ser filtrado com o operador (**>**) = GREATER_THAN.
|
|
121
|
+
*
|
|
122
|
+
* @param value O valor a ser filtrado.
|
|
123
|
+
* @returns A própria instância.
|
|
124
|
+
*/
|
|
125
|
+
greaterThan(value) {
|
|
126
|
+
this.parameterStub.withOperator(Operators_1.default.GREATER_THAN);
|
|
127
|
+
this.parameterStub.withValue(value);
|
|
128
|
+
this.addParamToGridAndResetStub();
|
|
129
|
+
super.setupQuery(this.createQueryObject());
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Adiciona, ao último objeto de parâmetro iniciado, um valor a ser filtrado com o operador (**>=**) = GREATER_THAN_EQUALS.
|
|
134
|
+
*
|
|
135
|
+
* @param value O valor a ser filtrado.
|
|
136
|
+
* @returns A própria instância.
|
|
137
|
+
*/
|
|
138
|
+
greaterThanEquals(value) {
|
|
139
|
+
this.parameterStub.withOperator(Operators_1.default.GREATER_THAN_EQUALS);
|
|
140
|
+
this.parameterStub.withValue(value);
|
|
141
|
+
this.addParamToGridAndResetStub();
|
|
142
|
+
super.setupQuery(this.createQueryObject());
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Define o número da página e a quantidade de registros por página que serão retornados pelo IXc Provedor.
|
|
147
|
+
*
|
|
148
|
+
* @param page A página a ser buscada.
|
|
149
|
+
* @param rows A quantidade de registros por página.
|
|
150
|
+
* @returns A própria instância.
|
|
151
|
+
*/
|
|
152
|
+
paginate(page, rows) {
|
|
153
|
+
this.pagination = new Pagination_1.default(page, rows);
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Define o tipo de ordenação dos registros retornados pela API do IXC Provedor.
|
|
158
|
+
*
|
|
159
|
+
* @param sort **ASC** ou **DESC**.
|
|
160
|
+
* @param column A coluna que será utilizada para ordenar os registros.
|
|
161
|
+
* @returns A própria instância.
|
|
162
|
+
*/
|
|
163
|
+
orderBy(column, sort) {
|
|
164
|
+
this.ordering = (sort === Ordering_1.Sort.ASC)
|
|
165
|
+
? Ordering_1.default.ascBy(super.getTable(), column)
|
|
166
|
+
: Ordering_1.default.descBy(super.getTable(), column);
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
createQueryObject() {
|
|
170
|
+
return {
|
|
171
|
+
qtype: super.getTable(),
|
|
172
|
+
query: "",
|
|
173
|
+
oper: "",
|
|
174
|
+
page: this.pagination.getPage(),
|
|
175
|
+
rp: this.pagination.getRows(),
|
|
176
|
+
sortname: this.ordering.getSortName(),
|
|
177
|
+
sortorder: this.ordering.getSortOrder().toString(),
|
|
178
|
+
grid_param: JSON.stringify(this.parameters)
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
addParamToGridAndResetStub() {
|
|
182
|
+
this.parameters.push(this.parameterStub.toJsonObject());
|
|
183
|
+
this.parameterStub = new Parameter_1.default(super.getTable());
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.default = IxcOrm;
|