@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
@@ -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,182 +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
- }
24
- else {
25
- if (!data.address)
26
- throw `Address is required for non self service orders`;
27
- }
49
+ let message;
28
50
  try {
29
51
  var order = await Order.findOne(data.orderId);
52
+ const shouldSendSucessMessage = order.state !== "CHECKOUT";
30
53
  if (!order) {
31
- return eventHelper.sendMessage(args.orderId, {
54
+ message = eventHelper.sendMessage({
55
+ deviceId: context.connectionParams.deviceId,
32
56
  type: "error",
33
- title: "Order not found",
34
- 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),
35
59
  });
36
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
+ }
37
71
  if (order.state === "ORDER") {
38
- return eventHelper.sendMessage(args.orderId, {
72
+ message = eventHelper.sendMessage({
73
+ deviceId: context.connectionParams.deviceId,
39
74
  type: "error",
40
- title: "Ошибка",
41
- message: "Корзина уже заказана",
75
+ title: context.i18n.__("Error"),
76
+ message: context.i18n.__("Cart was ordered"),
42
77
  });
43
78
  }
44
79
  if (data.paymentMethodId) {
45
80
  if (!PaymentMethod.checkAvailable(data.paymentMethodId)) {
46
- return eventHelper.sendMessage(args.orderId, {
81
+ message = eventHelper.sendMessage({
82
+ deviceId: context.connectionParams.deviceId,
47
83
  type: "error",
48
- title: "Ошибка",
49
- message: "Проверка платежной системы завершилась неудачей",
84
+ title: context.i18n.__("Error"),
85
+ message: context.i18n.__("Checking the payment system ended in failure"),
50
86
  });
51
87
  }
52
88
  }
53
- if (data.address) {
54
- data.address.city =
55
- 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
+ }
56
98
  }
57
- 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 + "" : "";
58
113
  if (data.comment)
59
114
  order.comment = data.comment;
60
- if (data.date)
61
- order.date = data.date;
62
- // callback: boolean - перезвонить для уточнения деталей
115
+ order.date = data.date;
116
+ // callback: boolean -call back to clarify details
63
117
  if (data.customData && data.customData.callback) {
64
118
  if (!order.customData)
65
119
  order.customData = {};
66
120
  order.customData.callback = data.customData.callback;
67
121
  }
68
122
  await Order.update({ id: order.id }, order).fetch();
69
- 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);
70
128
  order = await Order.findOne(data.orderId);
71
- let message;
72
- if (order.state === "CHECKOUT") {
129
+ if (order.state === "CHECKOUT" && shouldSendSucessMessage) {
73
130
  message = {
131
+ deviceId: context.connectionParams.deviceId,
74
132
  type: "info",
75
- title: "Внимание",
133
+ title: context.i18n.__("Attention"),
76
134
  message: order.message
77
- ? order.message
78
- : "Заказ готов к оформлению",
135
+ ? context.i18n.__(order.message)
136
+ : context.i18n.__("Ready for order"),
79
137
  };
80
138
  }
81
139
  else {
82
140
  if (order.message) {
83
141
  message = {
142
+ deviceId: context.connectionParams.deviceId,
84
143
  type: "error",
85
- title: "Внимание",
144
+ title: "Attention",
86
145
  message: order.message
87
- ? order.message
88
- : "Не удалось проверить заказ.",
146
+ ? context.i18n.__(order.message)
147
+ : context.i18n.__("It was not possible to check the order"),
89
148
  };
90
149
  }
91
150
  }
92
- eventHelper.sendMessage(args.orderId, message);
93
- return { message: message, order: order };
151
+ if (message) {
152
+ eventHelper.sendMessage(message);
153
+ }
154
+ return {
155
+ order: order,
156
+ ...message && { message: message }
157
+ };
94
158
  }
95
159
  catch (e) {
96
160
  let message = {
97
161
  type: "error",
98
- title: "Ошибка",
162
+ title: context.i18n.__("Error"),
99
163
  message: "",
100
164
  };
101
165
  if (e.code === 1) {
102
- message.message = "Введите имя заказчика";
166
+ message.message = context.i18n.__("Enter the name of the customer");
103
167
  }
104
168
  else if (e.code === 2) {
105
- message.message = "Введите телефон заказчика";
169
+ message.message = context.i18n.__("Enter the customer's phone");
106
170
  }
107
171
  else if (e.code === 3) {
108
- message.message = "Неверный формат имени заказчика";
172
+ message.message = context.i18n.__("The wrong format of the name of the customer");
109
173
  }
110
174
  else if (e.code === 4) {
111
- message.message = "Неверный формат номера заказчика";
175
+ message.message = context.i18n.__("The wrong format of the customer number");
112
176
  }
113
177
  else if (e.code === 5) {
114
- message.message = "Не указана улица";
178
+ message.message = context.i18n.__("No point of Street");
115
179
  }
116
180
  else if (e.code === 6) {
117
- message.message = "Не указан номер дома";
181
+ message.message = context.i18n.__("Not indicated the house number");
118
182
  }
119
183
  else if (e.code === 7) {
120
- message.message = "Не указан город";
184
+ message.message = context.i18n.__("The city is not indicated");
121
185
  }
122
186
  else if (e.code === 8) {
123
- 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);
124
191
  }
125
192
  else if (e.code === 10) {
126
- 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");
127
197
  }
128
198
  else {
129
199
  message.message = e.error
130
200
  ? e.error
131
- : `Проблема при проверки заказа: ${e}`;
201
+ : context.i18n.__(`Problem when checking the order: %s`, e);
132
202
  }
133
- eventHelper.sendMessage(args.orderId, message);
203
+ order = await Order.findOne(data.orderId);
134
204
  sails.log.error(e);
135
- return { message: message };
205
+ eventHelper.sendMessage(message);
206
+ return {
207
+ order: order,
208
+ message: message
209
+ };
136
210
  }
137
211
  },
138
212
  },
139
213
  sendOrder: {
140
214
  def: "sendOrder(orderId: String!): CheckResponse",
141
215
  fn: async function (parent, args, context) {
216
+ if (!context.connectionParams.deviceId) {
217
+ throw `Missed deviceId`;
218
+ }
142
219
  let data = args;
143
- try {
144
- var order = await Order.findOne({ id: data.orderId });
145
- if (!order) {
146
- const errorMessage = `Order with id ${data.orderId} not found`;
147
- 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,
148
249
  type: "error",
149
- title: "Order not found",
150
- message: errorMessage,
250
+ title: context.i18n.__("Error"),
251
+ message: context.i18n.__("The payment of the payment has ended unsuccessfully"),
151
252
  });
152
- sails.log.error(`${errorMessage}`);
153
- throw new errorWrapper_1.Error(0, errorMessage);
154
- }
155
- if (!(await PaymentMethod.isPaymentPromise(order.paymentMethod))) {
156
- try {
157
- let paymentResponse = await Order.payment({ id: order.id });
158
- const action = {
159
- type: "PaymentRedirect",
160
- data: {
161
- redirectLink: paymentResponse.redirectLink,
162
- },
163
- };
164
- eventHelper.sendAction(args.orderId, action);
165
- order = await Order.populate(order.id);
166
- return { order: order, action: action };
167
- }
168
- catch (e) {
169
- eventHelper.sendMessage(args.orderId, {
170
- type: "error",
171
- title: "Ошибка",
172
- message: "Попытка регистрации платежа завершилась неудачно",
173
- });
174
- sails.log.error(e);
175
- throw new errorWrapper_1.Error(JSON.stringify(e));
176
- }
253
+ const error = `External payment: ${e}`;
254
+ sails.log.error(error);
255
+ throw new Error(error);
177
256
  }
178
- await Order.order(order.id);
257
+ }
258
+ try {
259
+ await Order.order({ id: order.id });
179
260
  order = await Order.findOne({ id: data.orderId });
180
261
  const message = {
181
262
  type: "info",
182
- title: "Успешно",
183
- message: "Ваш заказ принят в обработку",
263
+ title: context.i18n.__("Successfully"),
264
+ message: context.i18n.__("Your order is accepted for processing"),
184
265
  };
185
- eventHelper.sendMessage(args.orderId, message);
266
+ // eventHelper.sendMessage(message);
186
267
  return { order: order, message: message };
187
268
  }
188
269
  catch (e) {
189
- eventHelper.sendMessage(args.orderId, {
190
- type: "error",
191
- title: "Ошибка",
192
- message: e,
193
- });
194
- sails.log.error("sendOrder error :", e);
195
- throw new errorWrapper_1.Error(0, `${e}`);
270
+ const error = `Order finalize error:, ${e}`;
271
+ sails.log.error(error);
272
+ throw new Error(error);
196
273
  }
197
274
  },
198
275
  },