@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.
- package/.gitattributes +2 -0
- package/.gitlab-ci.yml +18 -0
- package/.vscode/extensions.json +5 -0
- package/docs/actions.md +25 -0
- package/docs/authorization.md +215 -0
- package/docs/captcha.md +71 -0
- package/docs/device-id.md +30 -0
- package/docs/messages.md +10 -0
- package/docs/user.md +54 -0
- package/index.d.ts +0 -1
- package/index.js +6 -2
- package/index.ts +2 -2
- package/lib/afterHook.js +8 -0
- package/lib/afterHook.ts +9 -0
- package/lib/bindTranslations.d.ts +1 -0
- package/lib/bindTranslations.js +40 -0
- package/lib/bindTranslations.ts +39 -0
- package/lib/defaults.d.ts +1 -0
- package/lib/defaults.js +49 -10
- package/lib/defaults.ts +55 -0
- package/lib/eventHelper.d.ts +14 -5
- package/lib/eventHelper.js +28 -9
- package/lib/eventHelper.ts +41 -8
- package/lib/getRecomended.d.ts +1 -0
- package/lib/getRecomended.js +29 -0
- package/lib/getRecomended.ts +31 -0
- package/lib/graphqlHelper.d.ts +3 -4
- package/lib/graphqlHelper.js +184 -73
- package/lib/graphqlHelper.ts +329 -186
- package/lib/jwt.d.ts +10 -0
- package/lib/jwt.js +43 -0
- package/lib/jwt.ts +61 -0
- package/package.json +13 -6
- package/src/additionalResolvers.d.ts +72 -9
- package/src/additionalResolvers.js +93 -24
- package/src/additionalResolvers.ts +105 -34
- package/src/graphql.d.ts +5 -3
- package/src/graphql.js +170 -37
- package/src/graphql.ts +210 -60
- package/src/resolvers/bonusProgram.d.ts +32 -0
- package/src/resolvers/bonusProgram.js +65 -0
- package/src/resolvers/bonusProgram.ts +79 -0
- package/src/resolvers/captcha.d.ts +11 -0
- package/src/resolvers/captcha.js +19 -0
- package/src/resolvers/captcha.ts +16 -0
- package/src/resolvers/checkout.d.ts +43 -14
- package/src/resolvers/checkout.js +172 -122
- package/src/resolvers/checkout.ts +218 -142
- package/src/resolvers/dishAndModifier.js +8 -4
- package/src/resolvers/dishAndModifier.ts +4 -0
- package/src/resolvers/error.d.ts +9 -0
- package/src/resolvers/error.js +21 -0
- package/src/resolvers/error.ts +21 -0
- package/src/resolvers/menu.d.ts +9 -0
- package/src/resolvers/menu.js +12 -0
- package/src/resolvers/menu.ts +10 -0
- package/src/resolvers/order.d.ts +527 -0
- package/src/resolvers/order.js +349 -0
- package/src/resolvers/order.ts +435 -0
- package/src/resolvers/paymentMethod.js +7 -3
- package/src/resolvers/paymentMethod.ts +9 -5
- package/src/resolvers/pickupPoint.d.ts +1 -0
- package/src/resolvers/pickupPoint.js +24 -0
- package/src/resolvers/pickupPoint.ts +23 -0
- package/src/resolvers/recomended.d.ts +13 -0
- package/src/resolvers/recomended.js +80 -0
- package/src/resolvers/recomended.ts +86 -0
- package/src/resolvers/restrictions.d.ts +37 -1
- package/src/resolvers/restrictions.js +100 -15
- package/src/resolvers/restrictions.ts +106 -14
- package/src/resolvers/streets.d.ts +1 -1
- package/src/resolvers/streets.js +1 -4
- package/src/resolvers/streets.ts +1 -3
- package/src/resolvers/subscriptions.d.ts +4 -4
- package/src/resolvers/subscriptions.js +49 -12
- package/src/resolvers/subscriptions.ts +59 -14
- package/src/resolvers/telemetry.d.ts +14 -0
- package/src/resolvers/telemetry.js +25 -0
- package/src/resolvers/telemetry.ts +24 -0
- package/src/resolvers/user.d.ts +82 -0
- package/src/resolvers/user.js +416 -0
- package/src/resolvers/user.ts +621 -0
- package/src/resolvers/userLocation.d.ts +53 -0
- package/src/resolvers/userLocation.js +74 -0
- package/src/resolvers/userLocation.ts +125 -0
- package/src/resolvers/userOTPrequest.d.ts +21 -0
- package/src/resolvers/userOTPrequest.js +57 -0
- package/src/resolvers/userOTPrequest.ts +75 -0
- package/test/e2e_helper.js +157 -0
- package/test/e2e_helper.ts +212 -0
- package/test/fixture/config/i18n.js +7 -20
- package/test/fixture/config/locales/de.json +1 -0
- package/test/fixture/config/locales/en.json +10 -0
- package/test/fixture/config/locales/es.json +3 -0
- package/test/fixture/config/locales/fr.json +1 -0
- package/test/fixture/config/log.js +1 -1
- package/test/fixture/package.json +5 -6
- package/test/fixture/patches/rttc+10.0.1.patch +17 -0
- package/test/integration/captcha.test.js +20 -0
- package/test/integration/captcha.test.ts +25 -0
- package/test/integration/dish.test.js +35 -0
- package/test/integration/dish.test.ts +43 -0
- package/test/integration/graphql.test.js +5 -2
- package/test/integration/graphql.test.ts +2 -4
- package/test/integration/images.test.js +35 -0
- package/test/integration/images.test.ts +40 -0
- package/test/integration/locale.test.js +26 -0
- package/test/integration/locale.test.ts +32 -0
- package/test/integration/order.test.js +56 -43
- package/test/integration/order.test.ts +59 -59
- package/test/integration/subscriptions.test.js +136 -0
- package/test/integration/subscriptions.test.ts +162 -0
- package/test/integration/user.test.js +249 -0
- package/test/integration/user.test.ts +299 -0
- package/test/unit/first.test.js +4 -2
- package/test/unit/first.test.ts +1 -1
- package/test/unit/get-recomended.test.js +56 -0
- package/test/unit/get-recomended.test.ts +63 -0
- package/translations/de.json +2 -0
- package/translations/en.json +3 -0
- package/translations/es.json +3 -0
- package/translations/fr.json +2 -0
- package/translations/ru.json +36 -0
- package/tsconfig.json +20 -5
- package/types/global.d.ts +30 -0
- package/types/global.js +2 -0
- package/types/global.ts +31 -0
- package/types/primitives.d.ts +19 -0
- package/types/references.d.ts +1 -0
- package/types/restoGraphQLConfig.d.ts +13 -0
- package/lib/afterHook.ts___graphql-transport-ws +0 -138
- package/lib/afterHook.ts___graphql-ws +0 -133
- package/lib/errorWrapper.d.ts +0 -4
- package/lib/errorWrapper.js +0 -13
- package/lib/errorWrapper.ts +0 -12
- package/notes.md +0 -1976
- package/src/resolvers/cart.d.ts +0 -343
- package/src/resolvers/cart.js +0 -196
- package/src/resolvers/cart.ts +0 -277
- package/test/fixture/config/connections.js +0 -9
- package/test/integration/sails_not_crash.test.js +0 -3
- package/test/integration/sails_not_crash.test.ts +0 -3
|
@@ -1,12 +1,74 @@
|
|
|
1
1
|
import * as eventHelper from "../../lib/eventHelper";
|
|
2
|
-
import {
|
|
2
|
+
import { Action, Message } from "../../types/primitives";
|
|
3
|
+
import Order from "@webresto/core/models/Order"
|
|
4
|
+
|
|
5
|
+
type CheckResponse = {
|
|
6
|
+
order?: Order
|
|
7
|
+
message: Message
|
|
8
|
+
action?: Action
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
import graphqlHelper from "../../lib/graphqlHelper";
|
|
12
|
+
import Address from "@webresto/core/interfaces/Address";
|
|
13
|
+
import Customer from "@webresto/core/interfaces/Customer";
|
|
14
|
+
import { SpendBonus } from "@webresto/core/interfaces/SpendBonus";
|
|
15
|
+
import { JWTAuth } from "../../lib/jwt";
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
interface InputOrderCheckout {
|
|
19
|
+
orderId: string
|
|
20
|
+
paymentMethodId: string
|
|
21
|
+
selfService?: boolean
|
|
22
|
+
pickupPointId?: string
|
|
23
|
+
address?: Address
|
|
24
|
+
locationId: string
|
|
25
|
+
customer: Customer
|
|
26
|
+
date?: string
|
|
27
|
+
personsCount?: number
|
|
28
|
+
comment: string
|
|
29
|
+
spendBonus: SpendBonus
|
|
30
|
+
customData:{[key: string]: string | number}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
graphqlHelper.addType(`#graphql
|
|
34
|
+
input InputOrderCheckout {
|
|
35
|
+
orderId: String!
|
|
36
|
+
paymentMethodId: String!
|
|
37
|
+
customer: Customer!
|
|
38
|
+
spendBonus: InputSpendBonus
|
|
39
|
+
selfService: Boolean
|
|
40
|
+
pickupPointId: String
|
|
41
|
+
locationId: String
|
|
42
|
+
address: Address
|
|
43
|
+
date: String
|
|
44
|
+
comment: String
|
|
45
|
+
personsCount: Int
|
|
46
|
+
customData: Json
|
|
47
|
+
}
|
|
48
|
+
`);
|
|
49
|
+
|
|
50
|
+
graphqlHelper.addType(`#graphql
|
|
51
|
+
input InputSpendBonus {
|
|
52
|
+
bonusProgramId: String!
|
|
53
|
+
amount: Int!
|
|
54
|
+
adapter: String!
|
|
55
|
+
bonusProgramName: String!
|
|
56
|
+
}
|
|
57
|
+
`);
|
|
58
|
+
|
|
59
|
+
|
|
3
60
|
|
|
4
61
|
export default {
|
|
5
62
|
Mutation: {
|
|
6
63
|
checkOrder: {
|
|
7
|
-
def:
|
|
8
|
-
|
|
9
|
-
|
|
64
|
+
def: `#graphql
|
|
65
|
+
checkOrder(orderCheckout: InputOrderCheckout): CheckResponse`,
|
|
66
|
+
fn: async function (parent, args: { orderCheckout: InputOrderCheckout }, context): Promise<CheckResponse> {
|
|
67
|
+
let data = args.orderCheckout;
|
|
68
|
+
|
|
69
|
+
if (!context.connectionParams.deviceId) {
|
|
70
|
+
throw `Missed deviceId`
|
|
71
|
+
}
|
|
10
72
|
|
|
11
73
|
// if (data.date) {
|
|
12
74
|
// let date = moment(data.date)
|
|
@@ -19,51 +81,79 @@ export default {
|
|
|
19
81
|
|
|
20
82
|
let isSelfService: boolean;
|
|
21
83
|
|
|
22
|
-
//@ts-ignore
|
|
23
|
-
if (data.selfService || data.selfDelivery) {
|
|
24
|
-
isSelfService = true;
|
|
25
|
-
}
|
|
26
84
|
|
|
85
|
+
let message;
|
|
27
86
|
try {
|
|
28
87
|
var order = await Order.findOne(data.orderId);
|
|
29
|
-
|
|
88
|
+
const shouldSendSucessMessage = order.state !== "CHECKOUT"
|
|
30
89
|
if (!order) {
|
|
31
|
-
|
|
90
|
+
message = eventHelper.sendMessage({
|
|
91
|
+
deviceId: context.connectionParams.deviceId,
|
|
32
92
|
type: "error",
|
|
33
|
-
title: "Order not found",
|
|
34
|
-
message:
|
|
93
|
+
title: context.i18n.__("Order not found"),
|
|
94
|
+
message: context.i18n.__("Order with id %s not found", data.orderId),
|
|
35
95
|
});
|
|
36
96
|
}
|
|
37
97
|
|
|
98
|
+
//@ts-ignore
|
|
99
|
+
if (data.selfService) {
|
|
100
|
+
isSelfService = true;
|
|
101
|
+
order.pickupPoint = data.pickupPointId;
|
|
102
|
+
} else {
|
|
103
|
+
order.pickupPoint = null;
|
|
104
|
+
if(!data.address && !data.locationId) throw `Address is required for non self service orders`
|
|
105
|
+
}
|
|
106
|
+
|
|
38
107
|
if (order.state === "ORDER") {
|
|
39
|
-
|
|
108
|
+
message = eventHelper.sendMessage({
|
|
109
|
+
deviceId: context.connectionParams.deviceId,
|
|
40
110
|
type: "error",
|
|
41
|
-
title: "
|
|
42
|
-
message: "
|
|
111
|
+
title: context.i18n.__("Error"),
|
|
112
|
+
message: context.i18n.__("Cart was ordered"),
|
|
43
113
|
});
|
|
44
114
|
}
|
|
45
115
|
|
|
46
116
|
if (data.paymentMethodId) {
|
|
47
117
|
if (!PaymentMethod.checkAvailable(data.paymentMethodId)) {
|
|
48
|
-
|
|
118
|
+
message = eventHelper.sendMessage({
|
|
119
|
+
deviceId: context.connectionParams.deviceId,
|
|
49
120
|
type: "error",
|
|
50
|
-
title: "
|
|
51
|
-
message: "
|
|
121
|
+
title: context.i18n.__("Error"),
|
|
122
|
+
message: context.i18n.__("Checking the payment system ended in failure"),
|
|
52
123
|
});
|
|
53
124
|
}
|
|
54
125
|
}
|
|
55
126
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
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},
|
|
59
149
|
}
|
|
60
150
|
|
|
61
|
-
order.personsCount =
|
|
151
|
+
order.personsCount = data.personsCount ? data.personsCount+"" : "";
|
|
62
152
|
if (data.comment) order.comment = data.comment;
|
|
63
153
|
|
|
64
|
-
|
|
154
|
+
order.date = data.date;
|
|
65
155
|
|
|
66
|
-
// callback: boolean -
|
|
156
|
+
// callback: boolean -call back to clarify details
|
|
67
157
|
if (data.customData && data.customData.callback) {
|
|
68
158
|
if (!order.customData) order.customData = {};
|
|
69
159
|
order.customData.callback = data.customData.callback;
|
|
@@ -71,176 +161,162 @@ export default {
|
|
|
71
161
|
|
|
72
162
|
await Order.update({ id: order.id }, order).fetch();
|
|
73
163
|
|
|
164
|
+
let userId = null;
|
|
165
|
+
if (context && context.connectionParams.authorization) {
|
|
166
|
+
userId = (await JWTAuth.verify(context.connectionParams.authorization)).userId;
|
|
167
|
+
}
|
|
168
|
+
|
|
74
169
|
await Order.check(
|
|
75
|
-
order.id,
|
|
170
|
+
{id: order.id},
|
|
76
171
|
data.customer,
|
|
77
172
|
isSelfService,
|
|
78
173
|
data.address,
|
|
79
|
-
data.paymentMethodId
|
|
174
|
+
data.paymentMethodId,
|
|
175
|
+
userId,
|
|
176
|
+
data.spendBonus !== undefined && userId !== null ? data.spendBonus : null
|
|
80
177
|
);
|
|
81
178
|
|
|
82
179
|
order = await Order.findOne(data.orderId);
|
|
83
180
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (order.state === "CHECKOUT") {
|
|
181
|
+
if (order.state === "CHECKOUT" && shouldSendSucessMessage) {
|
|
87
182
|
message = {
|
|
183
|
+
deviceId: context.connectionParams.deviceId,
|
|
88
184
|
type: "info",
|
|
89
|
-
title: "
|
|
185
|
+
title: context.i18n.__("Attention"),
|
|
90
186
|
message: order.message
|
|
91
|
-
? order.message
|
|
92
|
-
: "
|
|
187
|
+
? context.i18n.__(order.message)
|
|
188
|
+
: context.i18n.__("Ready for order"),
|
|
93
189
|
};
|
|
94
190
|
|
|
95
191
|
} else {
|
|
96
192
|
if (order.message) {
|
|
97
193
|
message = {
|
|
194
|
+
deviceId: context.connectionParams.deviceId,
|
|
98
195
|
type: "error",
|
|
99
|
-
title: "
|
|
196
|
+
title: "Attention",
|
|
100
197
|
message: order.message
|
|
101
|
-
? order.message
|
|
102
|
-
: "
|
|
198
|
+
? context.i18n.__(order.message)
|
|
199
|
+
: context.i18n.__("It was not possible to check the order"),
|
|
103
200
|
}
|
|
104
201
|
}
|
|
105
202
|
}
|
|
106
203
|
|
|
107
|
-
|
|
204
|
+
if(message){
|
|
205
|
+
eventHelper.sendMessage(message);
|
|
206
|
+
}
|
|
108
207
|
|
|
109
|
-
return {
|
|
208
|
+
return {
|
|
209
|
+
order: order,
|
|
210
|
+
...message && { message: message }
|
|
211
|
+
};
|
|
110
212
|
} catch (e) {
|
|
111
213
|
let message = {
|
|
112
214
|
type: "error",
|
|
113
|
-
title: "
|
|
215
|
+
title: context.i18n.__("Error"),
|
|
114
216
|
message: "",
|
|
115
|
-
};
|
|
217
|
+
} as Message;
|
|
116
218
|
if (e.code === 1) {
|
|
117
|
-
message.message = "
|
|
219
|
+
message.message = context.i18n.__("Enter the name of the customer");
|
|
118
220
|
} else if (e.code === 2) {
|
|
119
|
-
message.message = "
|
|
221
|
+
message.message = context.i18n.__("Enter the customer's phone");
|
|
120
222
|
} else if (e.code === 3) {
|
|
121
|
-
message.message = "
|
|
223
|
+
message.message = context.i18n.__("The wrong format of the name of the customer");
|
|
122
224
|
} else if (e.code === 4) {
|
|
123
|
-
message.message = "
|
|
225
|
+
message.message = context.i18n.__("The wrong format of the customer number");
|
|
124
226
|
} else if (e.code === 5) {
|
|
125
|
-
message.message = "
|
|
227
|
+
message.message = context.i18n.__("No point of Street");
|
|
126
228
|
} else if (e.code === 6) {
|
|
127
|
-
message.message = "
|
|
229
|
+
message.message = context.i18n.__("Not indicated the house number");
|
|
128
230
|
} else if (e.code === 7) {
|
|
129
|
-
message.message = "
|
|
231
|
+
message.message = context.i18n.__("The city is not indicated");
|
|
130
232
|
} else if (e.code === 8) {
|
|
131
|
-
message.message = "
|
|
233
|
+
message.message = context.i18n.__("The payment system is not available");
|
|
234
|
+
} else if (e.code === 11) {
|
|
235
|
+
message.message = context.i18n.__(order.delivery.message) ;
|
|
132
236
|
} else if (e.code === 10) {
|
|
133
|
-
message.message = "
|
|
237
|
+
message.message = context.i18n.__("The date of execution of the order is not true");
|
|
238
|
+
} else if (e.code === 15) {
|
|
239
|
+
message.message = context.i18n.__("Ordering for a date in the past is not possible");
|
|
134
240
|
} else {
|
|
135
241
|
message.message = e.error
|
|
136
242
|
? e.error
|
|
137
|
-
:
|
|
243
|
+
: context.i18n.__(`Problem when checking the order: %s`, e);
|
|
138
244
|
}
|
|
139
245
|
|
|
140
|
-
|
|
246
|
+
order = await Order.findOne(data.orderId);
|
|
141
247
|
sails.log.error(e)
|
|
142
|
-
|
|
248
|
+
eventHelper.sendMessage(message);
|
|
249
|
+
return {
|
|
250
|
+
order: order,
|
|
251
|
+
message: message
|
|
252
|
+
};
|
|
143
253
|
}
|
|
144
254
|
},
|
|
145
255
|
},
|
|
146
256
|
sendOrder: {
|
|
147
257
|
def: "sendOrder(orderId: String!): CheckResponse",
|
|
148
258
|
fn: async function (parent, args, context) {
|
|
259
|
+
if (!context.connectionParams.deviceId) {
|
|
260
|
+
throw `Missed deviceId`;
|
|
261
|
+
}
|
|
149
262
|
let data = args;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
try {
|
|
161
|
-
var order = await Order.findOne({ id: data.orderId });
|
|
162
|
-
if (!order) {
|
|
163
|
-
const errorMessage = `Order with id ${data.orderId} not found`;
|
|
164
|
-
eventHelper.sendMessage(args.orderId, {
|
|
165
|
-
type: "error",
|
|
166
|
-
title: "Order not found",
|
|
167
|
-
message: errorMessage,
|
|
263
|
+
|
|
264
|
+
var order = await Order.findOne({ id: data.orderId });
|
|
265
|
+
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,
|
|
168
272
|
});
|
|
169
|
-
sails.log.error(`${errorMessage}`)
|
|
170
|
-
throw new Error(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
// }
|
|
199
|
-
|
|
200
|
-
// if (!(await PaymentMethod.isPaymentPromise(data.paymentMethodId))) {
|
|
201
|
-
// try {
|
|
202
|
-
// let paymentResponse = await order.payment();
|
|
203
|
-
// const action = {
|
|
204
|
-
// type: "PaymentRedirect",
|
|
205
|
-
// data: {
|
|
206
|
-
// redirectLink: paymentResponse.redirectLink,
|
|
207
|
-
// },
|
|
208
|
-
// };
|
|
209
|
-
// eventHelper.sendAction(args.orderId, action);
|
|
210
|
-
// return { order: order, action: action };
|
|
211
|
-
// } catch (e) {
|
|
212
|
-
// eventHelper.sendMessage(args.orderId, {
|
|
213
|
-
// type: "error",
|
|
214
|
-
// title: "Ошибка",
|
|
215
|
-
// message: "Попытка регистрации платежа завершилась неудачно",
|
|
216
|
-
// });
|
|
217
|
-
|
|
218
|
-
// sails.log.error(e);
|
|
219
|
-
// throw new Error(0, JSON.stringify(e));
|
|
220
|
-
// }
|
|
221
|
-
// }
|
|
222
|
-
// }
|
|
223
|
-
|
|
224
|
-
await Order.order(order.id);
|
|
225
|
-
order = await Order.findOne({ id: data.orderId })
|
|
226
|
-
const message = {
|
|
227
|
-
type: "info",
|
|
228
|
-
title: "Успешно",
|
|
229
|
-
message: "Ваш заказ принят в обработку",
|
|
230
|
-
};
|
|
231
|
-
eventHelper.sendMessage(args.orderId, message);
|
|
232
|
-
return { order: order, message: message };
|
|
233
|
-
} catch (e) {
|
|
234
|
-
eventHelper.sendMessage(args.orderId, {
|
|
235
|
-
type: "error",
|
|
236
|
-
title: "Ошибка",
|
|
237
|
-
message: e,
|
|
238
|
-
});
|
|
273
|
+
sails.log.error(`${errorMessage}`);
|
|
274
|
+
throw new Error(errorMessage);
|
|
275
|
+
}
|
|
276
|
+
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
|
+
}
|
|
301
|
+
}
|
|
239
302
|
|
|
240
|
-
|
|
241
|
-
|
|
303
|
+
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 };
|
|
313
|
+
}
|
|
314
|
+
catch (e) {
|
|
315
|
+
const error = `Order finalize error:, ${e}`
|
|
316
|
+
sails.log.error(error);
|
|
317
|
+
throw new Error(error);
|
|
242
318
|
}
|
|
243
319
|
},
|
|
244
320
|
},
|
|
245
321
|
},
|
|
246
|
-
}
|
|
322
|
+
}
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const graphqlHelper_1 = require("@webresto/graphql/lib/graphqlHelper");
|
|
4
4
|
// init
|
|
5
|
-
graphqlHelper_1.addToReplaceList("Dish.modifiers", "modifiers: [GroupModifier]");
|
|
6
|
-
graphqlHelper_1.addToReplaceList("OrderDish.modifiers", "modifiers: [OrderModifier]");
|
|
7
|
-
graphqlHelper_1.addType(`
|
|
5
|
+
(0, graphqlHelper_1.addToReplaceList)("Dish.modifiers", "modifiers: [GroupModifier]");
|
|
6
|
+
(0, graphqlHelper_1.addToReplaceList)("OrderDish.modifiers", "modifiers: [OrderModifier]");
|
|
7
|
+
(0, graphqlHelper_1.addType)(`
|
|
8
8
|
type GroupModifier {
|
|
9
|
+
"rmsId"
|
|
10
|
+
id: String
|
|
9
11
|
maxAmount: Int
|
|
10
12
|
minAmount: Int
|
|
11
13
|
modifierId: String
|
|
@@ -14,6 +16,8 @@ type GroupModifier {
|
|
|
14
16
|
group: Group
|
|
15
17
|
}
|
|
16
18
|
type Modifier {
|
|
19
|
+
"rmsId"
|
|
20
|
+
id: String
|
|
17
21
|
modifierId: String
|
|
18
22
|
maxAmount: Int
|
|
19
23
|
minAmount: Int
|
|
@@ -22,7 +26,7 @@ type Modifier {
|
|
|
22
26
|
dish: Dish
|
|
23
27
|
}
|
|
24
28
|
`);
|
|
25
|
-
graphqlHelper_1.addType(`
|
|
29
|
+
(0, graphqlHelper_1.addType)(`
|
|
26
30
|
type OrderModifier {
|
|
27
31
|
id: String
|
|
28
32
|
dish: Dish
|
|
@@ -6,6 +6,8 @@ addToReplaceList("OrderDish.modifiers", "modifiers: [OrderModifier]");
|
|
|
6
6
|
|
|
7
7
|
addType(`
|
|
8
8
|
type GroupModifier {
|
|
9
|
+
"rmsId"
|
|
10
|
+
id: String
|
|
9
11
|
maxAmount: Int
|
|
10
12
|
minAmount: Int
|
|
11
13
|
modifierId: String
|
|
@@ -14,6 +16,8 @@ type GroupModifier {
|
|
|
14
16
|
group: Group
|
|
15
17
|
}
|
|
16
18
|
type Modifier {
|
|
19
|
+
"rmsId"
|
|
20
|
+
id: String
|
|
17
21
|
modifierId: String
|
|
18
22
|
maxAmount: Int
|
|
19
23
|
minAmount: Int
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = {
|
|
4
|
+
Query: {
|
|
5
|
+
errorCheck: {
|
|
6
|
+
def: 'errorCheck: Boolean',
|
|
7
|
+
fn: async () => {
|
|
8
|
+
throw new Error(`modifier required (amount, id) for dish: amount: `);
|
|
9
|
+
// await Order.check(
|
|
10
|
+
// {id: "order.id"}
|
|
11
|
+
// );
|
|
12
|
+
// try {
|
|
13
|
+
// } catch (error) {
|
|
14
|
+
// console.log(JSON.stringify(error), error.trace())
|
|
15
|
+
// throw error;
|
|
16
|
+
// }
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
Query: {
|
|
3
|
+
errorCheck: {
|
|
4
|
+
def: 'errorCheck: Boolean',
|
|
5
|
+
fn: async () => {
|
|
6
|
+
throw new Error(
|
|
7
|
+
`modifier required (amount, id) for dish: amount: `
|
|
8
|
+
);
|
|
9
|
+
// await Order.check(
|
|
10
|
+
// {id: "order.id"}
|
|
11
|
+
// );
|
|
12
|
+
// try {
|
|
13
|
+
// } catch (error) {
|
|
14
|
+
// console.log(JSON.stringify(error), error.trace())
|
|
15
|
+
// throw error;
|
|
16
|
+
// }
|
|
17
|
+
return true
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = {
|
|
4
|
+
Query: {
|
|
5
|
+
menu: {
|
|
6
|
+
def: "menu(concept: String, topLevelGroupId: String): [Group]",
|
|
7
|
+
fn: async (parent, args, context, info) => {
|
|
8
|
+
return await Group.getMenuGroups(args.concept, args.topLevelGroupId);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|