@webresto/graphql 1.3.7 → 1.3.8
Sign up to get free protection for your applications and to get access to all the features.
- 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 -72
- package/lib/graphqlHelper.ts +329 -185
- 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 +35 -16
- package/src/resolvers/checkout.js +171 -94
- package/src/resolvers/checkout.ts +214 -104
- 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 -278
- 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
package/src/graphql.ts
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
import * as helper from
|
2
|
-
import getEmitter from "@webresto/core/libs/getEmitter";
|
1
|
+
import * as helper from "../lib/graphqlHelper";
|
3
2
|
import _ = require("lodash");
|
4
|
-
import { additionalResolver } from
|
3
|
+
import { additionalResolver } from "./additionalResolvers";
|
4
|
+
import * as langParser from "accept-language-parser"
|
5
|
+
import { ApolloServer } from "apollo-server-express";
|
6
|
+
const fs = require("fs");
|
7
|
+
const path = require("path");
|
8
|
+
var i18nFactory = require('i18n-2');
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
const path = require('path');
|
9
|
-
|
10
|
-
const { PubSub } = require('apollo-server');
|
10
|
+
import { PubSub } from "apollo-server";
|
11
|
+
import { GraphQLError, GraphQLFormattedError } from "graphql";
|
11
12
|
const pubsub = new PubSub();
|
12
13
|
sails.graphql = { pubsub };
|
13
|
-
let server;
|
14
|
+
let server: ApolloServer;
|
14
15
|
|
15
|
-
const AdditionalResolvers: any = {
|
16
|
-
}
|
16
|
+
const AdditionalResolvers: any = {};
|
17
17
|
|
18
18
|
export default {
|
19
19
|
getPubsub: () => pubsub,
|
@@ -22,7 +22,7 @@ export default {
|
|
22
22
|
_.merge(AdditionalResolvers, resolver);
|
23
23
|
},
|
24
24
|
init: async function () {
|
25
|
-
let resolversApiPath = path.resolve(__dirname,
|
25
|
+
let resolversApiPath = path.resolve(__dirname, "./resolvers");
|
26
26
|
if (fs.existsSync(resolversApiPath)) {
|
27
27
|
helper.addDirResolvers(resolversApiPath);
|
28
28
|
}
|
@@ -34,9 +34,7 @@ export default {
|
|
34
34
|
helper.addAllSailsModels();
|
35
35
|
|
36
36
|
if (sails.config.restographql?.whiteListAutoGen)
|
37
|
-
helper.setWhiteList(
|
38
|
-
sails.config.restographql.whiteListAutoGen
|
39
|
-
);
|
37
|
+
helper.setWhiteList(sails.config.restographql.whiteListAutoGen);
|
40
38
|
|
41
39
|
if (sails.config.restographql?.blackList)
|
42
40
|
helper.addToBlackList(sails.config.restographql.blackList);
|
@@ -45,13 +43,12 @@ export default {
|
|
45
43
|
_.merge(AdditionalResolvers, additionalResolver);
|
46
44
|
|
47
45
|
helper.addType(`
|
48
|
-
|
49
46
|
input Customer {
|
50
|
-
phone:
|
47
|
+
phone: InputPhone
|
51
48
|
mail: String
|
52
49
|
name: String!
|
53
50
|
}
|
54
|
-
input
|
51
|
+
input InputPhone {
|
55
52
|
code: String!
|
56
53
|
number: String!
|
57
54
|
additionalNumber: String
|
@@ -70,11 +67,13 @@ export default {
|
|
70
67
|
doorphone: String
|
71
68
|
}
|
72
69
|
type Message {
|
70
|
+
id: String
|
73
71
|
title: String
|
74
72
|
type: String
|
75
73
|
message: String
|
76
74
|
}
|
77
75
|
type Action {
|
76
|
+
id: String
|
78
77
|
type: String
|
79
78
|
data: Json
|
80
79
|
}
|
@@ -83,20 +82,66 @@ export default {
|
|
83
82
|
message: Message
|
84
83
|
action: Action
|
85
84
|
}
|
85
|
+
type Response {
|
86
|
+
message: Message
|
87
|
+
action: Action
|
88
|
+
}
|
86
89
|
type GetOrderResponse {
|
87
90
|
order: Order
|
88
91
|
customData: Json
|
89
92
|
}
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
93
|
+
|
94
|
+
type UserCustomField {
|
95
|
+
id: String
|
96
|
+
type: String
|
97
|
+
label: String
|
98
|
+
enum: [String]
|
99
|
+
description: String
|
100
|
+
required: Boolean
|
101
|
+
regex: String
|
96
102
|
}
|
97
|
-
`);
|
98
103
|
|
99
104
|
|
105
|
+
type Phone {
|
106
|
+
code: String
|
107
|
+
number: String
|
108
|
+
additionalNumber: String
|
109
|
+
}
|
110
|
+
type CaptchaJob {
|
111
|
+
id: String
|
112
|
+
task: String
|
113
|
+
}
|
114
|
+
type PromotionState {
|
115
|
+
type: String
|
116
|
+
message: String
|
117
|
+
state: Json
|
118
|
+
}
|
119
|
+
|
120
|
+
"""Solved captcha"""
|
121
|
+
input Captcha {
|
122
|
+
"Captcha job ID"
|
123
|
+
id: String!
|
124
|
+
"Resolved captcha"
|
125
|
+
solution: String!
|
126
|
+
}
|
127
|
+
|
128
|
+
"""Country"""
|
129
|
+
type Country {
|
130
|
+
phoneCode: String
|
131
|
+
iso: String
|
132
|
+
name: String
|
133
|
+
nativeCountryName: String
|
134
|
+
language: [String]
|
135
|
+
currency: String
|
136
|
+
currencySymbol: String
|
137
|
+
currencyISO: String
|
138
|
+
currencyUnit: String
|
139
|
+
currencyDenomination: Int
|
140
|
+
phoneMask: [String]
|
141
|
+
flag: String
|
142
|
+
}
|
143
|
+
`);
|
144
|
+
|
100
145
|
// helper.addToBlackList(["createdAt", "updatedAt"]);
|
101
146
|
|
102
147
|
// required root types for moduling schema
|
@@ -110,64 +155,169 @@ export default {
|
|
110
155
|
type Subscription {
|
111
156
|
_root: String
|
112
157
|
}`);
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
158
|
+
|
159
|
+
/**
|
160
|
+
* Discount fields global support
|
161
|
+
*/
|
162
|
+
helper.addCustomField("Dish", "discountAmount: Float");
|
163
|
+
helper.addCustomField("Dish", "discountType: String");
|
164
|
+
|
165
|
+
/**
|
166
|
+
* @deprecated ???
|
167
|
+
*/
|
168
|
+
helper.addCustomField("Dish", "oldPrice: Float");
|
169
|
+
|
170
|
+
helper.addCustomField("Dish", "salePrice: Float");
|
171
|
+
helper.addCustomField("Group", "discount: String");
|
172
|
+
|
173
|
+
/**
|
174
|
+
* Types of complex order fields
|
175
|
+
*/
|
176
|
+
helper.addType(`#graphql
|
177
|
+
type OrderDeliveryState {
|
178
|
+
"Time it will take for delivery"
|
179
|
+
deliveryTimeMinutes: Int
|
180
|
+
"If disabled, then delivery is not allowed and will be processed"
|
181
|
+
allowed: Boolean
|
182
|
+
"Cost of delivery"
|
183
|
+
cost: Float
|
184
|
+
"ID of the service that will be on the delivery receipt"
|
185
|
+
item: String
|
186
|
+
"Server message for current delivery"
|
187
|
+
message: String
|
188
|
+
}`
|
189
|
+
);
|
190
|
+
|
191
|
+
|
192
|
+
helper.addToReplaceList("Order.delivery", "delivery: OrderDeliveryState");
|
193
|
+
|
194
|
+
|
121
195
|
|
122
196
|
const { typeDefs, resolvers } = helper.getSchema();
|
123
197
|
|
124
|
-
|
198
|
+
emitter.on("core-order-after-count", "graphql", function (order) {
|
125
199
|
pubsub.publish("order-changed", order);
|
126
200
|
});
|
127
|
-
|
201
|
+
emitter.on("send-message", "graphql", function ({ orderId, message }) {
|
128
202
|
pubsub.publish("message", { orderId, message });
|
129
203
|
});
|
130
|
-
|
204
|
+
emitter.on("core-dish-after-update", "graphql", function (record) {
|
131
205
|
pubsub.publish("dish-changed", record);
|
132
206
|
});
|
133
|
-
|
207
|
+
emitter.on("core-maintenance-enabled", "graphql", function (record) {
|
134
208
|
pubsub.publish("maintenance", record);
|
135
209
|
});
|
136
|
-
|
210
|
+
emitter.on("core-maintenance-disabled", "graphql", function () {
|
137
211
|
pubsub.publish("maintenance", null);
|
138
212
|
});
|
139
|
-
|
140
|
-
let apolloServer
|
213
|
+
|
214
|
+
let apolloServer: ApolloServer;
|
141
215
|
try {
|
142
216
|
apolloServer = new ApolloServer({
|
143
217
|
typeDefs,
|
218
|
+
introspection: true,
|
219
|
+
playground: true,
|
144
220
|
resolvers: [resolvers, AdditionalResolvers],
|
145
221
|
subscriptions: {
|
146
222
|
onConnect: (connectionParams, webSocket) => {
|
147
|
-
let exContext = {}
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
}
|
223
|
+
let exContext = {};
|
224
|
+
|
225
|
+
if (connectionParams) {
|
226
|
+
|
227
|
+
/**
|
228
|
+
* Authorization
|
229
|
+
*/
|
230
|
+
if (!connectionParams["authorization"] && connectionParams["Authorization"]) {
|
231
|
+
connectionParams["authorization"] = connectionParams["Authorization"];
|
232
|
+
}
|
233
|
+
|
234
|
+
if (connectionParams["x-device-id"] || connectionParams["X-Device-Id"]) {
|
235
|
+
connectionParams["deviceId"] = connectionParams["x-device-id"] ? connectionParams["x-device-id"] : connectionParams["X-Device-Id"];
|
236
|
+
}
|
237
|
+
|
238
|
+
exContext["connectionParams"] = connectionParams;
|
239
|
+
|
240
|
+
/**
|
241
|
+
* Accept-Language
|
242
|
+
*/
|
243
|
+
|
244
|
+
connectionParams["locale"] = sails.config.i18n.defaultLocale
|
245
|
+
const acceptLanguge = connectionParams["Accept-Language"] ?? connectionParams["accept-language"] ?? false
|
246
|
+
if(acceptLanguge){
|
247
|
+
connectionParams["locale"] = langParser.parse(acceptLanguge)[0]?.code ?? sails.config.i18n.defaultLocale
|
248
|
+
}
|
249
|
+
const i18n = new i18nFactory({...sails.config.i18n, directory: sails.config.i18n.localesDirectory, extension: ".json"})
|
250
|
+
i18n.setLocale(connectionParams["locale"]);
|
251
|
+
exContext["i18n"] = i18n;
|
252
|
+
|
253
|
+
}
|
254
|
+
exContext["pubsub"] = pubsub;
|
255
|
+
return exContext;
|
256
|
+
},
|
257
|
+
},
|
258
|
+
formatError: (error: GraphQLError) => {
|
259
|
+
const graphQLFormattedError: GraphQLFormattedError = {
|
260
|
+
message: `${error.path}: ${error.message}`,
|
261
|
+
...process.env.NODE_ENV !== "production" && {
|
262
|
+
locations: error.extensions.exception.stacktrace,
|
263
|
+
path: error.path
|
157
264
|
},
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
265
|
+
}
|
266
|
+
return graphQLFormattedError;
|
267
|
+
},
|
268
|
+
context: ({ req, connection }) => {
|
269
|
+
if (connection && connection.context) {
|
270
|
+
return connection.context;
|
271
|
+
} else {
|
272
|
+
const headers = {};
|
273
|
+
if(req?.rawHeaders) {
|
274
|
+
for (let i = 0; i < req.rawHeaders.length; i += 2) {
|
275
|
+
const name = req.rawHeaders[i];
|
276
|
+
const value = req.rawHeaders[i + 1];
|
277
|
+
headers[name.toLowerCase()] = value;
|
163
278
|
}
|
164
279
|
}
|
165
|
-
|
280
|
+
if (headers["x-device-id"] || headers["X-Device-Id"]) {
|
281
|
+
headers["deviceId"] = headers["x-device-id"] ? headers["x-device-id"] : headers["X-Device-Id"];
|
282
|
+
}
|
283
|
+
|
284
|
+
if (!headers["authorization"] && headers["Authorization"]) {
|
285
|
+
headers["authorization"] = headers["Authorization"];
|
286
|
+
}
|
287
|
+
|
288
|
+
// set context locale
|
289
|
+
headers["locale"] = sails.config.i18n.defaultLocale
|
290
|
+
const acceptLanguge = headers["Accept-Language"] ?? headers["accept-language"] ?? false
|
291
|
+
if(acceptLanguge){
|
292
|
+
headers["locale"] = (langParser.parse(acceptLanguge))[0]?.code ?? sails.config.i18n.defaultLocale
|
293
|
+
}
|
294
|
+
|
295
|
+
const i18n = new i18nFactory({...sails.config.i18n, directory: sails.config.i18n.localesDirectory, extension: ".json"})
|
296
|
+
i18n.setLocale(headers["locale"]);
|
297
|
+
return { ...req, connectionParams: headers, i18n: i18n };
|
298
|
+
}
|
299
|
+
},
|
300
|
+
});
|
166
301
|
} catch (error) {
|
167
|
-
|
168
|
-
|
302
|
+
if (error.locations && error.locations[0].line) {
|
303
|
+
typeDefs.split("\n").forEach((item, i) => {
|
304
|
+
if (Math.abs(error.locations[0].line - i) < 10) {
|
305
|
+
console.log(i, `|`, item);
|
306
|
+
if (error.locations[0].line - 1 === i) {
|
307
|
+
console.log("_______________");
|
308
|
+
}
|
309
|
+
}
|
310
|
+
});
|
311
|
+
console.log(
|
312
|
+
`ERROR LINE: ${error.locations[0].line} `,
|
313
|
+
typeDefs.split("\n", -1)[error.locations[0].line - 1]
|
314
|
+
);
|
315
|
+
}
|
169
316
|
|
317
|
+
console.error(JSON.stringify(error));
|
318
|
+
throw error;
|
319
|
+
}
|
170
320
|
server = apolloServer;
|
171
321
|
return apolloServer;
|
172
|
-
}
|
173
|
-
}
|
322
|
+
},
|
323
|
+
};
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import UserBonusProgram from "@webresto/core/models/UserBonusProgram";
|
2
|
+
declare const _default: {
|
3
|
+
Query: {
|
4
|
+
bonusProgram: {
|
5
|
+
def: string;
|
6
|
+
fn: (parent: any, args: any, context: any) => Promise<import("@webresto/core/models/BonusProgram").default[]>;
|
7
|
+
};
|
8
|
+
};
|
9
|
+
Mutation: {
|
10
|
+
userRegistrationInBonusProgram: {
|
11
|
+
def: string;
|
12
|
+
fn: (parent: any, payload: {
|
13
|
+
bonusProgramId: string;
|
14
|
+
}, context: {
|
15
|
+
connectionParams: {
|
16
|
+
authorization: string;
|
17
|
+
};
|
18
|
+
}) => Promise<UserBonusProgram>;
|
19
|
+
};
|
20
|
+
userDeleteInBonusProgram: {
|
21
|
+
def: string;
|
22
|
+
fn: (parent: any, payload: {
|
23
|
+
bonusProgramId: string;
|
24
|
+
}, context: {
|
25
|
+
connectionParams: {
|
26
|
+
authorization: string;
|
27
|
+
};
|
28
|
+
}) => Promise<boolean>;
|
29
|
+
};
|
30
|
+
};
|
31
|
+
};
|
32
|
+
export default _default;
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
// export interface SpendBonus {
|
3
|
+
// bonusProgramId: string
|
4
|
+
// amount: number
|
5
|
+
// adapter: string
|
6
|
+
// bonusProgramName: string
|
7
|
+
// }
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
+
const jwt_1 = require("../../lib/jwt");
|
10
|
+
exports.default = {
|
11
|
+
Query: {
|
12
|
+
bonusProgram: {
|
13
|
+
def: 'bonusProgramAlived(orderId: String): [BonusProgram]',
|
14
|
+
fn: async function (parent, args, context) {
|
15
|
+
const orderId = args.orderId;
|
16
|
+
try {
|
17
|
+
if (orderId) {
|
18
|
+
const order = await Order.findOne({ id: orderId });
|
19
|
+
if (!order)
|
20
|
+
throw `order not found`;
|
21
|
+
}
|
22
|
+
const data = await BonusProgram.getAvailable();
|
23
|
+
await emitter.emit('graphql-return-bonus-program', orderId, data);
|
24
|
+
return data;
|
25
|
+
}
|
26
|
+
catch (e) {
|
27
|
+
sails.log.error(e);
|
28
|
+
throw `${JSON.stringify(e)}`;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
},
|
33
|
+
Mutation: {
|
34
|
+
// Authentication required
|
35
|
+
userRegistrationInBonusProgram: {
|
36
|
+
def: `#graphql
|
37
|
+
userRegistrationInBonusProgram(
|
38
|
+
bonusProgramId: String!
|
39
|
+
): UserBonusProgram`,
|
40
|
+
fn: async (parent, payload, context) => {
|
41
|
+
const auth = await jwt_1.JWTAuth.verify(context.connectionParams.authorization);
|
42
|
+
let adapter = await BonusProgram.getAdapter(payload.bonusProgramId);
|
43
|
+
return await UserBonusProgram.registration(auth.userId, adapter.id);
|
44
|
+
}
|
45
|
+
},
|
46
|
+
// Authentication required
|
47
|
+
userDeleteInBonusProgram: {
|
48
|
+
def: `#graphql
|
49
|
+
userDeleteInBonusProgram(
|
50
|
+
bonusProgramId: String!
|
51
|
+
): Boolean`,
|
52
|
+
fn: async (parent, payload, context) => {
|
53
|
+
const auth = await jwt_1.JWTAuth.verify(context.connectionParams.authorization);
|
54
|
+
let adapter = await BonusProgram.getAdapter(payload.bonusProgramId);
|
55
|
+
try {
|
56
|
+
await UserBonusProgram.delete(auth.userId, adapter.id);
|
57
|
+
return true;
|
58
|
+
}
|
59
|
+
catch (error) {
|
60
|
+
throw `Error deleting user in bonus program`;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
};
|
@@ -0,0 +1,79 @@
|
|
1
|
+
// export interface SpendBonus {
|
2
|
+
// bonusProgramId: string
|
3
|
+
// amount: number
|
4
|
+
// adapter: string
|
5
|
+
// bonusProgramName: string
|
6
|
+
// }
|
7
|
+
|
8
|
+
import { JWTAuth } from "../../lib/jwt";
|
9
|
+
import UserBonusProgram from "@webresto/core/models/UserBonusProgram";
|
10
|
+
|
11
|
+
export default {
|
12
|
+
Query: {
|
13
|
+
bonusProgram: {
|
14
|
+
def: 'bonusProgramAlived(orderId: String): [BonusProgram]',
|
15
|
+
fn: async function (parent, args, context) {
|
16
|
+
const orderId = args.orderId;
|
17
|
+
try {
|
18
|
+
if (orderId) {
|
19
|
+
const order = await Order.findOne({id: orderId});
|
20
|
+
if(!order) throw `order not found`
|
21
|
+
}
|
22
|
+
|
23
|
+
const data = await BonusProgram.getAvailable();
|
24
|
+
await emitter.emit('graphql-return-bonus-program', orderId, data);
|
25
|
+
return data;
|
26
|
+
} catch (e) {
|
27
|
+
sails.log.error(e);
|
28
|
+
throw `${JSON.stringify(e)}`
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
},
|
33
|
+
Mutation: {
|
34
|
+
// Authentication required
|
35
|
+
userRegistrationInBonusProgram: {
|
36
|
+
def: `#graphql
|
37
|
+
userRegistrationInBonusProgram(
|
38
|
+
bonusProgramId: String!
|
39
|
+
): UserBonusProgram`,
|
40
|
+
fn: async (
|
41
|
+
parent: any,
|
42
|
+
payload: { bonusProgramId: string },
|
43
|
+
context: { connectionParams: { authorization: string } }
|
44
|
+
): Promise<UserBonusProgram> => {
|
45
|
+
|
46
|
+
const auth = await JWTAuth.verify(
|
47
|
+
context.connectionParams.authorization
|
48
|
+
);
|
49
|
+
let adapter = await BonusProgram.getAdapter(payload.bonusProgramId);
|
50
|
+
|
51
|
+
return await UserBonusProgram.registration(auth.userId, adapter.id);
|
52
|
+
}
|
53
|
+
},
|
54
|
+
// Authentication required
|
55
|
+
userDeleteInBonusProgram: {
|
56
|
+
def: `#graphql
|
57
|
+
userDeleteInBonusProgram(
|
58
|
+
bonusProgramId: String!
|
59
|
+
): Boolean`,
|
60
|
+
fn: async (
|
61
|
+
parent: any,
|
62
|
+
payload: { bonusProgramId: string },
|
63
|
+
context: { connectionParams: { authorization: string } }
|
64
|
+
): Promise<boolean> => {
|
65
|
+
|
66
|
+
const auth = await JWTAuth.verify(
|
67
|
+
context.connectionParams.authorization
|
68
|
+
);
|
69
|
+
let adapter = await BonusProgram.getAdapter(payload.bonusProgramId);
|
70
|
+
try {
|
71
|
+
await UserBonusProgram.delete(auth.userId, adapter.id);
|
72
|
+
return true
|
73
|
+
} catch (error) {
|
74
|
+
throw `Error deleting user in bonus program`
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
declare const _default: {
|
2
|
+
Query: {
|
3
|
+
captchaGetJob: {
|
4
|
+
def: string;
|
5
|
+
fn: (parent: any, args: {
|
6
|
+
label: string;
|
7
|
+
}, context: any, info: any) => Promise<import("@webresto/core/adapters/captcha/CaptchaAdapter").CaptchaJob>;
|
8
|
+
};
|
9
|
+
};
|
10
|
+
};
|
11
|
+
export default _default;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const index_1 = require("@webresto/core/adapters/index");
|
4
|
+
exports.default = {
|
5
|
+
Query: {
|
6
|
+
captchaGetJob: {
|
7
|
+
def: 'captchaGetJob(label: String): CaptchaJob',
|
8
|
+
fn: async (parent, args, context, info) => {
|
9
|
+
try {
|
10
|
+
return (await index_1.Captcha.getAdapter()).getJob(args.label);
|
11
|
+
}
|
12
|
+
catch (error) {
|
13
|
+
sails.log.error(error);
|
14
|
+
throw error;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
};
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { Captcha } from "@webresto/core/adapters/index"
|
2
|
+
export default {
|
3
|
+
Query: {
|
4
|
+
captchaGetJob: {
|
5
|
+
def: 'captchaGetJob(label: String): CaptchaJob',
|
6
|
+
fn: async (parent: any, args: { label: string } , context: any, info: any) => {
|
7
|
+
try {
|
8
|
+
return (await Captcha.getAdapter()).getJob(args.label)
|
9
|
+
} catch (error) {
|
10
|
+
sails.log.error(error)
|
11
|
+
throw error
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
@@ -1,36 +1,55 @@
|
|
1
|
+
import { Action, Message } from "../../types/primitives";
|
2
|
+
import Order from "@webresto/core/models/Order";
|
3
|
+
type CheckResponse = {
|
4
|
+
order?: Order;
|
5
|
+
message: Message;
|
6
|
+
action?: Action;
|
7
|
+
};
|
8
|
+
import Address from "@webresto/core/interfaces/Address";
|
9
|
+
import Customer from "@webresto/core/interfaces/Customer";
|
10
|
+
import { SpendBonus } from "@webresto/core/interfaces/SpendBonus";
|
11
|
+
interface InputOrderCheckout {
|
12
|
+
orderId: string;
|
13
|
+
paymentMethodId: string;
|
14
|
+
selfService?: boolean;
|
15
|
+
pickupPointId?: string;
|
16
|
+
address?: Address;
|
17
|
+
locationId: string;
|
18
|
+
customer: Customer;
|
19
|
+
date?: string;
|
20
|
+
personsCount?: number;
|
21
|
+
comment: string;
|
22
|
+
spendBonus: SpendBonus;
|
23
|
+
customData: {
|
24
|
+
[key: string]: string | number;
|
25
|
+
};
|
26
|
+
}
|
1
27
|
declare const _default: {
|
2
28
|
Mutation: {
|
3
29
|
checkOrder: {
|
4
30
|
def: string;
|
5
|
-
fn: (parent: any, args:
|
6
|
-
|
7
|
-
|
8
|
-
} | {
|
9
|
-
message: {
|
10
|
-
type: string;
|
11
|
-
title: string;
|
12
|
-
message: string;
|
13
|
-
};
|
14
|
-
order?: undefined;
|
15
|
-
}>;
|
31
|
+
fn: (parent: any, args: {
|
32
|
+
orderCheckout: InputOrderCheckout;
|
33
|
+
}, context: any) => Promise<CheckResponse>;
|
16
34
|
};
|
17
35
|
sendOrder: {
|
18
36
|
def: string;
|
19
37
|
fn: (parent: any, args: any, context: any) => Promise<{
|
20
|
-
order:
|
38
|
+
order: Order;
|
21
39
|
action: {
|
40
|
+
deviceId: any;
|
22
41
|
type: string;
|
23
42
|
data: {
|
24
|
-
|
43
|
+
link: string;
|
25
44
|
};
|
26
45
|
};
|
27
46
|
message?: undefined;
|
28
47
|
} | {
|
29
|
-
order:
|
48
|
+
order: Order;
|
30
49
|
message: {
|
31
50
|
type: string;
|
32
|
-
title:
|
33
|
-
message:
|
51
|
+
title: any;
|
52
|
+
message: any;
|
34
53
|
};
|
35
54
|
action?: undefined;
|
36
55
|
}>;
|