@webresto/graphql 1.3.7 → 1.4.0

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.
Files changed (142) hide show
  1. package/.gitattributes +2 -0
  2. package/.gitlab-ci.yml +18 -0
  3. package/.vscode/extensions.json +5 -0
  4. package/docs/actions.md +25 -0
  5. package/docs/authorization.md +215 -0
  6. package/docs/captcha.md +71 -0
  7. package/docs/device-id.md +30 -0
  8. package/docs/messages.md +10 -0
  9. package/docs/user.md +54 -0
  10. package/index.d.ts +0 -1
  11. package/index.js +6 -2
  12. package/index.ts +2 -2
  13. package/lib/afterHook.js +8 -0
  14. package/lib/afterHook.ts +9 -0
  15. package/lib/bindTranslations.d.ts +1 -0
  16. package/lib/bindTranslations.js +40 -0
  17. package/lib/bindTranslations.ts +39 -0
  18. package/lib/defaults.d.ts +1 -0
  19. package/lib/defaults.js +49 -10
  20. package/lib/defaults.ts +55 -0
  21. package/lib/eventHelper.d.ts +14 -5
  22. package/lib/eventHelper.js +28 -9
  23. package/lib/eventHelper.ts +41 -8
  24. package/lib/getRecomended.d.ts +1 -0
  25. package/lib/getRecomended.js +29 -0
  26. package/lib/getRecomended.ts +31 -0
  27. package/lib/graphqlHelper.d.ts +3 -4
  28. package/lib/graphqlHelper.js +184 -72
  29. package/lib/graphqlHelper.ts +329 -185
  30. package/lib/jwt.d.ts +10 -0
  31. package/lib/jwt.js +43 -0
  32. package/lib/jwt.ts +61 -0
  33. package/package.json +15 -7
  34. package/src/additionalResolvers.d.ts +72 -9
  35. package/src/additionalResolvers.js +93 -24
  36. package/src/additionalResolvers.ts +105 -34
  37. package/src/graphql.d.ts +5 -3
  38. package/src/graphql.js +170 -37
  39. package/src/graphql.ts +210 -60
  40. package/src/resolvers/bonusProgram.d.ts +32 -0
  41. package/src/resolvers/bonusProgram.js +65 -0
  42. package/src/resolvers/bonusProgram.ts +79 -0
  43. package/src/resolvers/captcha.d.ts +11 -0
  44. package/src/resolvers/captcha.js +19 -0
  45. package/src/resolvers/captcha.ts +16 -0
  46. package/src/resolvers/checkout.d.ts +35 -16
  47. package/src/resolvers/checkout.js +171 -94
  48. package/src/resolvers/checkout.ts +214 -104
  49. package/src/resolvers/dishAndModifier.js +8 -4
  50. package/src/resolvers/dishAndModifier.ts +4 -0
  51. package/src/resolvers/error.d.ts +9 -0
  52. package/src/resolvers/error.js +21 -0
  53. package/src/resolvers/error.ts +21 -0
  54. package/src/resolvers/menu.d.ts +9 -0
  55. package/src/resolvers/menu.js +12 -0
  56. package/src/resolvers/menu.ts +10 -0
  57. package/src/resolvers/order.d.ts +527 -0
  58. package/src/resolvers/order.js +349 -0
  59. package/src/resolvers/order.ts +435 -0
  60. package/src/resolvers/paymentMethod.js +7 -3
  61. package/src/resolvers/paymentMethod.ts +9 -5
  62. package/src/resolvers/pickupPoint.d.ts +1 -0
  63. package/src/resolvers/pickupPoint.js +24 -0
  64. package/src/resolvers/pickupPoint.ts +23 -0
  65. package/src/resolvers/recomended.d.ts +13 -0
  66. package/src/resolvers/recomended.js +80 -0
  67. package/src/resolvers/recomended.ts +86 -0
  68. package/src/resolvers/restrictions.d.ts +37 -1
  69. package/src/resolvers/restrictions.js +100 -15
  70. package/src/resolvers/restrictions.ts +106 -14
  71. package/src/resolvers/streets.d.ts +1 -1
  72. package/src/resolvers/streets.js +1 -4
  73. package/src/resolvers/streets.ts +1 -3
  74. package/src/resolvers/subscriptions.d.ts +4 -4
  75. package/src/resolvers/subscriptions.js +49 -12
  76. package/src/resolvers/subscriptions.ts +59 -14
  77. package/src/resolvers/telemetry.d.ts +14 -0
  78. package/src/resolvers/telemetry.js +25 -0
  79. package/src/resolvers/telemetry.ts +24 -0
  80. package/src/resolvers/user.d.ts +82 -0
  81. package/src/resolvers/user.js +416 -0
  82. package/src/resolvers/user.ts +621 -0
  83. package/src/resolvers/userLocation.d.ts +53 -0
  84. package/src/resolvers/userLocation.js +74 -0
  85. package/src/resolvers/userLocation.ts +125 -0
  86. package/src/resolvers/userOTPrequest.d.ts +21 -0
  87. package/src/resolvers/userOTPrequest.js +57 -0
  88. package/src/resolvers/userOTPrequest.ts +75 -0
  89. package/test/e2e_helper.js +157 -0
  90. package/test/e2e_helper.ts +212 -0
  91. package/test/fixture/config/i18n.js +7 -20
  92. package/test/fixture/config/locales/de.json +1 -0
  93. package/test/fixture/config/locales/en.json +10 -0
  94. package/test/fixture/config/locales/es.json +3 -0
  95. package/test/fixture/config/locales/fr.json +1 -0
  96. package/test/fixture/config/log.js +1 -1
  97. package/test/fixture/package.json +5 -6
  98. package/test/fixture/patches/rttc+10.0.1.patch +17 -0
  99. package/test/integration/captcha.test.js +20 -0
  100. package/test/integration/captcha.test.ts +25 -0
  101. package/test/integration/dish.test.js +35 -0
  102. package/test/integration/dish.test.ts +43 -0
  103. package/test/integration/graphql.test.js +5 -2
  104. package/test/integration/graphql.test.ts +2 -4
  105. package/test/integration/images.test.js +35 -0
  106. package/test/integration/images.test.ts +40 -0
  107. package/test/integration/locale.test.js +26 -0
  108. package/test/integration/locale.test.ts +32 -0
  109. package/test/integration/order.test.js +56 -43
  110. package/test/integration/order.test.ts +59 -59
  111. package/test/integration/subscriptions.test.js +136 -0
  112. package/test/integration/subscriptions.test.ts +162 -0
  113. package/test/integration/user.test.js +249 -0
  114. package/test/integration/user.test.ts +299 -0
  115. package/test/unit/first.test.js +4 -2
  116. package/test/unit/first.test.ts +1 -1
  117. package/test/unit/get-recomended.test.js +56 -0
  118. package/test/unit/get-recomended.test.ts +63 -0
  119. package/translations/de.json +2 -0
  120. package/translations/en.json +3 -0
  121. package/translations/es.json +3 -0
  122. package/translations/fr.json +2 -0
  123. package/translations/ru.json +36 -0
  124. package/tsconfig.json +20 -5
  125. package/types/global.d.ts +30 -0
  126. package/types/global.js +2 -0
  127. package/types/global.ts +31 -0
  128. package/types/primitives.d.ts +19 -0
  129. package/types/references.d.ts +1 -0
  130. package/types/restoGraphQLConfig.d.ts +13 -0
  131. package/lib/afterHook.ts___graphql-transport-ws +0 -138
  132. package/lib/afterHook.ts___graphql-ws +0 -133
  133. package/lib/errorWrapper.d.ts +0 -4
  134. package/lib/errorWrapper.js +0 -13
  135. package/lib/errorWrapper.ts +0 -12
  136. package/notes.md +0 -1976
  137. package/src/resolvers/cart.d.ts +0 -343
  138. package/src/resolvers/cart.js +0 -196
  139. package/src/resolvers/cart.ts +0 -278
  140. package/test/fixture/config/connections.js +0 -9
  141. package/test/integration/sails_not_crash.test.js +0 -3
  142. package/test/integration/sails_not_crash.test.ts +0 -3
@@ -0,0 +1,435 @@
1
+ import * as eventHelper from "@webresto/graphql";
2
+ import checkExpression from "@webresto/core/libs/checkExpression";
3
+ import Order from "@webresto/core/models/Order"
4
+ import { JWTAuth } from "../../lib/jwt";
5
+
6
+ import { addToReplaceList } from "@webresto/graphql/lib/graphqlHelper";
7
+ addToReplaceList("Order.promotionState", "promotionState: [PromotionState]");
8
+ addToReplaceList("Order.pickupPoint", "pickupPoint: PickupPoint");
9
+ import graphqlHelper from "../../lib/graphqlHelper";
10
+
11
+ graphqlHelper.addType(`#graphql
12
+ input InputOrderUpdate {
13
+ id: String!
14
+ trifleFrom: Int
15
+ comment: String
16
+ date: String
17
+ isSelfService: Boolean
18
+ paymentMethodId: String
19
+ promotionCodeString: String
20
+ }
21
+ `);
22
+
23
+ export default {
24
+ Query: {
25
+ order: {
26
+ def: `#graphql
27
+ """ if orderId is not set, a new cart will be returned """
28
+ order(orderId: String, shortId: String, orderNumber: String): Order`,
29
+
30
+ fn: async function (parent, args, context) {
31
+ let order;
32
+
33
+ let criteria = {};
34
+ if (args.orderNumber) {
35
+ criteria["rmsOrderNumber"] = args.orderNumber;
36
+ criteria["sort"] = "createdAt DESC";
37
+ } else if (args.orderId) {
38
+ criteria["id"] = args.orderId;
39
+ } else if (args.shortId) {
40
+ criteria["shortId"] = args.shortId;
41
+ }
42
+
43
+ if (Object.keys(criteria).length !== 0) {
44
+ order = (await Order.find(criteria))[0];
45
+ }
46
+
47
+ if (!order) {
48
+ sails.log.silly(
49
+ "GQL > order resolver error: ",
50
+ `order with id ${args.orderId} not found. Trying make new cart.`
51
+ );
52
+ order = await getNewCart(context, args.orderId);
53
+ }
54
+
55
+ let fullOrder = await Order.populate(order.id);
56
+ emitter.emit("http-api:before-response-order", fullOrder);
57
+ return fullOrder
58
+ },
59
+ },
60
+ },
61
+ Mutation: {
62
+ orderAddDish: {
63
+ def: "orderAddDish(orderId: String, dishId: String, amount: Int, modifiers: Json, comment: String, from: String, replace: Boolean, orderDishId: Int): Order",
64
+ fn: async function (parent, args, context) {
65
+ let order;
66
+
67
+
68
+
69
+ if (args.modifiers) {
70
+ args.modifiers.forEach((modifier) => {
71
+ if (modifier.amount === undefined || modifier.id === undefined){
72
+ const error = `modifier required (amount, id) for dish: ${args.dishId} current values: id: ${modifier.id}, amount: ${modifier.amount}`
73
+ sails.log(error)
74
+ throw new Error(error);
75
+ }
76
+ });
77
+ }
78
+
79
+ if (args.orderId) order = await Order.findOne({ id: args.orderId });
80
+
81
+ if (!order) {
82
+ sails.log.silly(
83
+ "GQL > orderAddDish resolver error: ",
84
+ `order with id ${args.orderId} not found. Trying make new cart.`
85
+ );
86
+ order = await getNewCart(context, args.orderId);
87
+ }
88
+
89
+ const dish = await Dish.findOne({ id: args.dishId });
90
+
91
+ if (!dish && !args.replace)
92
+ throw `dish with id ${args.dishId} not found`;
93
+
94
+ if (dish && checkExpression(dish) === "promo") {
95
+ let additionalInfo;
96
+ try {
97
+ additionalInfo = JSON.parse(dish.additionalInfo);
98
+ } catch (e) {}
99
+
100
+ if (additionalInfo && additionalInfo.defaultOrderDish) {
101
+ // Исключение на товар в каждую корзину
102
+ } else {
103
+ const error = `"${dish.name}" not promo item`
104
+ sails.log(error)
105
+ throw new Error(error);
106
+ }
107
+ }
108
+
109
+ try {
110
+ await Order.addDish(
111
+ order.id,
112
+ args.dishId,
113
+ args.amount,
114
+ args.modifiers === undefined ? [] : args.modifiers,
115
+ args.comment,
116
+ 'user',
117
+ args.replace,
118
+ args.orderDishId
119
+ );
120
+ } catch (error) {
121
+ if(await Settings.get("PASS_ORDERS_ERRORS") === "TRUE") {
122
+ throw error
123
+ } else {
124
+ // TODO: need think about it, it not clean
125
+ order = await getNewCart(context);
126
+ }
127
+ }
128
+
129
+ await Order.countCart({id: order.id});
130
+ let fullOrder = await Order.populate(order.id);
131
+ emitter.emit("http-api:before-response-order-add-dish", fullOrder);
132
+ return fullOrder
133
+ },
134
+ },
135
+ orderReplaceDish: {
136
+ def: "orderReplaceDish(orderId: String!, orderDishId: Int!, amount: Int, modifiers: Json, comment: String, from: String): Order",
137
+ fn: async (parent, args, context) => {
138
+ let order;
139
+ if (args.orderId) order = await Order.findOne({ id: args.orderId });
140
+
141
+ if (!order) {
142
+ sails.log.silly(
143
+ "GQL > orderReplaceDish resolver error: ",
144
+ `order with id ${args.orderId} not found. Trying make new cart.`
145
+ );
146
+ order = await getNewCart(context, args.orderId);
147
+ }
148
+
149
+ if (order.paid || order.state === "ORDER") {
150
+ order = await getNewCart();
151
+ }
152
+
153
+ try {
154
+ await Order.addDish(
155
+ order.id,
156
+ args.dishId,
157
+ args.amount,
158
+ args.modifiers === undefined ? [] : args.modifiers,
159
+ args.comment,
160
+ args.from,
161
+ args.replace,
162
+ args.orderDishId
163
+ );
164
+ } catch (error) {
165
+ if(await Settings.get("PASS_ORDERS_ERRORS") === "TRUE") {
166
+ throw error
167
+ } else {
168
+ // TODO: need think about it, it not clean
169
+ order = await getNewCart(context);
170
+ }
171
+ }
172
+
173
+ await Order.countCart({id: order.id});
174
+ let fullOrder = await Order.populate(order.id);
175
+ emitter.emit("http-api:before-response-order-replace-dish", fullOrder);
176
+ return fullOrder
177
+ },
178
+ },
179
+ orderRemoveDish: {
180
+ def: "orderRemoveDish(id: String!, orderDishId: Int!, amount: Int): Order",
181
+ fn: async function (parent, args, context) {
182
+ let order;
183
+ order = await Order.findOne({ id: args.id });
184
+
185
+ if (!order) {
186
+ sails.log.silly(
187
+ "GQL > orderRemoveDish resolver error: ",
188
+ `order with id ${args.orderId} not found. Trying make new cart.`
189
+ );
190
+ order = await getNewCart(context, args.orderId);
191
+ }
192
+
193
+ if (order.paid || order.state === "ORDER") {
194
+ order = await getNewCart();
195
+ }
196
+
197
+ const orderDish = await OrderDish.findOne({ id: args.orderDishId });
198
+
199
+ try {
200
+ await Order.removeDish(order.id, orderDish, args.amount, false);
201
+ } catch (error) {
202
+ if(await Settings.get("PASS_ORDERS_ERRORS") === "TRUE") {
203
+ throw error
204
+ } else {
205
+ // TODO: need think about it, it not clean
206
+ order = await getNewCart(context);
207
+ }
208
+ }
209
+
210
+
211
+ await Order.countCart({id: order.id});
212
+ let fullOrder = await Order.populate(order.id);
213
+ emitter.emit("http-api:before-response-order-remove-dish", fullOrder);
214
+ return fullOrder
215
+ },
216
+ },
217
+ orderSetDishAmount: {
218
+ def: "orderSetDishAmount(id: String, orderDishId: Int, amount: Int): Order",
219
+ fn: async function (parent, args, context) {
220
+ let order;
221
+
222
+ order = await Order.findOne(args.id);
223
+
224
+ if (!order) {
225
+ sails.log.silly(
226
+ "GQL > orderSetDishAmount resolver error: ",
227
+ `order with id ${args.orderId} not found. Trying make new cart.`
228
+ );
229
+ order = await getNewCart(context, args.orderId);
230
+ }
231
+
232
+ if (order.paid || order.state === "ORDER") {
233
+ order = await getNewCart();
234
+ }
235
+
236
+ let dish = await OrderDish.findOne(args.orderDishId).populate("dish");
237
+ if (!dish){
238
+ const error = `OrderDish with id ${args.orderDishId} not found`;
239
+ sails.log.error(error)
240
+ throw new Error(error);
241
+ }
242
+ if (!dish.dish) {
243
+ const error = `Dish in OrderDish with id ${args.orderDishId} not found`;
244
+ sails.log.error(error)
245
+ throw new Error(error);
246
+ }
247
+
248
+ try {
249
+ await Order.setCount(order.id, dish, args.amount);
250
+ } catch (error) {
251
+ if(await Settings.get("PASS_ORDERS_ERRORS") === "TRUE") {
252
+ throw error
253
+ } else {
254
+ // TODO: need think about it, it not clean
255
+ order = await getNewCart(context);
256
+ }
257
+ }
258
+
259
+ await Order.countCart({id: order.id});
260
+ let fullOrder = await Order.populate(order.id);
261
+ emitter.emit("http-api:before-response-order-set-dish-amount", fullOrder);
262
+ return fullOrder
263
+ },
264
+ },
265
+ orderSetDishComment: {
266
+ def: "orderSetDishComment(id: String, orderDishId: Int, comment: String): Order",
267
+ fn: async function (parent, args, context) {
268
+ let order;
269
+
270
+ const data = args;
271
+ const orderId = data.orderId;
272
+ const comment = data.comment || "";
273
+ const dishId = data.dishId;
274
+ if (!dishId) {
275
+ const error = "dishId is required";
276
+ sails.log.error(error)
277
+ throw new Error(error);
278
+ }
279
+
280
+ order = await Order.findOne(orderId);
281
+
282
+ if (!order) {
283
+ sails.log.silly(
284
+ "GQL > orderSetDishComment resolver error: ",
285
+ `order with id ${args.orderId} not found. Trying make new cart.`
286
+ );
287
+ order = await getNewCart(context, args.orderId);
288
+ }
289
+
290
+ if (order.paid || order.state === "ORDER") {
291
+ order = await getNewCart();
292
+ }
293
+
294
+ const dish = await OrderDish.findOne({ id: dishId }).populate("dish");
295
+ if (!dish) {
296
+ const error = `Dish with id ${dishId} not found`
297
+ sails.log.error(error)
298
+ throw new Error(error);
299
+ }
300
+
301
+ await order.setComment(dish, comment);
302
+ await Order.countCart({id: order.id});
303
+ let fullOrder = await Order.populate(order.id);
304
+ emitter.emit("http-api:before-response-order-set-dish-comment", fullOrder);
305
+ return fullOrder
306
+ },
307
+ },
308
+
309
+ orderUpdate: {
310
+ def: '"""Experimental! allowed only for trifleFrom """ orderUpdate(order: InputOrderUpdate): Order',
311
+ fn: async function (parent, args, context) {
312
+
313
+ let order = args.order;
314
+ if (!order.id) throw "order.id field is required"
315
+ let _order = await Order.findOne(order.id);
316
+
317
+ if(['CART', 'CHECKOUT', 'PAYMENT'].includes(_order.state) !== true) {
318
+ throw `Order in state [${order.state}] update not allowed`
319
+ }
320
+
321
+ let orderToCartState = false;
322
+
323
+ if(Object.keys(order).length === 1) {
324
+ throw `no passed updates`
325
+ }
326
+
327
+ const orderUpd = {}
328
+ if(order.trifleFrom) {
329
+ orderUpd['trifleFrom'] = order.trifleFrom
330
+ }
331
+
332
+ if(order.comment) {
333
+ orderUpd['comment'] = order.comment
334
+ }
335
+
336
+ if(order.date) {
337
+ orderUpd['date'] = order.date
338
+ orderToCartState = true
339
+ }
340
+
341
+ if(order.isSelfService) {
342
+ orderUpd['isSelfService'] = order.isSelfService
343
+ orderToCartState = true
344
+ }
345
+
346
+ if(order.paymentMethodId) {
347
+ orderUpd['paymentMethodId'] = order.paymentMethodId
348
+ orderToCartState = true
349
+ }
350
+
351
+ if(order.promotionCodeString || order.promotionCodeString === ""){
352
+ await Order.applyPromotionCode({id: order.id}, order.promotionCodeString)
353
+ delete order.promotionCodeString;
354
+ }
355
+
356
+ if(Object.keys(order).length > 1){
357
+ await Order.update({id: order.id}, orderUpd)
358
+ }
359
+
360
+ // TODO: Need move logic update in Order Model
361
+ if(orderToCartState) {
362
+ await Order.next("CART")
363
+ }
364
+
365
+ let fullOrder = await Order.populate(order.id);
366
+ emitter.emit("http-api:before-response-order-update", fullOrder);
367
+ return fullOrder
368
+ },
369
+ },
370
+
371
+ orderClone: {
372
+ def: 'orderClone(orderId: String!): Order',
373
+ fn: async function (parent, args, context) {
374
+
375
+ let orderId = args.orderId;
376
+ let newcart = await Order.clone({id: orderId});
377
+ let fullOrder = await Order.populate({id: newcart.id});
378
+ emitter.emit("http-api:before-response-order-update", fullOrder);
379
+ return fullOrder
380
+ },
381
+ },
382
+
383
+ orderPromocodeApply: {
384
+ def: 'orderPromocodeApply(orderId: String!, promocode: String!): Order',
385
+ fn: async function (parent, args, context) {
386
+ let orderId = args.orderId;
387
+ let promocode = args.promocode;
388
+ await Order.applyPromotionCode({id: orderId}, promocode)
389
+ let fullOrder = await Order.populate({id: orderId});
390
+ emitter.emit("http-api:before-response-order-update", fullOrder);
391
+ return fullOrder
392
+ },
393
+ },
394
+
395
+ orderPromocodeReset: {
396
+ def: 'orderPromocodeReset(orderId: String!): Order',
397
+ fn: async function (parent, args, context) {
398
+ let orderId = args.orderId;
399
+ let promocode = null;
400
+ await Order.applyPromotionCode({id: orderId}, promocode)
401
+ let fullOrder = await Order.populate({id: orderId});
402
+ emitter.emit("http-api:before-response-order-update", fullOrder);
403
+ return fullOrder
404
+ },
405
+ },
406
+
407
+ },
408
+ };
409
+
410
+ // Generate new cart
411
+ async function getNewCart(context?: any, orderId?: string) {
412
+
413
+ if (!context.connectionParams.deviceId) {
414
+ throw `Missed deviceId`
415
+ }
416
+
417
+ let userId = null;
418
+ if (context && context.connectionParams.authorization) {
419
+ userId = (await JWTAuth.verify(context.connectionParams.authorization)).userId;
420
+ }
421
+
422
+ let order: any;
423
+ let initOrder: Order = {};
424
+
425
+ // Pass oredrId from frontend
426
+ if (orderId) initOrder["id"] = orderId;
427
+ if (userId) initOrder["user"] = userId;
428
+ initOrder.deviceId = context.connectionParams.deviceId
429
+
430
+ emitter.emit("http-api:init-newcart", initOrder);
431
+ order = await Order.create(initOrder).fetch();
432
+ await emitter.emit("http-api:create-newcart", order);
433
+
434
+ return order;
435
+ }
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const getEmitter_1 = require("@webresto/core/libs/getEmitter");
4
3
  exports.default = {
5
4
  Query: {
6
5
  paymentMethod: {
@@ -8,13 +7,18 @@ exports.default = {
8
7
  fn: async function (parent, args, context) {
9
8
  const orderId = args.orderId;
10
9
  try {
10
+ const order = await Order.findOne({ id: orderId });
11
+ if (!order) {
12
+ // TODO: implement logic for event
13
+ console.log(`order not found`);
14
+ }
11
15
  const data = await PaymentMethod.getAvailable();
12
- await getEmitter_1.default().emit('graphql-return-payment-method', orderId, data);
16
+ await emitter.emit('graphql-return-payment-method', orderId, data);
13
17
  return data;
14
18
  }
15
19
  catch (e) {
16
20
  sails.log.error(e);
17
- throw new Error(0, JSON.stringify(e));
21
+ throw `${JSON.stringify(e)}`;
18
22
  }
19
23
  }
20
24
  }
@@ -1,5 +1,3 @@
1
- import getEmitter from "@webresto/core/libs/getEmitter";
2
-
3
1
  export default {
4
2
  Query: {
5
3
  paymentMethod: {
@@ -7,12 +5,18 @@ export default {
7
5
  fn: async function (parent, args, context) {
8
6
  const orderId = args.orderId;
9
7
  try {
8
+ const order = await Order.findOne({id: orderId});
9
+ if(!order) {
10
+ // TODO: implement logic for event
11
+ console.log(`order not found`)
12
+ }
13
+
10
14
  const data = await PaymentMethod.getAvailable();
11
- await getEmitter().emit('graphql-return-payment-method', orderId, data);
15
+ await emitter.emit('graphql-return-payment-method', orderId, data);
12
16
  return data;
13
17
  } catch (e) {
14
- sails.log.error(e); throw new Error(0, JSON.stringify(e));
15
-
18
+ sails.log.error(e);
19
+ throw `${JSON.stringify(e)}`
16
20
  }
17
21
  }
18
22
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const graphqlHelper_1 = require("@webresto/graphql/lib/graphqlHelper");
4
+ (0, graphqlHelper_1.addType)(`type PickupPoint {
5
+ id: String
6
+ title: String
7
+ address: String
8
+ order: Int
9
+ enable: Boolean
10
+ worktime: Json
11
+ active: Boolean
12
+ phone: String
13
+ }`);
14
+ exports.default = {
15
+ Query: {
16
+ pickuppoints: {
17
+ def: "pickuppoints: [PickupPoint]",
18
+ fn: async () => {
19
+ let result = await Place.find({ isPickupPoint: true, enable: true });
20
+ return result;
21
+ }
22
+ }
23
+ }
24
+ };
@@ -0,0 +1,23 @@
1
+ import { addType } from "@webresto/graphql/lib/graphqlHelper"
2
+ addType(`type PickupPoint {
3
+ id: String
4
+ title: String
5
+ address: String
6
+ order: Int
7
+ enable: Boolean
8
+ worktime: Json
9
+ active: Boolean
10
+ phone: String
11
+ }`);
12
+
13
+ exports.default = {
14
+ Query: {
15
+ pickuppoints: {
16
+ def: "pickuppoints: [PickupPoint]",
17
+ fn: async () => {
18
+ let result = await Place.find({ isPickupPoint: true, enable: true });
19
+ return result;
20
+ }
21
+ }
22
+ }
23
+ };
@@ -0,0 +1,13 @@
1
+ declare const _default: {
2
+ Query: {
3
+ recomendedForDish: {
4
+ def: string;
5
+ fn: (parent: any, args: any, context: any) => Promise<any[]>;
6
+ };
7
+ recomendedForOrder: {
8
+ def: string;
9
+ fn: (parent: any, args: any, context: any) => Promise<any[]>;
10
+ };
11
+ };
12
+ };
13
+ export default _default;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getRecomended_1 = require("../../lib/getRecomended");
4
+ exports.default = {
5
+ Query: {
6
+ recomendedForDish: {
7
+ def: 'recomendedForDish(dishId: String): [Dish]',
8
+ fn: async function (parent, args, context) {
9
+ try {
10
+ let criteria = {};
11
+ const RECOMENDED_GROUPID_FOR_DISHES = await Settings.get("RECOMENDED_GROUPID_FOR_DISHES");
12
+ let defaultGroup = null;
13
+ let listOfAllowedGroups = null;
14
+ if (RECOMENDED_GROUPID_FOR_DISHES) {
15
+ defaultGroup = await Group.find({ id: RECOMENDED_GROUPID_FOR_DISHES });
16
+ listOfAllowedGroups = await Group.getMenuTree(defaultGroup);
17
+ }
18
+ else {
19
+ listOfAllowedGroups = await Group.getMenuTree();
20
+ }
21
+ let dish = await Dish.findOne({ id: args.dishId });
22
+ criteria['where'] = {
23
+ 'and': [
24
+ { 'parentGroup': { 'in': listOfAllowedGroups } },
25
+ { 'balance': { "!=": 0 } },
26
+ { 'modifier': false },
27
+ { 'isDeleted': false }
28
+ ]
29
+ };
30
+ if (dish) {
31
+ criteria['where']['and'].push({ 'parentGroup': { "!=": dish.parentGroup } });
32
+ }
33
+ const array = await Dish.find(criteria);
34
+ return (0, getRecomended_1.getRecomendElements)(array, 7);
35
+ }
36
+ catch (e) {
37
+ sails.log.error(e);
38
+ throw `${JSON.stringify(e)}`;
39
+ }
40
+ }
41
+ },
42
+ recomendedForOrder: {
43
+ def: 'recomendedForOrder(orderId: String): [Dish]',
44
+ fn: async function (parent, args, context) {
45
+ try {
46
+ const RECOMENDED_GROUPID_FOR_ORDER = await Settings.get("RECOMENDED_GROUPID_FOR_ORDER");
47
+ let orderDishes = await OrderDish.find({ order: args.orderId });
48
+ const orderDishIds = orderDishes.map(orderDish => orderDish.dish);
49
+ let criteria = {};
50
+ let defaultGroup = null;
51
+ let listOfAllowedGroups = null;
52
+ if (RECOMENDED_GROUPID_FOR_ORDER) {
53
+ defaultGroup = await Group.find({ id: RECOMENDED_GROUPID_FOR_ORDER });
54
+ listOfAllowedGroups = await Group.getMenuTree(defaultGroup);
55
+ }
56
+ else {
57
+ listOfAllowedGroups = await Group.getMenuTree();
58
+ }
59
+ criteria['where'] = {
60
+ 'and': [
61
+ { 'parentGroup': { 'in': listOfAllowedGroups } },
62
+ { 'balance': { "!=": 0 } },
63
+ { 'modifier': false },
64
+ { 'isDeleted': false }
65
+ ]
66
+ };
67
+ if (orderDishIds.length) {
68
+ criteria["where"]["and"].push({ id: { "!=": orderDishIds } });
69
+ }
70
+ const allDishes = await Dish.find(criteria);
71
+ return (0, getRecomended_1.getRecomendElements)(allDishes, 7);
72
+ }
73
+ catch (e) {
74
+ sails.log.error(e);
75
+ throw `${JSON.stringify(e)}`;
76
+ }
77
+ }
78
+ }
79
+ }
80
+ };