http-sankhya 1.0.1 → 1.0.3

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/README.md CHANGED
@@ -138,16 +138,18 @@ const novoGrupo = await sankhya.saveRecord({
138
138
  });
139
139
  ```
140
140
 
141
- #### Atualizar Registro Existente (Upsert)
142
- Para atualizar, inclua a Chave Primária nos `localFields`. O comportamento exato depende da entidade Sankhya, mas geralmente atua como "Upsert" (Atualiza se existe, cria se não).
141
+ #### Atualizar Registro Existente
142
+ Para atualizar um registro existente, você deve fornecer a propriedade `key` contendo a chave primária do registro. Isso instrui o Sankhya a realizar um update na linha específica.
143
143
 
144
144
  ```typescript
145
145
  const atualizacao = await sankhya.saveRecord({
146
146
  rootEntity: 'GrupoProduto',
147
147
  localFields: {
148
- CODGRUPOPROD: "20310006", // PK existente
149
- DESCRGRUPOPROD: "NOME ATUALIZADO", // Campo a alterar
148
+ DESCRGRUPOPROD: "NOME ATUALIZADO", // Campos a alterar
150
149
  ATIVO: "N"
150
+ },
151
+ key: {
152
+ CODGRUPOPROD: "20310006" // Chave Primária (PK) para identificação do registro
151
153
  }
152
154
  });
153
155
  ```
package/dist/Sankhya.d.ts CHANGED
@@ -16,6 +16,7 @@ export interface SaveRecordOptions {
16
16
  rootEntity: string;
17
17
  includePresentationFields?: 'S' | 'N';
18
18
  localFields?: Record<string, any>;
19
+ key?: Record<string, any>;
19
20
  entity?: Record<string, any>;
20
21
  }
21
22
  export interface ExecServiceOptions {
@@ -42,6 +43,6 @@ export declare class Sankhya {
42
43
  execService(options: ExecServiceOptions, outputType?: 'json' | 'xml'): Promise<any>;
43
44
  loadRecords({ rootEntity, includePresentationFields, offsetPage, criteria, entity }: LoadRecordsOptions, outputType?: 'json' | 'xml'): Promise<any>;
44
45
  loadRecord({ rootEntity, includePresentationFields, criteria, entity, rows }: LoadRecordsOptions, outputType?: 'json' | 'xml'): Promise<any>;
45
- saveRecord({ rootEntity, includePresentationFields, localFields, entity }: SaveRecordOptions, outputType?: 'json' | 'xml'): Promise<any>;
46
+ saveRecord({ rootEntity, includePresentationFields, localFields, key, entity }: SaveRecordOptions, outputType?: 'json' | 'xml'): Promise<any>;
46
47
  private isEmptyObject;
47
48
  }
package/dist/Sankhya.js CHANGED
@@ -139,7 +139,7 @@ class Sankhya {
139
139
  outputType
140
140
  }, outputType);
141
141
  }
142
- async saveRecord({ rootEntity, includePresentationFields = 'N', localFields = {}, entity = {} }, outputType = 'json') {
142
+ async saveRecord({ rootEntity, includePresentationFields = 'N', localFields = {}, key = {}, entity = {} }, outputType = 'json') {
143
143
  return this.execService({
144
144
  serviceName: 'CRUDServiceProvider.saveRecord',
145
145
  requestBody: {
@@ -147,10 +147,11 @@ class Sankhya {
147
147
  rootEntity,
148
148
  includePresentationFields,
149
149
  dataRow: {
150
- localFields: SankhyaHelper_1.SankhyaHelper.transformLocalFields(localFields)
150
+ localFields: SankhyaHelper_1.SankhyaHelper.transformLocalFields(localFields),
151
+ key: SankhyaHelper_1.SankhyaHelper.transformLocalFields(key)
151
152
  },
152
- },
153
- entity
153
+ entity
154
+ }
154
155
  },
155
156
  outputType
156
157
  }, outputType);
@@ -11,5 +11,7 @@ export declare class SankhyaHelper {
11
11
  * Ex: { CAMPO: "VALOR" } -> { CAMPO: { "$": "VALOR" } }
12
12
  */
13
13
  static transformLocalFields(localFields: Record<string, any>): Record<string, any>;
14
+ private static processSaveRecord;
15
+ private static processLoadRecord;
14
16
  private static processLoadRecords;
15
17
  }
@@ -12,9 +12,11 @@ class SankhyaHelper {
12
12
  }
13
13
  switch (options.serviceName) {
14
14
  case 'CRUDServiceProvider.loadRecords':
15
- case 'CRUDServiceProvider.loadRecord':
16
- case 'CRUDServiceProvider.saveRecord':
17
15
  return this.processLoadRecords(response);
16
+ case 'CRUDServiceProvider.saveRecord':
17
+ return this.processSaveRecord(response);
18
+ case 'CRUDServiceProvider.loadRecord':
19
+ return this.processLoadRecord(response);
18
20
  default:
19
21
  // Se não for um dos serviços conhecidos de CRUD/Load, retorna original
20
22
  return response;
@@ -39,6 +41,19 @@ class SankhyaHelper {
39
41
  return transformed;
40
42
  }
41
43
  // Lógica de transformação extraída para método privado
44
+ static processSaveRecord(response) {
45
+ if (response.status === '0') {
46
+ return response;
47
+ }
48
+ return this.processLoadRecords(response);
49
+ }
50
+ static processLoadRecord(response) {
51
+ const { entities } = response.responseBody;
52
+ if (entities.total === '0') {
53
+ return null;
54
+ }
55
+ return this.processLoadRecords(response);
56
+ }
42
57
  static processLoadRecords(response) {
43
58
  const { entities } = response.responseBody;
44
59
  const metadata = entities.metadata;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "http-sankhya",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Biblioteca TypeScript para integração com ERP Sankhya",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",