@webresto/graphql 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/eventHelper.js +1 -0
- package/lib/eventHelper.ts +1 -0
- package/package.json +1 -1
- package/src/additionalResolvers.js +32 -4
- package/src/additionalResolvers.ts +37 -4
- package/src/graphql.js +0 -5
- package/src/graphql.ts +1 -5
- package/src/resolvers/checkout.js +9 -7
- package/src/resolvers/checkout.ts +13 -9
- package/test/fixture/app.js +1 -1
- package/test/integration/order.test.js +86 -0
- package/test/integration/order.test.ts +108 -0
package/lib/eventHelper.js
CHANGED
package/lib/eventHelper.ts
CHANGED
package/package.json
CHANGED
@@ -70,7 +70,7 @@ exports.additionalResolver = {
|
|
70
70
|
});
|
71
71
|
dataloaders.set(info.fieldNodes, dl);
|
72
72
|
}
|
73
|
-
return dl.load(parent.parentGroup);
|
73
|
+
return await dl.load(parent.parentGroup);
|
74
74
|
},
|
75
75
|
images: async (parent, args, context, info) => {
|
76
76
|
if (!parent.id)
|
@@ -87,7 +87,7 @@ exports.additionalResolver = {
|
|
87
87
|
});
|
88
88
|
dataloaders.set(info.fieldNodes, dl);
|
89
89
|
}
|
90
|
-
return dl.load(parent.id);
|
90
|
+
return await dl.load(parent.id);
|
91
91
|
}
|
92
92
|
},
|
93
93
|
Group: {
|
@@ -108,7 +108,35 @@ exports.additionalResolver = {
|
|
108
108
|
});
|
109
109
|
dataloaders.set(info.fieldNodes, dl);
|
110
110
|
}
|
111
|
-
return dl.load(parent.parentGroup);
|
111
|
+
return await dl.load(parent.parentGroup);
|
112
112
|
}
|
113
|
-
}
|
113
|
+
},
|
114
|
+
Order: {
|
115
|
+
dishes: async (parent, args, context, info) => {
|
116
|
+
if (typeof parent.dishes === "object") {
|
117
|
+
return parent.dishes;
|
118
|
+
}
|
119
|
+
return await OrderDish.find({ order: parent.id });
|
120
|
+
},
|
121
|
+
},
|
122
|
+
OrderDish: {
|
123
|
+
dish: async (parent, args, context, info) => {
|
124
|
+
if (!parent.dish)
|
125
|
+
return;
|
126
|
+
if (!context.dataloaders)
|
127
|
+
context.dataloaders = new WeakMap();
|
128
|
+
const dataloaders = context.dataloaders;
|
129
|
+
if (typeof parent.dish === "object") {
|
130
|
+
return parent.dish;
|
131
|
+
}
|
132
|
+
let dl = dataloaders.get(info.fieldNodes);
|
133
|
+
if (!dl) {
|
134
|
+
dl = new DataLoader(async (dishId) => {
|
135
|
+
return await Dish.find({ id: dishId }).sort('id ASC');
|
136
|
+
});
|
137
|
+
dataloaders.set(info.fieldNodes, dl);
|
138
|
+
}
|
139
|
+
return await dl.load(parent.dish);
|
140
|
+
},
|
141
|
+
},
|
114
142
|
};
|
@@ -68,7 +68,7 @@ export const additionalResolver = {
|
|
68
68
|
});
|
69
69
|
dataloaders.set(info.fieldNodes, dl);
|
70
70
|
}
|
71
|
-
return dl.load(parent.parentGroup);
|
71
|
+
return await dl.load(parent.parentGroup);
|
72
72
|
},
|
73
73
|
images: async (parent, args, context, info) => {
|
74
74
|
if (!parent.id) return;
|
@@ -84,7 +84,7 @@ export const additionalResolver = {
|
|
84
84
|
});
|
85
85
|
dataloaders.set(info.fieldNodes, dl);
|
86
86
|
}
|
87
|
-
return dl.load(parent.id);
|
87
|
+
return await dl.load(parent.id);
|
88
88
|
}
|
89
89
|
},
|
90
90
|
Group: {
|
@@ -105,7 +105,40 @@ export const additionalResolver = {
|
|
105
105
|
});
|
106
106
|
dataloaders.set(info.fieldNodes, dl);
|
107
107
|
}
|
108
|
-
return dl.load(parent.parentGroup);
|
108
|
+
return await dl.load(parent.parentGroup);
|
109
109
|
}
|
110
|
-
}
|
110
|
+
},
|
111
|
+
Order: {
|
112
|
+
dishes: async (parent, args, context, info) => {
|
113
|
+
if (typeof parent.dishes === "object") {
|
114
|
+
return parent.dishes;
|
115
|
+
}
|
116
|
+
|
117
|
+
return await OrderDish.find({order: parent.id});
|
118
|
+
|
119
|
+
},
|
120
|
+
|
121
|
+
},
|
122
|
+
OrderDish: {
|
123
|
+
dish: async (parent, args, context, info) => {
|
124
|
+
|
125
|
+
if (!parent.dish) return;
|
126
|
+
if (!context.dataloaders) context.dataloaders = new WeakMap();
|
127
|
+
const dataloaders = context.dataloaders;
|
128
|
+
|
129
|
+
if (typeof parent.dish === "object") {
|
130
|
+
return parent.dish;
|
131
|
+
}
|
132
|
+
|
133
|
+
let dl = dataloaders.get(info.fieldNodes);
|
134
|
+
if (!dl) {
|
135
|
+
dl = new DataLoader(async (dishId: string) => {
|
136
|
+
return await Dish.find({id: dishId}).sort('id ASC');
|
137
|
+
});
|
138
|
+
dataloaders.set(info.fieldNodes, dl);
|
139
|
+
}
|
140
|
+
return await dl.load(parent.dish);
|
141
|
+
},
|
142
|
+
|
143
|
+
},
|
111
144
|
}
|
package/src/graphql.js
CHANGED
package/src/graphql.ts
CHANGED
@@ -74,11 +74,6 @@ export default {
|
|
74
74
|
type: String
|
75
75
|
message: String
|
76
76
|
}
|
77
|
-
type Street {
|
78
|
-
id: String
|
79
|
-
name: String
|
80
|
-
customData: Json
|
81
|
-
}
|
82
77
|
type Action {
|
83
78
|
type: String
|
84
79
|
data: Json
|
@@ -141,6 +136,7 @@ export default {
|
|
141
136
|
getEmitter().on("core-maintenance-disabled", "graphql", function () {
|
142
137
|
pubsub.publish("maintenance", null);
|
143
138
|
});
|
139
|
+
|
144
140
|
let apolloServer
|
145
141
|
try {
|
146
142
|
apolloServer = new ApolloServer({
|
@@ -62,11 +62,11 @@ exports.default = {
|
|
62
62
|
order.customData.callback = data.customData.callback;
|
63
63
|
}
|
64
64
|
await Order.update({ id: order.id }, order).fetch();
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
await Order.check(order.id, data.customer, isSelfService, data.address, data.paymentMethodId);
|
66
|
+
order = await Order.findOne(data.orderId);
|
67
|
+
console.log(order.dishes);
|
68
68
|
let message;
|
69
|
-
if (
|
69
|
+
if (order.state === "CHECKOUT") {
|
70
70
|
message = {
|
71
71
|
type: "info",
|
72
72
|
title: "Внимание",
|
@@ -77,16 +77,17 @@ exports.default = {
|
|
77
77
|
}
|
78
78
|
else {
|
79
79
|
if (order.message) {
|
80
|
-
|
80
|
+
message = {
|
81
81
|
type: "error",
|
82
82
|
title: "Внимание",
|
83
83
|
message: order.message
|
84
84
|
? order.message
|
85
85
|
: "Не удалось проверить заказ.",
|
86
|
-
}
|
86
|
+
};
|
87
87
|
}
|
88
88
|
}
|
89
|
-
return
|
89
|
+
return eventHelper.sendMessage(args.orderId, message);
|
90
|
+
return { message: message, order: order };
|
90
91
|
}
|
91
92
|
catch (e) {
|
92
93
|
let message = {
|
@@ -203,6 +204,7 @@ exports.default = {
|
|
203
204
|
// }
|
204
205
|
// }
|
205
206
|
await Order.order(order.id);
|
207
|
+
order = await Order.findOne({ id: data.orderId });
|
206
208
|
const message = {
|
207
209
|
type: "info",
|
208
210
|
title: "Успешно",
|
@@ -42,6 +42,7 @@ export default {
|
|
42
42
|
message: "Корзина уже заказана",
|
43
43
|
});
|
44
44
|
}
|
45
|
+
|
45
46
|
if (data.paymentMethodId) {
|
46
47
|
if (!PaymentMethod.checkAvailable(data.paymentMethodId)) {
|
47
48
|
return eventHelper.sendMessage(args.orderId, {
|
@@ -70,19 +71,20 @@ export default {
|
|
70
71
|
|
71
72
|
await Order.update({ id: order.id }, order).fetch();
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
success = await Order.check(
|
74
|
+
await Order.check(
|
76
75
|
order.id,
|
77
76
|
data.customer,
|
78
77
|
isSelfService,
|
79
78
|
data.address,
|
80
79
|
data.paymentMethodId
|
81
80
|
);
|
82
|
-
|
81
|
+
|
82
|
+
order = await Order.findOne(data.orderId);
|
83
|
+
console.log(order.dishes)
|
84
|
+
|
83
85
|
let message;
|
84
86
|
|
85
|
-
if (
|
87
|
+
if (order.state === "CHECKOUT") {
|
86
88
|
message = {
|
87
89
|
type: "info",
|
88
90
|
title: "Внимание",
|
@@ -93,17 +95,19 @@ export default {
|
|
93
95
|
|
94
96
|
} else {
|
95
97
|
if (order.message) {
|
96
|
-
|
98
|
+
message = {
|
97
99
|
type: "error",
|
98
100
|
title: "Внимание",
|
99
101
|
message: order.message
|
100
102
|
? order.message
|
101
103
|
: "Не удалось проверить заказ.",
|
102
|
-
}
|
104
|
+
}
|
103
105
|
}
|
104
106
|
}
|
105
107
|
|
106
|
-
return
|
108
|
+
return eventHelper.sendMessage(args.orderId, message);
|
109
|
+
|
110
|
+
return { message: message, order: order };
|
107
111
|
} catch (e) {
|
108
112
|
let message = {
|
109
113
|
type: "error",
|
@@ -219,7 +223,7 @@ export default {
|
|
219
223
|
// }
|
220
224
|
|
221
225
|
await Order.order(order.id);
|
222
|
-
|
226
|
+
order = await Order.findOne({ id: data.orderId })
|
223
227
|
const message = {
|
224
228
|
type: "info",
|
225
229
|
title: "Успешно",
|
package/test/fixture/app.js
CHANGED
@@ -0,0 +1,86 @@
|
|
1
|
+
const expect = require("chai").expect;
|
2
|
+
describe('Send order to restarant', function () {
|
3
|
+
it('Create new', async () => {
|
4
|
+
const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
|
5
|
+
console.log(graphql);
|
6
|
+
const result = await graphql.getServer().executeOperation({
|
7
|
+
query: `
|
8
|
+
{order(orderId:"test-cart"){
|
9
|
+
id
|
10
|
+
total
|
11
|
+
}}`
|
12
|
+
});
|
13
|
+
expect(result.errors).to.be.undefined;
|
14
|
+
});
|
15
|
+
it('orderAddDish', async () => {
|
16
|
+
const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
|
17
|
+
console.log(graphql);
|
18
|
+
const result = await graphql.getServer().executeOperation({
|
19
|
+
query: `
|
20
|
+
mutation{orderAddDish(dishId: "df19cbbc-c026-595e-9296-1c8a378da6b3", orderId:"test-cart", amount: 1){
|
21
|
+
dishes {
|
22
|
+
dish {
|
23
|
+
id
|
24
|
+
name
|
25
|
+
price
|
26
|
+
}
|
27
|
+
itemTotal
|
28
|
+
}
|
29
|
+
total
|
30
|
+
}}
|
31
|
+
`
|
32
|
+
});
|
33
|
+
expect(result.data.orderAddDish.dishes[0].dish.id).to.equal("df19cbbc-c026-595e-9296-1c8a378da6b3");
|
34
|
+
});
|
35
|
+
it('checkOrder', async () => {
|
36
|
+
const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
|
37
|
+
console.log(graphql);
|
38
|
+
const result = await graphql.getServer().executeOperation({
|
39
|
+
query: `
|
40
|
+
mutation{checkOrder(orderId:"test-cart", paymentMethodId: "", address: {city: "town", street: "test", home: "123"}, customer: {phone: {code: "+1", number: "0000000000"}, name: "Piter Parker"}) {
|
41
|
+
order {
|
42
|
+
id
|
43
|
+
state
|
44
|
+
dishes{
|
45
|
+
dish {
|
46
|
+
name
|
47
|
+
id
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
message {
|
52
|
+
title
|
53
|
+
message
|
54
|
+
}
|
55
|
+
}}
|
56
|
+
`
|
57
|
+
});
|
58
|
+
expect(result.data.checkOrder.order.dishes[0].dish.id).to.equal("df19cbbc-c026-595e-9296-1c8a378da6b3");
|
59
|
+
});
|
60
|
+
it('sendOrder', async () => {
|
61
|
+
const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
|
62
|
+
console.log(graphql);
|
63
|
+
const result = await graphql.getServer().executeOperation({
|
64
|
+
query: `
|
65
|
+
mutation{sendOrder(orderId:"test-cart") {
|
66
|
+
order {
|
67
|
+
id
|
68
|
+
state
|
69
|
+
dishes{
|
70
|
+
dish {
|
71
|
+
name
|
72
|
+
id
|
73
|
+
}
|
74
|
+
amount
|
75
|
+
}
|
76
|
+
}
|
77
|
+
message {
|
78
|
+
title
|
79
|
+
message
|
80
|
+
}
|
81
|
+
}}
|
82
|
+
`
|
83
|
+
});
|
84
|
+
expect(result.data.sendOrder.order.state).to.equal("ORDER");
|
85
|
+
});
|
86
|
+
});
|
@@ -0,0 +1,108 @@
|
|
1
|
+
const expect = require("chai").expect;
|
2
|
+
|
3
|
+
describe('Send order to restarant', function () {
|
4
|
+
it('Create new', async () => {
|
5
|
+
|
6
|
+
const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
|
7
|
+
console.log(graphql)
|
8
|
+
const result = await graphql.getServer().executeOperation({
|
9
|
+
query: `
|
10
|
+
{order(orderId:"test-cart"){
|
11
|
+
id
|
12
|
+
total
|
13
|
+
}}`
|
14
|
+
});
|
15
|
+
|
16
|
+
expect(result.errors).to.be.undefined;
|
17
|
+
});
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
it('orderAddDish', async () => {
|
23
|
+
|
24
|
+
const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
|
25
|
+
console.log(graphql)
|
26
|
+
const result = await graphql.getServer().executeOperation({
|
27
|
+
query: `
|
28
|
+
mutation{orderAddDish(dishId: "df19cbbc-c026-595e-9296-1c8a378da6b3", orderId:"test-cart", amount: 1){
|
29
|
+
dishes {
|
30
|
+
dish {
|
31
|
+
id
|
32
|
+
name
|
33
|
+
price
|
34
|
+
}
|
35
|
+
itemTotal
|
36
|
+
}
|
37
|
+
total
|
38
|
+
}}
|
39
|
+
`
|
40
|
+
});
|
41
|
+
expect(result.data.orderAddDish.dishes[0].dish.id).to.equal("df19cbbc-c026-595e-9296-1c8a378da6b3");
|
42
|
+
});
|
43
|
+
|
44
|
+
|
45
|
+
it('checkOrder', async () => {
|
46
|
+
|
47
|
+
const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
|
48
|
+
console.log(graphql)
|
49
|
+
const result = await graphql.getServer().executeOperation({
|
50
|
+
query: `
|
51
|
+
mutation{checkOrder(orderId:"test-cart", paymentMethodId: "", address: {city: "town", street: "test", home: "123"}, customer: {phone: {code: "+1", number: "0000000000"}, name: "Piter Parker"}) {
|
52
|
+
order {
|
53
|
+
id
|
54
|
+
state
|
55
|
+
dishes{
|
56
|
+
dish {
|
57
|
+
name
|
58
|
+
id
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
message {
|
63
|
+
title
|
64
|
+
message
|
65
|
+
}
|
66
|
+
}}
|
67
|
+
`
|
68
|
+
});
|
69
|
+
expect(result.data.checkOrder.order.dishes[0].dish.id).to.equal("df19cbbc-c026-595e-9296-1c8a378da6b3");
|
70
|
+
});
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
it('sendOrder', async () => {
|
75
|
+
|
76
|
+
const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
|
77
|
+
console.log(graphql)
|
78
|
+
const result = await graphql.getServer().executeOperation({
|
79
|
+
query: `
|
80
|
+
mutation{sendOrder(orderId:"test-cart") {
|
81
|
+
order {
|
82
|
+
id
|
83
|
+
state
|
84
|
+
dishes{
|
85
|
+
dish {
|
86
|
+
name
|
87
|
+
id
|
88
|
+
}
|
89
|
+
amount
|
90
|
+
}
|
91
|
+
}
|
92
|
+
message {
|
93
|
+
title
|
94
|
+
message
|
95
|
+
}
|
96
|
+
}}
|
97
|
+
`
|
98
|
+
});
|
99
|
+
|
100
|
+
expect(result.data.sendOrder.order.state).to.equal("ORDER");
|
101
|
+
});
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
});
|
107
|
+
|
108
|
+
|