Skip to content

Commit 9d661f1

Browse files
committed
paser yard data json
1 parent 3d6bdc0 commit 9d661f1

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "helyosjs-sdk",
3-
"version": "2.0.4",
3+
"version": "2.0.5",
44
"description": "Comunication with helyos postgress database using graphql interface",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -20,7 +20,6 @@
2020
"javascript",
2121
"api"
2222
],
23-
"author": "Carlos Viol Barbosa",
2423
"license": "MIT",
2524
"devDependencies": {
2625
"@types/basic-auth": "^1.1.2",

src/cruds/yards.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ import { H_Yard } from '../helyos.models';
5454
this.lastListPromise= this._client.query({ query: TOOL_QUERY, variables: { condition: condition } })
5555
.then(response => {
5656
self.fetching = false;
57-
return gqlJsonResponseHandler(response, QUERY_FUNTCION);
57+
const listItems = gqlJsonResponseHandler(response, QUERY_FUNTCION);
58+
return parseStringifiedJsonColumns(listItems, ['mapData']);
5859
})
5960
.catch(e => {
6061
console.log(e);
@@ -67,6 +68,7 @@ import { H_Yard } from '../helyos.models';
6768

6869

6970
create(yard: Partial<H_Yard>): Promise<any> {
71+
const QUERY_FUNTCION = 'createYard';
7072
const CREATE = gql`
7173
mutation createYard ($postMessage: CreateYardInput!){
7274
createYard(input: $postMessage) {
@@ -93,10 +95,16 @@ import { H_Yard } from '../helyos.models';
9395
9496
`;
9597

96-
const postMessage = { clientMutationId: "not_used", yard: yard };
98+
const patch = {...yard};
99+
delete patch['__typename'];
100+
stringifyJsonFields(patch,['mapData']);
101+
102+
const postMessage = { clientMutationId: "not_used", yard: patch };
103+
console.log("postMessage",postMessage)
97104
return this._client.mutate({ mutation: CREATE, variables: { postMessage, yard: yard } })
98105
.then(response => {
99-
return response.data.createYard.yard;
106+
const data = gqlJsonResponseInstanceHandler(response, QUERY_FUNTCION,'yard' );
107+
return parseStringifiedJsonColumns([data], ['mapData'])[0];
100108
})
101109
.catch(e => {
102110
console.log(e);
@@ -111,7 +119,7 @@ import { H_Yard } from '../helyos.models';
111119

112120
patch(yard: Partial<H_Yard>): Promise<any> {
113121
const QUERY_FUNTCION = 'updateYardById';
114-
const TOOL_UPDATE = gql`
122+
const YARD_UPDATE = gql`
115123
mutation updateYardById ($postMessage: UpdateYardByIdInput!){
116124
updateYardById(input: $postMessage) {
117125
yard {
@@ -136,12 +144,14 @@ import { H_Yard } from '../helyos.models';
136144
}
137145
`;
138146

139-
delete yard['__typename'];
140-
const postMessage = { id: yard.id, yardPatch: yard };
141-
return this._client.mutate({ mutation: TOOL_UPDATE, variables: { postMessage, yard: yard } })
147+
const patch = {...yard};
148+
delete patch['__typename'];
149+
stringifyJsonFields(patch,['mapData']);
150+
const postMessage = { id: yard.id, yardPatch: patch };
151+
return this._client.mutate({ mutation: YARD_UPDATE, variables: { postMessage, yard: patch } })
142152
.then(response => {
143-
console.log('update request response', response);
144-
return gqlJsonResponseInstanceHandler(response, QUERY_FUNTCION,'yard' );
153+
const data = gqlJsonResponseInstanceHandler(response, QUERY_FUNTCION,'yard' );
154+
return parseStringifiedJsonColumns([data], ['mapData'])[0];
145155
})
146156
.catch(e => {
147157
console.log(e);
@@ -153,7 +163,7 @@ import { H_Yard } from '../helyos.models';
153163

154164
get(yardId: string ): Promise<H_Yard> {
155165
const QUERY_FUNTCION = 'yardById';
156-
const SHAPE_QUERY = gql`
166+
const GET_QUERY = gql`
157167
query ${QUERY_FUNTCION}($yardId: BigInt! ){
158168
${QUERY_FUNTCION}(id: $yardId) {
159169
id,
@@ -177,10 +187,11 @@ import { H_Yard } from '../helyos.models';
177187
`;
178188

179189

180-
this.getActionPromise = this._client.query({ query: SHAPE_QUERY, variables: {yardId: parseInt(yardId) } })
190+
this.getActionPromise = this._client.query({ query: GET_QUERY, variables: {yardId: parseInt(yardId) } })
181191
.then(response => {
182192
const data = gqlJsonResponseHandler(response, QUERY_FUNTCION);
183-
return data;
193+
return parseStringifiedJsonColumns([data], ['mapData'])[0];
194+
184195
})
185196
.catch(e => {
186197
console.log(e);
@@ -192,15 +203,15 @@ import { H_Yard } from '../helyos.models';
192203

193204
delete(id): Promise<any> {
194205
const QUERY_FUNTCION = 'deleteYardById';
195-
const SHAPE_QUERY = gql`
206+
const DELETE_QUERY = gql`
196207
mutation ${QUERY_FUNTCION}($deletedYardById: DeleteYardByIdInput! ){
197208
${QUERY_FUNTCION}(input: $deletedYardById) {
198209
deletedYardId
199210
}
200211
}
201212
`;
202213

203-
return this._client.query({ query: SHAPE_QUERY, variables: {deletedYardById: {id:parseInt(id,10) }} })
214+
return this._client.query({ query: DELETE_QUERY, variables: {deletedYardById: {id:parseInt(id,10) }} })
204215
.then(response => {
205216
if (response.errors) {
206217
return response.errors[0];

0 commit comments

Comments
 (0)