@webresto/graphql 1.3.6 → 1.3.8

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 -73
  29. package/lib/graphqlHelper.ts +329 -186
  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 +13 -6
  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 +43 -14
  47. package/src/resolvers/checkout.js +172 -122
  48. package/src/resolvers/checkout.ts +218 -142
  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 -277
  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
@@ -1,13 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const eventHelper = require("../../lib/eventHelper");
4
- const errorWrapper_1 = require("../../lib/errorWrapper");
4
+ const graphqlHelper_1 = require("../../lib/graphqlHelper");
5
+ const jwt_1 = require("../../lib/jwt");
6
+ graphqlHelper_1.default.addType(`#graphql
7
+ input InputOrderCheckout {
8
+ orderId: String!
9
+ paymentMethodId: String!
10
+ customer: Customer!
11
+ spendBonus: InputSpendBonus
12
+ selfService: Boolean
13
+ pickupPointId: String
14
+ locationId: String
15
+ address: Address
16
+ date: String
17
+ comment: String
18
+ personsCount: Int
19
+ customData: Json
20
+ }
21
+ `);
22
+ graphqlHelper_1.default.addType(`#graphql
23
+ input InputSpendBonus {
24
+ bonusProgramId: String!
25
+ amount: Int!
26
+ adapter: String!
27
+ bonusProgramName: String!
28
+ }
29
+ `);
5
30
  exports.default = {
6
31
  Mutation: {
7
32
  checkOrder: {
8
- def: "checkOrder(orderId: String!, paymentMethodId: String!, selfService: Boolean, address: Address, customer: Customer!, date: String, comment: String, customData: Json): CheckResponse",
33
+ def: `#graphql
34
+ checkOrder(orderCheckout: InputOrderCheckout): CheckResponse`,
9
35
  fn: async function (parent, args, context) {
10
- let data = args;
36
+ let data = args.orderCheckout;
37
+ if (!context.connectionParams.deviceId) {
38
+ throw `Missed deviceId`;
39
+ }
11
40
  // if (data.date) {
12
41
  // let date = moment(data.date)
13
42
  // if(!date.isValid()){
@@ -17,209 +46,230 @@ exports.default = {
17
46
  // }
18
47
  // }
19
48
  let isSelfService;
20
- //@ts-ignore
21
- if (data.selfService || data.selfDelivery) {
22
- isSelfService = true;
23
- }
49
+ let message;
24
50
  try {
25
51
  var order = await Order.findOne(data.orderId);
52
+ const shouldSendSucessMessage = order.state !== "CHECKOUT";
26
53
  if (!order) {
27
- return eventHelper.sendMessage(args.orderId, {
54
+ message = eventHelper.sendMessage({
55
+ deviceId: context.connectionParams.deviceId,
28
56
  type: "error",
29
- title: "Order not found",
30
- message: `Order with id ${data.orderId} not found`,
57
+ title: context.i18n.__("Order not found"),
58
+ message: context.i18n.__("Order with id %s not found", data.orderId),
31
59
  });
32
60
  }
61
+ //@ts-ignore
62
+ if (data.selfService) {
63
+ isSelfService = true;
64
+ order.pickupPoint = data.pickupPointId;
65
+ }
66
+ else {
67
+ order.pickupPoint = null;
68
+ if (!data.address && !data.locationId)
69
+ throw `Address is required for non self service orders`;
70
+ }
33
71
  if (order.state === "ORDER") {
34
- return eventHelper.sendMessage(args.orderId, {
72
+ message = eventHelper.sendMessage({
73
+ deviceId: context.connectionParams.deviceId,
35
74
  type: "error",
36
- title: "Ошибка",
37
- message: "Корзина уже заказана",
75
+ title: context.i18n.__("Error"),
76
+ message: context.i18n.__("Cart was ordered"),
38
77
  });
39
78
  }
40
79
  if (data.paymentMethodId) {
41
80
  if (!PaymentMethod.checkAvailable(data.paymentMethodId)) {
42
- return eventHelper.sendMessage(args.orderId, {
81
+ message = eventHelper.sendMessage({
82
+ deviceId: context.connectionParams.deviceId,
43
83
  type: "error",
44
- title: "Ошибка",
45
- message: "Проверка платежной системы завершилась неудачей",
84
+ title: context.i18n.__("Error"),
85
+ message: context.i18n.__("Checking the payment system ended in failure"),
46
86
  });
47
87
  }
48
88
  }
49
- if (data.address) {
50
- data.address.city =
51
- data.address.city || (await Settings.use("city"));
89
+ if (data.locationId) {
90
+ var address = await UserLocation.findOne({ id: data.locationId });
91
+ if (!address)
92
+ throw `locationId not found`;
93
+ }
94
+ else {
95
+ if (data.address) {
96
+ var address = data.address;
97
+ }
52
98
  }
53
- order.personsCount = data.personsCount ? data.personsCount : "";
99
+ address = {
100
+ city: address.city || await Settings.use("city"),
101
+ street: address.street,
102
+ ...address.streetId && { streetId: address.streetId },
103
+ home: address.home,
104
+ ...address.housing && { housing: address.housing },
105
+ ...address.apartment && { apartment: address.apartment },
106
+ ...address.index && { index: address.index },
107
+ ...address.entrance && { entrance: address.entrance },
108
+ ...address.floor && { floor: address.floor },
109
+ ...address.apartment && { apartment: address.apartment },
110
+ ...address.comment && { comment: address.comment },
111
+ };
112
+ order.personsCount = data.personsCount ? data.personsCount + "" : "";
54
113
  if (data.comment)
55
114
  order.comment = data.comment;
56
- if (data.date)
57
- order.date = data.date;
58
- // callback: boolean - перезвонить для уточнения деталей
115
+ order.date = data.date;
116
+ // callback: boolean -call back to clarify details
59
117
  if (data.customData && data.customData.callback) {
60
118
  if (!order.customData)
61
119
  order.customData = {};
62
120
  order.customData.callback = data.customData.callback;
63
121
  }
64
122
  await Order.update({ id: order.id }, order).fetch();
65
- await Order.check(order.id, data.customer, isSelfService, data.address, data.paymentMethodId);
123
+ let userId = null;
124
+ if (context && context.connectionParams.authorization) {
125
+ userId = (await jwt_1.JWTAuth.verify(context.connectionParams.authorization)).userId;
126
+ }
127
+ await Order.check({ id: order.id }, data.customer, isSelfService, data.address, data.paymentMethodId, userId, data.spendBonus !== undefined && userId !== null ? data.spendBonus : null);
66
128
  order = await Order.findOne(data.orderId);
67
- let message;
68
- if (order.state === "CHECKOUT") {
129
+ if (order.state === "CHECKOUT" && shouldSendSucessMessage) {
69
130
  message = {
131
+ deviceId: context.connectionParams.deviceId,
70
132
  type: "info",
71
- title: "Внимание",
133
+ title: context.i18n.__("Attention"),
72
134
  message: order.message
73
- ? order.message
74
- : "Заказ готов к оформлению",
135
+ ? context.i18n.__(order.message)
136
+ : context.i18n.__("Ready for order"),
75
137
  };
76
138
  }
77
139
  else {
78
140
  if (order.message) {
79
141
  message = {
142
+ deviceId: context.connectionParams.deviceId,
80
143
  type: "error",
81
- title: "Внимание",
144
+ title: "Attention",
82
145
  message: order.message
83
- ? order.message
84
- : "Не удалось проверить заказ.",
146
+ ? context.i18n.__(order.message)
147
+ : context.i18n.__("It was not possible to check the order"),
85
148
  };
86
149
  }
87
150
  }
88
- eventHelper.sendMessage(args.orderId, message);
89
- return { message: message, order: order };
151
+ if (message) {
152
+ eventHelper.sendMessage(message);
153
+ }
154
+ return {
155
+ order: order,
156
+ ...message && { message: message }
157
+ };
90
158
  }
91
159
  catch (e) {
92
160
  let message = {
93
161
  type: "error",
94
- title: "Ошибка",
162
+ title: context.i18n.__("Error"),
95
163
  message: "",
96
164
  };
97
165
  if (e.code === 1) {
98
- message.message = "Введите имя заказчика";
166
+ message.message = context.i18n.__("Enter the name of the customer");
99
167
  }
100
168
  else if (e.code === 2) {
101
- message.message = "Введите телефон заказчика";
169
+ message.message = context.i18n.__("Enter the customer's phone");
102
170
  }
103
171
  else if (e.code === 3) {
104
- message.message = "Неверный формат имени заказчика";
172
+ message.message = context.i18n.__("The wrong format of the name of the customer");
105
173
  }
106
174
  else if (e.code === 4) {
107
- message.message = "Неверный формат номера заказчика";
175
+ message.message = context.i18n.__("The wrong format of the customer number");
108
176
  }
109
177
  else if (e.code === 5) {
110
- message.message = "Не указана улица";
178
+ message.message = context.i18n.__("No point of Street");
111
179
  }
112
180
  else if (e.code === 6) {
113
- message.message = "Не указан номер дома";
181
+ message.message = context.i18n.__("Not indicated the house number");
114
182
  }
115
183
  else if (e.code === 7) {
116
- message.message = "Не указан город";
184
+ message.message = context.i18n.__("The city is not indicated");
117
185
  }
118
186
  else if (e.code === 8) {
119
- message.message = "Платежная система недоступна";
187
+ message.message = context.i18n.__("The payment system is not available");
188
+ }
189
+ else if (e.code === 11) {
190
+ message.message = context.i18n.__(order.delivery.message);
120
191
  }
121
192
  else if (e.code === 10) {
122
- message.message = "Дата выполнения заказа не верная";
193
+ message.message = context.i18n.__("The date of execution of the order is not true");
194
+ }
195
+ else if (e.code === 15) {
196
+ message.message = context.i18n.__("Ordering for a date in the past is not possible");
123
197
  }
124
198
  else {
125
199
  message.message = e.error
126
200
  ? e.error
127
- : `Проблема при проверки заказа: ${e}`;
201
+ : context.i18n.__(`Problem when checking the order: %s`, e);
128
202
  }
129
- eventHelper.sendMessage(args.orderId, message);
203
+ order = await Order.findOne(data.orderId);
130
204
  sails.log.error(e);
131
- return { message: message };
205
+ eventHelper.sendMessage(message);
206
+ return {
207
+ order: order,
208
+ message: message
209
+ };
132
210
  }
133
211
  },
134
212
  },
135
213
  sendOrder: {
136
214
  def: "sendOrder(orderId: String!): CheckResponse",
137
215
  fn: async function (parent, args, context) {
216
+ if (!context.connectionParams.deviceId) {
217
+ throw `Missed deviceId`;
218
+ }
138
219
  let data = args;
139
- // if (data.date) {
140
- // let date = moment(data.date)
141
- // if(!date.isValid()){
142
- // return eventHelper.sendMessage(args.orderId,"Please order.date format is ISO (YYYY-MM-DD HH:mm:ss)");
143
- // } else {
144
- // data.date = date.format('YYYY-MM-DD HH:mm:ss');
145
- // }
146
- // }
147
- try {
148
- var order = await Order.findOne({ id: data.orderId });
149
- if (!order) {
150
- const errorMessage = `Order with id ${data.orderId} not found`;
151
- eventHelper.sendMessage(args.orderId, {
220
+ var order = await Order.findOne({ id: data.orderId });
221
+ if (!order) {
222
+ const errorMessage = context.i18n.__(`Order with id %s not found`, data.orderId);
223
+ eventHelper.sendMessage({
224
+ deviceId: context.connectionParams.deviceId,
225
+ type: "error",
226
+ title: context.i18n.__("Order not found"),
227
+ message: errorMessage,
228
+ });
229
+ sails.log.error(`${errorMessage}`);
230
+ throw new Error(errorMessage);
231
+ }
232
+ if (!order.isPaymentPromise) {
233
+ try {
234
+ let paymentResponse = await Order.payment({ id: order.id });
235
+ const action = {
236
+ deviceId: context.connectionParams.deviceId,
237
+ type: "Redirect",
238
+ data: {
239
+ link: paymentResponse.redirectLink,
240
+ },
241
+ };
242
+ eventHelper.sendAction(action);
243
+ order = await Order.populate({ id: order.id });
244
+ return { order: order, action: action };
245
+ }
246
+ catch (e) {
247
+ eventHelper.sendMessage({
248
+ deviceId: context.connectionParams.deviceId,
152
249
  type: "error",
153
- title: "Order not found",
154
- message: errorMessage,
250
+ title: context.i18n.__("Error"),
251
+ message: context.i18n.__("The payment of the payment has ended unsuccessfully"),
155
252
  });
156
- sails.log.error(`${errorMessage}`);
157
- throw new errorWrapper_1.Error(0, errorMessage);
158
- }
159
- // if (data.comment) order.comment = data.comment;
160
- // if (data.paymentMethodId) {
161
- // if (order.paymentMethod !== data.paymentMethodId) {
162
- // await Order.check(
163
- // order.id,
164
- // null,
165
- // null,
166
- // null,
167
- // data.paymentMethodId
168
- // );
169
- // order = await Order.findOne({ id: data.orderId });
170
- // }
171
- // }
172
- // if (order.paymentMethod) {
173
- // if (!(await PaymentMethod.checkAvailable(order.paymentMethod))) {
174
- // let errorMessage = `Проверка платежной системы завершилась неудачно`;
175
- // eventHelper.sendMessage(args.orderId, {
176
- // type: "error",
177
- // title: "Ошибка",
178
- // message: errorMessage,
179
- // });
180
- // sails.log.error(`${errorMessage}`)
181
- // throw new Error(0,errorMessage);
182
- // }
183
- // if (!(await PaymentMethod.isPaymentPromise(data.paymentMethodId))) {
184
- // try {
185
- // let paymentResponse = await order.payment();
186
- // const action = {
187
- // type: "PaymentRedirect",
188
- // data: {
189
- // redirectLink: paymentResponse.redirectLink,
190
- // },
191
- // };
192
- // eventHelper.sendAction(args.orderId, action);
193
- // return { order: order, action: action };
194
- // } catch (e) {
195
- // eventHelper.sendMessage(args.orderId, {
196
- // type: "error",
197
- // title: "Ошибка",
198
- // message: "Попытка регистрации платежа завершилась неудачно",
199
- // });
200
- // sails.log.error(e);
201
- // throw new Error(0, JSON.stringify(e));
202
- // }
203
- // }
204
- // }
205
- await Order.order(order.id);
253
+ const error = `External payment: ${e}`;
254
+ sails.log.error(error);
255
+ throw new Error(error);
256
+ }
257
+ }
258
+ try {
259
+ await Order.order({ id: order.id });
206
260
  order = await Order.findOne({ id: data.orderId });
207
261
  const message = {
208
262
  type: "info",
209
- title: "Успешно",
210
- message: "Ваш заказ принят в обработку",
263
+ title: context.i18n.__("Successfully"),
264
+ message: context.i18n.__("Your order is accepted for processing"),
211
265
  };
212
- eventHelper.sendMessage(args.orderId, message);
266
+ // eventHelper.sendMessage(message);
213
267
  return { order: order, message: message };
214
268
  }
215
269
  catch (e) {
216
- eventHelper.sendMessage(args.orderId, {
217
- type: "error",
218
- title: "Ошибка",
219
- message: e,
220
- });
221
- sails.log.error("sendOrder error :", e);
222
- throw new errorWrapper_1.Error(0, `${e}`);
270
+ const error = `Order finalize error:, ${e}`;
271
+ sails.log.error(error);
272
+ throw new Error(error);
223
273
  }
224
274
  },
225
275
  },