@webresto/graphql 1.4.2 → 1.4.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/lib/afterHook.js CHANGED
@@ -14,12 +14,19 @@ async function default_1() {
14
14
  cache = null;
15
15
  });
16
16
  sails.on('lifted', async function () {
17
- const graphServer = await graphql_1.default.init();
18
- // inject middleware into express app
19
- sails.hooks.http.app.use(graphServer.getMiddleware());
20
- let layer = sails.hooks.http.app._router.stack.slice(-1)[0];
21
- sails.hooks.http.app._router.stack.splice(1, 0, layer);
22
- graphServer.installSubscriptionHandlers(sails.hooks.http.server);
17
+ try {
18
+ const graphServer = await graphql_1.default.init();
19
+ // inject middleware into express app
20
+ sails.hooks.http.app.use(graphServer.getMiddleware());
21
+ let layer = sails.hooks.http.app._router.stack.slice(-1)[0];
22
+ sails.hooks.http.app._router.stack.splice(1, 0, layer);
23
+ graphServer.installSubscriptionHandlers(sails.hooks.http.server);
24
+ sails.emit('graphql-middleware:loaded');
25
+ }
26
+ catch (error) {
27
+ sails.emit('graphql-middleware:error');
28
+ sails.log.error(error);
29
+ }
23
30
  });
24
31
  if (await Settings.get("JWT_SECRET") === undefined) {
25
32
  //@ts-ignore
package/lib/afterHook.ts CHANGED
@@ -11,13 +11,19 @@ export default async function () {
11
11
  cache = null;
12
12
  });
13
13
  sails.on('lifted', async function (){
14
- const graphServer = await graphql.init();
15
-
16
- // inject middleware into express app
17
- sails.hooks.http.app.use(graphServer.getMiddleware());
18
- let layer = sails.hooks.http.app._router.stack.slice(-1)[0]
19
- sails.hooks.http.app._router.stack.splice(1, 0, layer)
20
- graphServer.installSubscriptionHandlers(sails.hooks.http.server);
14
+ try {
15
+ const graphServer = await graphql.init();
16
+
17
+ // inject middleware into express app
18
+ sails.hooks.http.app.use(graphServer.getMiddleware());
19
+ let layer = sails.hooks.http.app._router.stack.slice(-1)[0]
20
+ sails.hooks.http.app._router.stack.splice(1, 0, layer)
21
+ graphServer.installSubscriptionHandlers(sails.hooks.http.server);
22
+ sails.emit('graphql-middleware:loaded');
23
+ } catch (error) {
24
+ sails.emit('graphql-middleware:error');
25
+ sails.log.error(error);
26
+ }
21
27
  })
22
28
 
23
29
  if (await Settings.get("JWT_SECRET") === undefined) {
@@ -0,0 +1 @@
1
+ export default function checkDeviceId(context: any): void;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function checkDeviceId(context) {
4
+ if (!context.connectionParams.deviceId) {
5
+ throw `Missed deviceId`;
6
+ }
7
+ }
8
+ exports.default = checkDeviceId;
@@ -0,0 +1,5 @@
1
+ export default function checkDeviceId(context: any): void {
2
+ if (!context.connectionParams.deviceId) {
3
+ throw `Missed deviceId`;
4
+ }
5
+ }
package/package.json CHANGED
@@ -68,5 +68,5 @@
68
68
  "test:js": "mocha test/bootstrap.js './test/{,!(fixture)/**}/*.test.js' --exit",
69
69
  "test:init": "cd ./test/fixture && npm i --no-package-lock --prefix ./ && cd -"
70
70
  },
71
- "version": "1.4.2"
71
+ "version": "1.4.3"
72
72
  }
package/src/graphql.js CHANGED
@@ -252,13 +252,12 @@ exports.default = {
252
252
  },
253
253
  formatError: (error) => {
254
254
  const graphQLFormattedError = {
255
- message: `${error.path}: ${error.message}`,
256
- ...process.env.NODE_ENV !== "production" && {
257
- locations: error.extensions.exception.stacktrace,
258
- path: error.path
259
- },
255
+ message: error.message,
256
+ locations: process.env.NODE_ENV !== "production" ? error.locations ?? error.extensions.exception.stacktrace ?? null : null,
257
+ path: error.path
260
258
  };
261
- sails.log.error(`Grahql error:`, JSON.stringify(graphQLFormattedError));
259
+ sails.log.error('GraphQL Error:', graphQLFormattedError);
260
+ sails.log.error(error.locations ?? error.extensions.exception.stacktrace);
262
261
  return graphQLFormattedError;
263
262
  },
264
263
  context: ({ req, connection }) => {
package/src/graphql.ts CHANGED
@@ -255,15 +255,15 @@ export default {
255
255
  return exContext;
256
256
  },
257
257
  },
258
- formatError: (error: GraphQLError) => {
258
+
259
+ formatError: (error) => {
259
260
  const graphQLFormattedError: GraphQLFormattedError = {
260
- message: `${error.path}: ${error.message}`,
261
- ...process.env.NODE_ENV !== "production" && {
262
- locations: error.extensions.exception.stacktrace,
261
+ message: error.message,
262
+ locations: process.env.NODE_ENV !== "production" ? error.locations ?? error.extensions.exception.stacktrace ?? null : null,
263
263
  path: error.path
264
- },
265
- }
266
- sails.log.error(`Grahql error:`, JSON.stringify(graphQLFormattedError));
264
+ };
265
+ sails.log.error('GraphQL Error:', graphQLFormattedError);
266
+ sails.log.error(error.locations ?? error.extensions.exception.stacktrace)
267
267
  return graphQLFormattedError;
268
268
  },
269
269
  context: ({ req, connection }) => {
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const eventHelper = __importStar(require("../../lib/eventHelper"));
30
30
  const graphqlHelper_1 = __importDefault(require("../../lib/graphqlHelper"));
31
31
  const jwt_1 = require("../../lib/jwt");
32
+ const checkDeviceId_1 = __importDefault(require("../../lib/helper/checkDeviceId"));
32
33
  graphqlHelper_1.default.addType(`#graphql
33
34
  input InputOrderCheckout {
34
35
  orderId: String!
@@ -60,9 +61,7 @@ exports.default = {
60
61
  checkOrder(orderCheckout: InputOrderCheckout): CheckResponse`,
61
62
  fn: async function (parent, args, context) {
62
63
  let data = args.orderCheckout;
63
- if (!context.connectionParams.deviceId) {
64
- throw `Missed deviceId`;
65
- }
64
+ (0, checkDeviceId_1.default)(context);
66
65
  // if (data.date) {
67
66
  // let date = moment(data.date)
68
67
  // if(!date.isValid()){
@@ -84,6 +83,7 @@ exports.default = {
84
83
  message: context.i18n.__("Order with id %s not found", data.orderId),
85
84
  });
86
85
  }
86
+ let address = null;
87
87
  //@ts-ignore
88
88
  if (data.selfService) {
89
89
  isSelfService = true;
@@ -93,6 +93,19 @@ exports.default = {
93
93
  order.pickupPoint = null;
94
94
  if (!data.address && !data.locationId)
95
95
  throw `Address is required for non self service orders`;
96
+ address = {
97
+ city: address.city || await Settings.use("city"),
98
+ street: address.street,
99
+ ...address.streetId && { streetId: address.streetId },
100
+ home: address.home,
101
+ ...address.housing && { housing: address.housing },
102
+ ...address.apartment && { apartment: address.apartment },
103
+ ...address.index && { index: address.index },
104
+ ...address.entrance && { entrance: address.entrance },
105
+ ...address.floor && { floor: address.floor },
106
+ ...address.apartment && { apartment: address.apartment },
107
+ ...address.comment && { comment: address.comment },
108
+ };
96
109
  }
97
110
  if (order.state === "ORDER") {
98
111
  message = eventHelper.sendMessage({
@@ -112,29 +125,18 @@ exports.default = {
112
125
  });
113
126
  }
114
127
  }
115
- if (data.locationId) {
116
- var address = await UserLocation.findOne({ id: data.locationId });
117
- if (!address)
118
- throw `locationId not found`;
119
- }
120
- else {
121
- if (data.address) {
122
- var address = data.address;
128
+ if (!isSelfService) {
129
+ if (data.locationId) {
130
+ address = await UserLocation.findOne({ id: data.locationId });
131
+ if (!address)
132
+ throw `locationId not found`;
133
+ }
134
+ else {
135
+ if (data.address) {
136
+ address = data.address;
137
+ }
123
138
  }
124
139
  }
125
- address = {
126
- city: address.city || await Settings.use("city"),
127
- street: address.street,
128
- ...address.streetId && { streetId: address.streetId },
129
- home: address.home,
130
- ...address.housing && { housing: address.housing },
131
- ...address.apartment && { apartment: address.apartment },
132
- ...address.index && { index: address.index },
133
- ...address.entrance && { entrance: address.entrance },
134
- ...address.floor && { floor: address.floor },
135
- ...address.apartment && { apartment: address.apartment },
136
- ...address.comment && { comment: address.comment },
137
- };
138
140
  order.personsCount = data.personsCount ? data.personsCount + "" : "";
139
141
  if (data.comment)
140
142
  order.comment = data.comment;
@@ -150,7 +152,7 @@ exports.default = {
150
152
  if (context && context.connectionParams.authorization) {
151
153
  userId = (await jwt_1.JWTAuth.verify(context.connectionParams.authorization)).userId;
152
154
  }
153
- await Order.check({ id: order.id }, data.customer, isSelfService, data.address, data.paymentMethodId, userId, data.spendBonus !== undefined && userId !== null ? data.spendBonus : null);
155
+ await Order.check({ id: order.id }, data.customer, isSelfService, isSelfService ? undefined : data.address, data.paymentMethodId, userId, data.spendBonus !== undefined && userId !== null ? data.spendBonus : null);
154
156
  order = await Order.findOne(data.orderId);
155
157
  if (order.state === "CHECKOUT" && shouldSendSucessMessage) {
156
158
  message = {
@@ -239,9 +241,7 @@ exports.default = {
239
241
  sendOrder: {
240
242
  def: "sendOrder(orderId: String!): CheckResponse",
241
243
  fn: async function (parent, args, context) {
242
- if (!context.connectionParams.deviceId) {
243
- throw `Missed deviceId`;
244
- }
244
+ (0, checkDeviceId_1.default)(context);
245
245
  let data = args;
246
246
  var order = await Order.findOne({ id: data.orderId });
247
247
  if (!order) {
@@ -13,21 +13,22 @@ import Address from "@webresto/core/interfaces/Address";
13
13
  import Customer from "@webresto/core/interfaces/Customer";
14
14
  import { SpendBonus } from "@webresto/core/interfaces/SpendBonus";
15
15
  import { JWTAuth } from "../../lib/jwt";
16
+ import checkDeviceId from "../../lib/helper/checkDeviceId";
16
17
 
17
18
 
18
19
  interface InputOrderCheckout {
19
- orderId: string
20
- paymentMethodId: string
20
+ orderId: string
21
+ paymentMethodId: string
21
22
  selfService?: boolean
22
- pickupPointId?: string
23
+ pickupPointId?: string
23
24
  address?: Address
24
25
  locationId: string
25
- customer: Customer
26
+ customer: Customer
26
27
  date?: string
27
28
  personsCount?: number
28
29
  comment: string
29
30
  spendBonus: SpendBonus
30
- customData:{[key: string]: string | number}
31
+ customData: { [key: string]: string | number }
31
32
  }
32
33
 
33
34
  graphqlHelper.addType(`#graphql
@@ -66,9 +67,8 @@ export default {
66
67
  fn: async function (parent, args: { orderCheckout: InputOrderCheckout }, context): Promise<CheckResponse> {
67
68
  let data = args.orderCheckout;
68
69
 
69
- if (!context.connectionParams.deviceId) {
70
- throw `Missed deviceId`
71
- }
70
+ checkDeviceId(context);
71
+
72
72
 
73
73
  // if (data.date) {
74
74
  // let date = moment(data.date)
@@ -95,13 +95,30 @@ export default {
95
95
  });
96
96
  }
97
97
 
98
+ let address: Address = null;
99
+
98
100
  //@ts-ignore
99
101
  if (data.selfService) {
100
102
  isSelfService = true;
101
103
  order.pickupPoint = data.pickupPointId;
102
104
  } else {
103
105
  order.pickupPoint = null;
104
- if(!data.address && !data.locationId) throw `Address is required for non self service orders`
106
+ if (!data.address && !data.locationId) throw `Address is required for non self service orders`
107
+
108
+ address = {
109
+ city: address.city || (await Settings.use("city") as string),
110
+ street: address.street,
111
+ ...address.streetId && { streetId: address.streetId },
112
+ home: address.home,
113
+ ...address.housing && { housing: address.housing },
114
+ ...address.apartment && { apartment: address.apartment },
115
+ ...address.index && { index: address.index },
116
+ ...address.entrance && { entrance: address.entrance },
117
+ ...address.floor && { floor: address.floor },
118
+ ...address.apartment && { apartment: address.apartment },
119
+ ...address.comment && { comment: address.comment },
120
+ }
121
+
105
122
  }
106
123
 
107
124
  if (order.state === "ORDER") {
@@ -124,31 +141,18 @@ export default {
124
141
  }
125
142
  }
126
143
 
127
-
128
- if (data.locationId) {
129
- var address: Address = await UserLocation.findOne({id: data.locationId}) as Address;
130
- if (!address) throw `locationId not found`
131
- } else {
132
- if (data.address) {
133
- var address: Address = data.address;
144
+ if(!isSelfService){
145
+ if (data.locationId) {
146
+ address = await UserLocation.findOne({ id: data.locationId }) as Address;
147
+ if (!address) throw `locationId not found`
148
+ } else {
149
+ if (data.address) {
150
+ address = data.address;
151
+ }
134
152
  }
135
153
  }
136
-
137
- address = {
138
- city: address.city || (await Settings.use("city") as string),
139
- street: address.street,
140
- ...address.streetId && {streetId: address.streetId},
141
- home: address.home,
142
- ...address.housing && {housing: address.housing},
143
- ...address.apartment && {apartment: address.apartment},
144
- ...address.index && {index: address.index},
145
- ...address.entrance && {entrance: address.entrance},
146
- ...address.floor && {floor: address.floor},
147
- ...address.apartment && {apartment: address.apartment},
148
- ...address.comment && {comment: address.comment},
149
- }
150
154
 
151
- order.personsCount = data.personsCount ? data.personsCount+"" : "";
155
+ order.personsCount = data.personsCount ? data.personsCount + "" : "";
152
156
  if (data.comment) order.comment = data.comment;
153
157
 
154
158
  order.date = data.date;
@@ -167,17 +171,17 @@ export default {
167
171
  }
168
172
 
169
173
  await Order.check(
170
- {id: order.id},
174
+ { id: order.id },
171
175
  data.customer,
172
176
  isSelfService,
173
- data.address,
177
+ isSelfService ? undefined : data.address,
174
178
  data.paymentMethodId,
175
179
  userId,
176
180
  data.spendBonus !== undefined && userId !== null ? data.spendBonus : null
177
181
  );
178
182
 
179
183
  order = await Order.findOne(data.orderId);
180
-
184
+
181
185
  if (order.state === "CHECKOUT" && shouldSendSucessMessage) {
182
186
  message = {
183
187
  deviceId: context.connectionParams.deviceId,
@@ -201,13 +205,13 @@ export default {
201
205
  }
202
206
  }
203
207
 
204
- if(message){
208
+ if (message) {
205
209
  eventHelper.sendMessage(message);
206
210
  }
207
211
 
208
- return {
209
- order: order,
210
- ...message && { message: message }
212
+ return {
213
+ order: order,
214
+ ...message && { message: message }
211
215
  };
212
216
  } catch (e) {
213
217
  let message = {
@@ -232,11 +236,11 @@ export default {
232
236
  } else if (e.code === 8) {
233
237
  message.message = context.i18n.__("The payment system is not available");
234
238
  } else if (e.code === 11) {
235
- message.message = context.i18n.__(order.delivery.message) ;
239
+ message.message = context.i18n.__(order.delivery.message);
236
240
  } else if (e.code === 10) {
237
241
  message.message = context.i18n.__("The date of execution of the order is not true");
238
242
  } else if (e.code === 15) {
239
- message.message = context.i18n.__("Ordering for a date in the past is not possible");
243
+ message.message = context.i18n.__("Ordering for a date in the past is not possible");
240
244
  } else {
241
245
  message.message = e.error
242
246
  ? e.error
@@ -246,9 +250,9 @@ export default {
246
250
  order = await Order.findOne(data.orderId);
247
251
  sails.log.error(e)
248
252
  eventHelper.sendMessage(message);
249
- return {
253
+ return {
250
254
  order: order,
251
- message: message
255
+ message: message
252
256
  };
253
257
  }
254
258
  },
@@ -256,65 +260,63 @@ export default {
256
260
  sendOrder: {
257
261
  def: "sendOrder(orderId: String!): CheckResponse",
258
262
  fn: async function (parent, args, context) {
259
- if (!context.connectionParams.deviceId) {
260
- throw `Missed deviceId`;
261
- }
263
+ checkDeviceId(context);
262
264
  let data = args;
263
-
265
+
264
266
  var order = await Order.findOne({ id: data.orderId });
265
267
  if (!order) {
266
- const errorMessage = context.i18n.__(`Order with id %s not found`, data.orderId);
267
- eventHelper.sendMessage({
268
- deviceId: context.connectionParams.deviceId,
269
- type: "error",
270
- title: context.i18n.__("Order not found"),
271
- message: errorMessage,
272
- });
273
- sails.log.error(`${errorMessage}`);
274
- throw new Error(errorMessage);
268
+ const errorMessage = context.i18n.__(`Order with id %s not found`, data.orderId);
269
+ eventHelper.sendMessage({
270
+ deviceId: context.connectionParams.deviceId,
271
+ type: "error",
272
+ title: context.i18n.__("Order not found"),
273
+ message: errorMessage,
274
+ });
275
+ sails.log.error(`${errorMessage}`);
276
+ throw new Error(errorMessage);
275
277
  }
276
278
  if (!order.isPaymentPromise) {
277
- try {
278
- let paymentResponse = await Order.payment({ id: order.id });
279
- const action = {
280
- deviceId: context.connectionParams.deviceId,
281
- type: "Redirect",
282
- data: {
283
- link: paymentResponse.redirectLink,
284
- },
285
- };
286
- eventHelper.sendAction(action);
287
- order = await Order.populate({ id: order.id });
288
- return { order: order, action: action };
289
- }
290
- catch (e) {
291
- eventHelper.sendMessage({
292
- deviceId: context.connectionParams.deviceId,
293
- type: "error",
294
- title: context.i18n.__("Error"),
295
- message: context.i18n.__("The payment of the payment has ended unsuccessfully"),
296
- });
297
- const error = `External payment: ${e}`
298
- sails.log.error(error);
299
- throw new Error(error);
300
- }
279
+ try {
280
+ let paymentResponse = await Order.payment({ id: order.id });
281
+ const action = {
282
+ deviceId: context.connectionParams.deviceId,
283
+ type: "Redirect",
284
+ data: {
285
+ link: paymentResponse.redirectLink,
286
+ },
287
+ };
288
+ eventHelper.sendAction(action);
289
+ order = await Order.populate({ id: order.id });
290
+ return { order: order, action: action };
291
+ }
292
+ catch (e) {
293
+ eventHelper.sendMessage({
294
+ deviceId: context.connectionParams.deviceId,
295
+ type: "error",
296
+ title: context.i18n.__("Error"),
297
+ message: context.i18n.__("The payment of the payment has ended unsuccessfully"),
298
+ });
299
+ const error = `External payment: ${e}`
300
+ sails.log.error(error);
301
+ throw new Error(error);
302
+ }
301
303
  }
302
304
 
303
305
  try {
304
- await Order.order({ id: order.id });
305
- order = await Order.findOne({ id: data.orderId });
306
- const message = {
307
- type: "info",
308
- title: context.i18n.__("Successfully"),
309
- message: context.i18n.__("Your order is accepted for processing"),
310
- };
311
- // eventHelper.sendMessage(message);
312
- return { order: order, message: message };
306
+ await Order.order({ id: order.id });
307
+ order = await Order.findOne({ id: data.orderId });
308
+ const message = {
309
+ type: "info",
310
+ title: context.i18n.__("Successfully"),
311
+ message: context.i18n.__("Your order is accepted for processing"),
312
+ };
313
+ // eventHelper.sendMessage(message);
314
+ return { order: order, message: message };
313
315
  }
314
316
  catch (e) {
315
- const error = `Order finalize error:, ${e}`
316
- sails.log.error(error);
317
- throw new Error(error);
317
+ const error = `Order finalize error:, ${e}`
318
+ sails.log.error(error);
319
+ throw new Error(error);
318
320
  }
319
321
  },
320
322
  },
@@ -9,6 +9,7 @@ const graphqlHelper_1 = require("@webresto/graphql/lib/graphqlHelper");
9
9
  (0, graphqlHelper_1.addToReplaceList)("Order.promotionState", "promotionState: [PromotionState]");
10
10
  (0, graphqlHelper_1.addToReplaceList)("Order.pickupPoint", "pickupPoint: PickupPoint");
11
11
  const graphqlHelper_2 = __importDefault(require("../../lib/graphqlHelper"));
12
+ const checkDeviceId_1 = __importDefault(require("../../lib/helper/checkDeviceId"));
12
13
  graphqlHelper_2.default.addType(`#graphql
13
14
  input InputOrderUpdate {
14
15
  id: String!
@@ -330,9 +331,7 @@ exports.default = {
330
331
  };
331
332
  // Generate new cart
332
333
  async function getNewCart(context, orderId) {
333
- if (!context.connectionParams.deviceId) {
334
- throw `Missed deviceId`;
335
- }
334
+ (0, checkDeviceId_1.default)(context);
336
335
  let userId = null;
337
336
  if (context && context.connectionParams.authorization) {
338
337
  userId = (await jwt_1.JWTAuth.verify(context.connectionParams.authorization)).userId;
@@ -7,6 +7,7 @@ import { addToReplaceList } from "@webresto/graphql/lib/graphqlHelper";
7
7
  addToReplaceList("Order.promotionState", "promotionState: [PromotionState]");
8
8
  addToReplaceList("Order.pickupPoint", "pickupPoint: PickupPoint");
9
9
  import graphqlHelper from "../../lib/graphqlHelper";
10
+ import checkDeviceId from "../../lib/helper/checkDeviceId";
10
11
 
11
12
  graphqlHelper.addType(`#graphql
12
13
  input InputOrderUpdate {
@@ -410,9 +411,8 @@ export default {
410
411
  // Generate new cart
411
412
  async function getNewCart(context?: any, orderId?: string) {
412
413
 
413
- if (!context.connectionParams.deviceId) {
414
- throw `Missed deviceId`
415
- }
414
+ checkDeviceId(context);
415
+
416
416
 
417
417
  let userId = null;
418
418
  if (context && context.connectionParams.authorization) {
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const apollo_server_1 = require("apollo-server");
7
+ const checkDeviceId_1 = __importDefault(require("../../lib/helper/checkDeviceId"));
4
8
  exports.default = {
5
9
  Subscription: {
6
10
  order: {
@@ -13,9 +17,7 @@ exports.default = {
13
17
  if (args.deviceId) {
14
18
  context.connectionParams.deviceId = args.deviceId;
15
19
  }
16
- if (!context.connectionParams.deviceId) {
17
- throw `Missed deviceId`;
18
- }
20
+ (0, checkDeviceId_1.default)(context);
19
21
  return context.pubsub.asyncIterator('order-changed');
20
22
  }, (payload, query, context, info) => {
21
23
  return payload.deviceId === context.connectionParams.deviceId;
@@ -36,9 +38,7 @@ exports.default = {
36
38
  if (args.deviceId) {
37
39
  context.connectionParams.deviceId = args.deviceId;
38
40
  }
39
- if (!context.connectionParams.deviceId) {
40
- throw `Missed deviceId`;
41
- }
41
+ (0, checkDeviceId_1.default)(context);
42
42
  return context.pubsub.asyncIterator('message');
43
43
  }, (payload, query, context, info) => {
44
44
  console.log(payload.deviceId, context.connectionParams.deviceId);
@@ -59,9 +59,7 @@ exports.default = {
59
59
  if (args.deviceId) {
60
60
  context.connectionParams.deviceId = args.deviceId;
61
61
  }
62
- if (!context.connectionParams.deviceId) {
63
- throw `Missed deviceId`;
64
- }
62
+ (0, checkDeviceId_1.default)(context);
65
63
  return context.pubsub.asyncIterator('action');
66
64
  }, (payload, query, context, info) => {
67
65
  console.log(payload.deviceId, context.connectionParams.deviceId);
@@ -1,4 +1,5 @@
1
1
  import { withFilter } from 'apollo-server';
2
+ import checkDeviceId from '../../lib/helper/checkDeviceId';
2
3
 
3
4
  export default {
4
5
  Subscription: {
@@ -10,13 +11,12 @@ export default {
10
11
  fn: {
11
12
  subscribe: withFilter(
12
13
  (rootValue, args, context, info) => {
13
- if(args.deviceId) {
14
+ if (args.deviceId) {
14
15
  context.connectionParams.deviceId = args.deviceId;
15
16
  }
16
17
 
17
- if (!context.connectionParams.deviceId) {
18
- throw `Missed deviceId`
19
- }
18
+ checkDeviceId(context);
19
+
20
20
 
21
21
  return context.pubsub.asyncIterator('order-changed')
22
22
  },
@@ -40,13 +40,12 @@ export default {
40
40
  subscribe: withFilter(
41
41
  (rootValue, args, context, info) => {
42
42
 
43
- if(args.deviceId) {
43
+ if (args.deviceId) {
44
44
  context.connectionParams.deviceId = args.deviceId;
45
45
  }
46
46
 
47
- if (!context.connectionParams.deviceId) {
48
- throw `Missed deviceId`
49
- }
47
+ checkDeviceId(context);
48
+
50
49
 
51
50
  return context.pubsub.asyncIterator('message')
52
51
  },
@@ -68,13 +67,12 @@ export default {
68
67
  fn: {
69
68
  subscribe: withFilter(
70
69
  (rootValue, args, context, info) => {
71
- if(args.deviceId) {
70
+ if (args.deviceId) {
72
71
  context.connectionParams.deviceId = args.deviceId;
73
72
  }
74
-
75
- if (!context.connectionParams.deviceId) {
76
- throw `Missed deviceId`
77
- }
73
+
74
+ checkDeviceId(context);
75
+
78
76
 
79
77
  return context.pubsub.asyncIterator('action')
80
78
  },
@@ -8,6 +8,7 @@ const jwt_1 = require("../../lib/jwt");
8
8
  const adapters_1 = require("@webresto/core/adapters");
9
9
  let captchaAdapter = adapters_1.Captcha.getAdapter();
10
10
  const graphqlHelper_1 = __importDefault(require("../../lib/graphqlHelper"));
11
+ const checkDeviceId_1 = __importDefault(require("../../lib/helper/checkDeviceId"));
11
12
  graphqlHelper_1.default.addType(`#graphql
12
13
  type UserResponse {
13
14
  user: User
@@ -67,9 +68,7 @@ exports.default = {
67
68
  if (!payload.otp && !payload.password) {
68
69
  throw `or Password or OTP required`;
69
70
  }
70
- if (!context.connectionParams.deviceId) {
71
- throw `Missed deviceId`;
72
- }
71
+ (0, checkDeviceId_1.default)(context);
73
72
  // Check phone TODO: move in User
74
73
  if ((await Settings.get("LOGIN_FIELD")) === undefined ||
75
74
  (await Settings.get("LOGIN_FIELD")) === "phone") {
@@ -133,9 +132,7 @@ exports.default = {
133
132
  captcha: Captcha!
134
133
  ): UserResponse`,
135
134
  fn: async (parent, payload, context) => {
136
- if (!context.connectionParams.deviceId) {
137
- throw `Missed deviceId`;
138
- }
135
+ (0, checkDeviceId_1.default)(context);
139
136
  // Check password policy
140
137
  let passwordPolicy = (await Settings.get("PASSWORD_POLICY"));
141
138
  if (!passwordPolicy)
@@ -214,9 +211,7 @@ exports.default = {
214
211
  captcha: Captcha!
215
212
  ): UserResponse`,
216
213
  fn: async (parent, payload, context, info) => {
217
- if (!context.connectionParams.deviceId) {
218
- throw `Missed deviceId`;
219
- }
214
+ (0, checkDeviceId_1.default)(context);
220
215
  try {
221
216
  if (!(await captchaAdapter).check(payload.captcha, `registration:${payload.login}`))
222
217
  throw `bad captcha`;
@@ -8,6 +8,7 @@ import { Message, Action, Response } from "../../types/primitives";
8
8
  let captchaAdapter = Captcha.getAdapter();
9
9
 
10
10
  import graphqlHelper from "../../lib/graphqlHelper";
11
+ import checkDeviceId from "../../lib/helper/checkDeviceId";
11
12
 
12
13
  // define UserResponse
13
14
  interface UserResponse extends Response {
@@ -117,9 +118,8 @@ export default {
117
118
  throw `or Password or OTP required`;
118
119
  }
119
120
 
120
- if (!context.connectionParams.deviceId) {
121
- throw `Missed deviceId`;
122
- }
121
+ checkDeviceId(context);
122
+
123
123
 
124
124
  // Check phone TODO: move in User
125
125
  if (
@@ -210,9 +210,8 @@ export default {
210
210
  context: any
211
211
  ): Promise<UserResponse> => {
212
212
 
213
- if (!context.connectionParams.deviceId) {
214
- throw `Missed deviceId`
215
- }
213
+ checkDeviceId(context);
214
+
216
215
 
217
216
  // Check password policy
218
217
  let passwordPolicy = (await Settings.get("PASSWORD_POLICY")) as
@@ -317,9 +316,8 @@ export default {
317
316
  context: any,
318
317
  info: any
319
318
  ): Promise<UserResponse> => {
320
- if (!context.connectionParams.deviceId) {
321
- throw `Missed deviceId`
322
- }
319
+ checkDeviceId(context);
320
+
323
321
 
324
322
  try {
325
323
  if (
@@ -443,7 +441,7 @@ export default {
443
441
  payload: { deviceId: any },
444
442
  context: { connectionParams: { authorization: string }, i18n: any }
445
443
  ): Promise<Response> => {
446
-
444
+
447
445
  const auth = await JWTAuth.verify(
448
446
  context.connectionParams.authorization
449
447
  );
@@ -562,8 +560,8 @@ export default {
562
560
  context.connectionParams.authorization
563
561
  );
564
562
 
565
- let user = await User.updateOne({id: auth.userId}, payload.user)
566
-
563
+ let user = await User.updateOne({ id: auth.userId }, payload.user)
564
+
567
565
  let message: Message = {
568
566
  deviceId: null,
569
567
  title: context.i18n.__("Success"),
@@ -607,7 +605,7 @@ export default {
607
605
  type: "info",
608
606
  message: context.i18n.__("The user will be deleted"),
609
607
  };
610
-
608
+
611
609
  let action: Action = null
612
610
  // Here should be Emmiter for midificate Action And Message
613
611