@webresto/graphql 1.3.2 → 1.3.5

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 (71) hide show
  1. package/lib/eventHelper.js +1 -0
  2. package/lib/eventHelper.ts +1 -0
  3. package/package.json +1 -1
  4. package/src/additionalResolvers.js +33 -5
  5. package/src/additionalResolvers.ts +38 -5
  6. package/src/graphql.js +35 -22
  7. package/src/graphql.ts +38 -25
  8. package/src/resolvers/cart.d.ts +225 -7
  9. package/src/resolvers/cart.js +21 -7
  10. package/src/resolvers/cart.ts +23 -8
  11. package/src/resolvers/checkout.js +9 -7
  12. package/src/resolvers/checkout.ts +14 -9
  13. package/test/{_bootstrap.js → bootstrap.js} +6 -7
  14. package/test/bootstrap.ts +3 -0
  15. package/test/fixture/.sailsrc +14 -0
  16. package/test/fixture/api/controllers/.gitkeep +0 -0
  17. package/test/fixture/api/models/.gitkeep +0 -0
  18. package/test/fixture/api/services/.gitkeep +0 -0
  19. package/test/fixture/app-export.js +73 -73
  20. package/test/fixture/app.js +56 -56
  21. package/test/fixture/config/adminpanel.js +25 -3
  22. package/test/fixture/config/bootstrap.js +161 -0
  23. package/test/fixture/config/connections.js +9 -9
  24. package/test/fixture/config/env/development.js +10 -10
  25. package/test/fixture/config/env/production.js +16 -16
  26. package/test/fixture/config/globals.js +16 -16
  27. package/test/fixture/config/hookTimeout.js +8 -8
  28. package/test/fixture/config/http.js +93 -93
  29. package/test/fixture/config/i18n.js +57 -57
  30. package/test/fixture/config/log.js +29 -29
  31. package/test/fixture/config/models.js +8 -8
  32. package/test/fixture/config/modulemanager.js +22 -22
  33. package/test/fixture/config/policies.js +51 -51
  34. package/test/fixture/config/routes.js +49 -49
  35. package/test/fixture/config/session.js +100 -100
  36. package/test/fixture/config/sockets.js +141 -141
  37. package/test/fixture/config/views.js +94 -94
  38. package/test/fixture/hacks/waterline.js +39 -0
  39. package/test/fixture/package.json +33 -30
  40. package/test/fixture/seeds/dish.json +37042 -0
  41. package/test/fixture/seeds/group.json +1418 -0
  42. package/test/fixture/seeds/iikoDiscount.json +365 -0
  43. package/test/fixture/views/403.ejs +68 -68
  44. package/test/fixture/views/404.ejs +68 -68
  45. package/test/fixture/views/500.ejs +73 -73
  46. package/test/fixture/views/homepage.ejs +74 -74
  47. package/test/fixture/views/layout.ejs +91 -91
  48. package/test/integration/graphql.test.js +11 -0
  49. package/test/integration/graphql.test.ts +15 -0
  50. package/test/integration/order.test.js +86 -0
  51. package/test/integration/order.test.ts +108 -0
  52. package/test/{unit → integration}/sails_not_crash.test.js +0 -0
  53. package/test/{unit → integration}/sails_not_crash.test.ts +0 -0
  54. package/test/unit/first.test.js +1 -1
  55. package/test/unit/first.test.ts +1 -1
  56. package/test/fixture/.tmp/localDiskDb/archive.db +0 -1
  57. package/test/fixture/.tmp/localDiskDb/dish.db +0 -1
  58. package/test/fixture/.tmp/localDiskDb/dish_images__image_dish.db +0 -1
  59. package/test/fixture/.tmp/localDiskDb/group.db +0 -1
  60. package/test/fixture/.tmp/localDiskDb/group_images__image_group.db +0 -1
  61. package/test/fixture/.tmp/localDiskDb/image.db +0 -1
  62. package/test/fixture/.tmp/localDiskDb/maintenance.db +0 -1
  63. package/test/fixture/.tmp/localDiskDb/order.db +0 -1
  64. package/test/fixture/.tmp/localDiskDb/orderdish.db +0 -1
  65. package/test/fixture/.tmp/localDiskDb/paymentdocument.db +0 -1
  66. package/test/fixture/.tmp/localDiskDb/paymentmethod.db +0 -2
  67. package/test/fixture/.tmp/localDiskDb/place.db +0 -1
  68. package/test/fixture/.tmp/localDiskDb/settings.db +0 -2
  69. package/test/fixture/.tmp/localDiskDb/street.db +0 -1
  70. package/test/fixture/package-lock.json +0 -9805
  71. package/test.zip +0 -0
@@ -8,6 +8,7 @@ exports.default = {
8
8
  sendAction
9
9
  };
10
10
  function sendMessage(orderId, message) {
11
+ console.log({ orderId, message });
11
12
  const pubsub = graphql_1.default.getPubsub();
12
13
  pubsub.publish("message", { orderId, message });
13
14
  }
@@ -11,6 +11,7 @@ export {
11
11
  }
12
12
 
13
13
  function sendMessage(orderId: String, message: any) {
14
+ console.log({orderId, message})
14
15
  const pubsub = graphql.getPubsub();
15
16
  pubsub.publish("message", {orderId, message});
16
17
  }
package/package.json CHANGED
@@ -60,5 +60,5 @@
60
60
  "test:js": "mocha test/bootstrap.js './test/{,!(fixture)/**}/*.test.js' --exit",
61
61
  "test:init": "cd ./test/fixture && npm i --no-package-lock --prefix ./ && cd -"
62
62
  },
63
- "version": "1.3.2"
63
+ "version": "1.3.5"
64
64
  }
@@ -46,7 +46,7 @@ exports.additionalResolver = {
46
46
  },
47
47
  OrderModifier: {
48
48
  dish: async (parent, args, context, info) => {
49
- return (await Dish.find({ id: parent.id, balance: { "!": 0 }, isDeleted: false }).populateAll())[0];
49
+ return (await Dish.find({ id: parent.id, balance: { "!=": 0 }, isDeleted: false }).populateAll())[0];
50
50
  },
51
51
  group: async (parent, args) => {
52
52
  return (await Group.find({ id: parent.groupId, isDeleted: false }).populateAll())[0];
@@ -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
  };
@@ -43,7 +43,7 @@ export const additionalResolver = {
43
43
 
44
44
  OrderModifier: {
45
45
  dish: async (parent, args, context, info) => {
46
- return (await Dish.find({id: parent.id, balance: { "!": 0 }, isDeleted: false}).populateAll())[0];
46
+ return (await Dish.find({id: parent.id, balance: { "!=": 0 }, isDeleted: false}).populateAll())[0];
47
47
  },
48
48
  group: async (parent, args) => {
49
49
  return (await Group.find({id: parent.groupId, isDeleted: false}).populateAll())[0];
@@ -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
@@ -98,6 +98,13 @@ exports.default = {
98
98
  type Subscription {
99
99
  _root: String
100
100
  }`);
101
+ /**
102
+ * Discount fields global support
103
+ */
104
+ helper.addCustomField("Dish", "discountAmount: Float");
105
+ helper.addCustomField("Dish", "discountType: String");
106
+ helper.addCustomField("Dish", "oldPrice: Float");
107
+ helper.addCustomField("Group", "discount: String");
101
108
  const { typeDefs, resolvers } = helper.getSchema();
102
109
  getEmitter_1.default().on('core-order-after-count', 'graphql', function (order) {
103
110
  pubsub.publish("order-changed", order);
@@ -114,30 +121,36 @@ exports.default = {
114
121
  getEmitter_1.default().on("core-maintenance-disabled", "graphql", function () {
115
122
  pubsub.publish("maintenance", null);
116
123
  });
117
- const apolloServer = new ApolloServer({
118
- typeDefs,
119
- resolvers: [resolvers, AdditionalResolvers],
120
- subscriptions: {
121
- onConnect: (connectionParams, webSocket) => {
122
- let exContext = {};
123
- if (connectionParams) {
124
- if (!connectionParams['authorization'] && connectionParams['Authorization'])
125
- connectionParams['authorization'] = connectionParams['Authorization'];
126
- exContext['connectionParams'] = connectionParams;
127
- }
128
- exContext['pubsub'] = pubsub;
129
- return exContext;
124
+ let apolloServer;
125
+ try {
126
+ apolloServer = new ApolloServer({
127
+ typeDefs,
128
+ resolvers: [resolvers, AdditionalResolvers],
129
+ subscriptions: {
130
+ onConnect: (connectionParams, webSocket) => {
131
+ let exContext = {};
132
+ if (connectionParams) {
133
+ if (!connectionParams['authorization'] && connectionParams['Authorization'])
134
+ connectionParams['authorization'] = connectionParams['Authorization'];
135
+ exContext['connectionParams'] = connectionParams;
136
+ }
137
+ exContext['pubsub'] = pubsub;
138
+ return exContext;
139
+ },
130
140
  },
131
- },
132
- context: async ({ req, connection }) => {
133
- if (connection) {
134
- return connection.context;
135
- }
136
- else {
137
- return { ...req };
141
+ context: async ({ req, connection }) => {
142
+ if (connection) {
143
+ return connection.context;
144
+ }
145
+ else {
146
+ return { ...req };
147
+ }
138
148
  }
139
- }
140
- });
149
+ });
150
+ }
151
+ catch (error) {
152
+ console.error("GraphQL start error: ", error);
153
+ }
141
154
  server = apolloServer;
142
155
  return apolloServer;
143
156
  }
package/src/graphql.ts CHANGED
@@ -110,6 +110,14 @@ export default {
110
110
  type Subscription {
111
111
  _root: String
112
112
  }`);
113
+
114
+ /**
115
+ * Discount fields global support
116
+ */
117
+ helper.addCustomField("Dish", "discountAmount: Float")
118
+ helper.addCustomField("Dish", "discountType: String")
119
+ helper.addCustomField("Dish", "oldPrice: Float")
120
+ helper.addCustomField("Group", "discount: String")
113
121
 
114
122
  const { typeDefs, resolvers } = helper.getSchema();
115
123
 
@@ -128,31 +136,36 @@ export default {
128
136
  getEmitter().on("core-maintenance-disabled", "graphql", function () {
129
137
  pubsub.publish("maintenance", null);
130
138
  });
131
-
132
- const apolloServer = new ApolloServer({
133
- typeDefs,
134
- resolvers: [resolvers, AdditionalResolvers],
135
- subscriptions: {
136
- onConnect: (connectionParams, webSocket) => {
137
- let exContext = {}
138
- if (connectionParams) {
139
- if (!connectionParams['authorization'] && connectionParams['Authorization'])
140
- connectionParams['authorization'] = connectionParams['Authorization'];
141
-
142
- exContext['connectionParams'] = connectionParams
143
- }
144
- exContext['pubsub'] = pubsub;
145
- return exContext;
146
- },
147
- },
148
- context: async ({ req , connection}) => {
149
- if (connection) {
150
- return connection.context;
151
- } else {
152
- return { ...req };
153
- }
154
- }
155
- });
139
+
140
+ let apolloServer
141
+ try {
142
+ apolloServer = new ApolloServer({
143
+ typeDefs,
144
+ resolvers: [resolvers, AdditionalResolvers],
145
+ subscriptions: {
146
+ onConnect: (connectionParams, webSocket) => {
147
+ let exContext = {}
148
+ if (connectionParams) {
149
+ if (!connectionParams['authorization'] && connectionParams['Authorization'])
150
+ connectionParams['authorization'] = connectionParams['Authorization'];
151
+
152
+ exContext['connectionParams'] = connectionParams
153
+ }
154
+ exContext['pubsub'] = pubsub;
155
+ return exContext;
156
+ },
157
+ },
158
+ context: async ({ req , connection}) => {
159
+ if (connection) {
160
+ return connection.context;
161
+ } else {
162
+ return { ...req };
163
+ }
164
+ }
165
+ });
166
+ } catch (error) {
167
+ console.error("GraphQL start error: ", error)
168
+ }
156
169
 
157
170
  server = apolloServer;
158
171
  return apolloServer;
@@ -6,7 +6,6 @@ declare const _default: {
6
6
  id: string;
7
7
  shortId: string;
8
8
  dishes: number[] | import("@webresto/core/models/OrderDish").default[];
9
- discount: any;
10
9
  paymentMethod: any;
11
10
  paymentMethodTitle: string;
12
11
  paid: {
@@ -53,23 +52,243 @@ declare const _default: {
53
52
  Mutation: {
54
53
  orderAddDish: {
55
54
  def: string;
56
- fn: (parent: any, args: any, context: any) => Promise<import("@webresto/core/models/Order").default>;
55
+ fn: (parent: any, args: any, context: any) => Promise<{
56
+ id: string;
57
+ shortId: string;
58
+ dishes: number[] | import("@webresto/core/models/OrderDish").default[];
59
+ paymentMethod: any;
60
+ paymentMethodTitle: string;
61
+ paid: {
62
+ type: string;
63
+ defaultsTo: boolean;
64
+ };
65
+ isPaymentPromise: boolean;
66
+ dishesCount: number;
67
+ uniqueDishes: number;
68
+ modifiers: any;
69
+ customer: any;
70
+ address: any;
71
+ comment: string;
72
+ personsCount: string;
73
+ date: string;
74
+ problem: boolean;
75
+ rmsDelivered: boolean;
76
+ rmsId: string;
77
+ rmsOrderNumber: string;
78
+ rmsOrderData: any;
79
+ rmsDeliveryDate: string;
80
+ rmsErrorMessage: string;
81
+ rmsErrorCode: string;
82
+ rmsStatusCode: string;
83
+ deliveryStatus: string;
84
+ selfService: boolean;
85
+ deliveryDescription: string;
86
+ message: string;
87
+ deliveryItem: any;
88
+ deliveryCost: number;
89
+ totalWeight: number;
90
+ trifleFrom: number;
91
+ bonusesTotal: number;
92
+ total: number;
93
+ orderTotal: number;
94
+ discountTotal: number;
95
+ orderDate: string;
96
+ customData: any;
97
+ state: string;
98
+ toJSON(): any;
99
+ }>;
57
100
  };
58
101
  orderReplaceDish: {
59
102
  def: string;
60
- fn: (parent: any, args: any, context: any) => Promise<import("@webresto/core/models/Order").default>;
103
+ fn: (parent: any, args: any, context: any) => Promise<{
104
+ id: string;
105
+ shortId: string;
106
+ dishes: number[] | import("@webresto/core/models/OrderDish").default[];
107
+ paymentMethod: any;
108
+ paymentMethodTitle: string;
109
+ paid: {
110
+ type: string;
111
+ defaultsTo: boolean;
112
+ };
113
+ isPaymentPromise: boolean;
114
+ dishesCount: number;
115
+ uniqueDishes: number;
116
+ modifiers: any;
117
+ customer: any;
118
+ address: any;
119
+ comment: string;
120
+ personsCount: string;
121
+ date: string;
122
+ problem: boolean;
123
+ rmsDelivered: boolean;
124
+ rmsId: string;
125
+ rmsOrderNumber: string;
126
+ rmsOrderData: any;
127
+ rmsDeliveryDate: string;
128
+ rmsErrorMessage: string;
129
+ rmsErrorCode: string;
130
+ rmsStatusCode: string;
131
+ deliveryStatus: string;
132
+ selfService: boolean;
133
+ deliveryDescription: string;
134
+ message: string;
135
+ deliveryItem: any;
136
+ deliveryCost: number;
137
+ totalWeight: number;
138
+ trifleFrom: number;
139
+ bonusesTotal: number;
140
+ total: number;
141
+ orderTotal: number;
142
+ discountTotal: number;
143
+ orderDate: string;
144
+ customData: any;
145
+ state: string;
146
+ toJSON(): any;
147
+ }>;
61
148
  };
62
149
  orderRemoveDish: {
63
150
  def: string;
64
- fn: (parent: any, args: any, context: any) => Promise<import("@webresto/core/models/Order").default>;
151
+ fn: (parent: any, args: any, context: any) => Promise<{
152
+ id: string;
153
+ shortId: string;
154
+ dishes: number[] | import("@webresto/core/models/OrderDish").default[];
155
+ paymentMethod: any;
156
+ paymentMethodTitle: string;
157
+ paid: {
158
+ type: string;
159
+ defaultsTo: boolean;
160
+ };
161
+ isPaymentPromise: boolean;
162
+ dishesCount: number;
163
+ uniqueDishes: number;
164
+ modifiers: any;
165
+ customer: any;
166
+ address: any;
167
+ comment: string;
168
+ personsCount: string;
169
+ date: string;
170
+ problem: boolean;
171
+ rmsDelivered: boolean;
172
+ rmsId: string;
173
+ rmsOrderNumber: string;
174
+ rmsOrderData: any;
175
+ rmsDeliveryDate: string;
176
+ rmsErrorMessage: string;
177
+ rmsErrorCode: string;
178
+ rmsStatusCode: string;
179
+ deliveryStatus: string;
180
+ selfService: boolean;
181
+ deliveryDescription: string;
182
+ message: string;
183
+ deliveryItem: any;
184
+ deliveryCost: number;
185
+ totalWeight: number;
186
+ trifleFrom: number;
187
+ bonusesTotal: number;
188
+ total: number;
189
+ orderTotal: number;
190
+ discountTotal: number;
191
+ orderDate: string;
192
+ customData: any;
193
+ state: string;
194
+ toJSON(): any;
195
+ }>;
65
196
  };
66
197
  orderSetDishAmount: {
67
198
  def: string;
68
- fn: (parent: any, args: any, context: any) => Promise<import("@webresto/core/models/Order").default>;
199
+ fn: (parent: any, args: any, context: any) => Promise<{
200
+ id: string;
201
+ shortId: string;
202
+ dishes: number[] | import("@webresto/core/models/OrderDish").default[];
203
+ paymentMethod: any;
204
+ paymentMethodTitle: string;
205
+ paid: {
206
+ type: string;
207
+ defaultsTo: boolean;
208
+ };
209
+ isPaymentPromise: boolean;
210
+ dishesCount: number;
211
+ uniqueDishes: number;
212
+ modifiers: any;
213
+ customer: any;
214
+ address: any;
215
+ comment: string;
216
+ personsCount: string;
217
+ date: string;
218
+ problem: boolean;
219
+ rmsDelivered: boolean;
220
+ rmsId: string;
221
+ rmsOrderNumber: string;
222
+ rmsOrderData: any;
223
+ rmsDeliveryDate: string;
224
+ rmsErrorMessage: string;
225
+ rmsErrorCode: string;
226
+ rmsStatusCode: string;
227
+ deliveryStatus: string;
228
+ selfService: boolean;
229
+ deliveryDescription: string;
230
+ message: string;
231
+ deliveryItem: any;
232
+ deliveryCost: number;
233
+ totalWeight: number;
234
+ trifleFrom: number;
235
+ bonusesTotal: number;
236
+ total: number;
237
+ orderTotal: number;
238
+ discountTotal: number;
239
+ orderDate: string;
240
+ customData: any;
241
+ state: string;
242
+ toJSON(): any;
243
+ }>;
69
244
  };
70
245
  orderSetDishComment: {
71
246
  def: string;
72
- fn: (parent: any, args: any, context: any) => Promise<import("@webresto/core/models/Order").default>;
247
+ fn: (parent: any, args: any, context: any) => Promise<{
248
+ id: string;
249
+ shortId: string;
250
+ dishes: number[] | import("@webresto/core/models/OrderDish").default[];
251
+ paymentMethod: any;
252
+ paymentMethodTitle: string;
253
+ paid: {
254
+ type: string;
255
+ defaultsTo: boolean;
256
+ };
257
+ isPaymentPromise: boolean;
258
+ dishesCount: number;
259
+ uniqueDishes: number;
260
+ modifiers: any;
261
+ customer: any;
262
+ address: any;
263
+ comment: string;
264
+ personsCount: string;
265
+ date: string;
266
+ problem: boolean;
267
+ rmsDelivered: boolean;
268
+ rmsId: string;
269
+ rmsOrderNumber: string;
270
+ rmsOrderData: any;
271
+ rmsDeliveryDate: string;
272
+ rmsErrorMessage: string;
273
+ rmsErrorCode: string;
274
+ rmsStatusCode: string;
275
+ deliveryStatus: string;
276
+ selfService: boolean;
277
+ deliveryDescription: string;
278
+ message: string;
279
+ deliveryItem: any;
280
+ deliveryCost: number;
281
+ totalWeight: number;
282
+ trifleFrom: number;
283
+ bonusesTotal: number;
284
+ total: number;
285
+ orderTotal: number;
286
+ discountTotal: number;
287
+ orderDate: string;
288
+ customData: any;
289
+ state: string;
290
+ toJSON(): any;
291
+ }>;
73
292
  };
74
293
  orderUpdate: {
75
294
  def: string;
@@ -77,7 +296,6 @@ declare const _default: {
77
296
  id: string;
78
297
  shortId: string;
79
298
  dishes: number[] | import("@webresto/core/models/OrderDish").default[];
80
- discount: any;
81
299
  paymentMethod: any;
82
300
  paymentMethodTitle: string;
83
301
  paid: {
@@ -27,7 +27,9 @@ exports.default = {
27
27
  sails.log.error("GQL > order resolver error: ", `order with id ${args.orderId} . Trying make new cart.`);
28
28
  order = await getNewCart(args.orderId);
29
29
  }
30
- return await Order.populate(order.id);
30
+ let fullOrder = await Order.populate(order.id);
31
+ getEmitter_1.default().emit("http-api:before-response-order", fullOrder);
32
+ return fullOrder;
31
33
  },
32
34
  },
33
35
  },
@@ -66,7 +68,9 @@ exports.default = {
66
68
  }
67
69
  await Order.addDish(order.id, args.dishId, args.amount, args.modifiers || [], args.comment, args.from, args.replace, args.orderDishId);
68
70
  await Order.countCart(order);
69
- return await Order.populate(order.id);
71
+ let fullOrder = await Order.populate(order.id);
72
+ getEmitter_1.default().emit("http-api:before-response-order-add-dish", fullOrder);
73
+ return fullOrder;
70
74
  },
71
75
  },
72
76
  orderReplaceDish: {
@@ -84,7 +88,9 @@ exports.default = {
84
88
  }
85
89
  await Order.addDish(order.id, args.dishId, args.amount, args.modifiers || [], args.comment, args.from, args.replace, args.orderDishId);
86
90
  await Order.countCart(order);
87
- return await Order.populate(order.id);
91
+ let fullOrder = await Order.populate(order.id);
92
+ getEmitter_1.default().emit("http-api:before-response-order-replace-dish", fullOrder);
93
+ return fullOrder;
88
94
  },
89
95
  },
90
96
  orderRemoveDish: {
@@ -102,7 +108,9 @@ exports.default = {
102
108
  const orderDish = await OrderDish.findOne({ id: args.orderDishId });
103
109
  await Order.removeDish(order.id, orderDish, args.amount, false);
104
110
  await Order.countCart(order);
105
- return await Order.populate(order.id);
111
+ let fullOrder = await Order.populate(order.id);
112
+ getEmitter_1.default().emit("http-api:before-response-order-remove-dish", fullOrder);
113
+ return fullOrder;
106
114
  },
107
115
  },
108
116
  orderSetDishAmount: {
@@ -124,7 +132,9 @@ exports.default = {
124
132
  throw new errorWrapper_1.Error(0, "ERROR", `Dish in OrderDish with id ${args.orderDishId} not found`);
125
133
  await Order.setCount(order.id, dish, args.amount);
126
134
  await Order.countCart(order);
127
- return await Order.populate(order.id);
135
+ let fullOrder = await Order.populate(order.id);
136
+ getEmitter_1.default().emit("http-api:before-response-order-set-dish-amount", fullOrder);
137
+ return fullOrder;
128
138
  },
129
139
  },
130
140
  orderSetDishComment: {
@@ -152,7 +162,9 @@ exports.default = {
152
162
  }
153
163
  await order.setComment(dish, comment);
154
164
  await Order.countCart(order);
155
- return await Order.populate(order.id);
165
+ let fullOrder = await Order.populate(order.id);
166
+ getEmitter_1.default().emit("http-api:before-response-order-set-dish-comment", fullOrder);
167
+ return fullOrder;
156
168
  },
157
169
  },
158
170
  orderUpdate: {
@@ -163,7 +175,9 @@ exports.default = {
163
175
  throw "order.id field is required";
164
176
  await Order.update({ id: order.id }, { trifleFrom: order.trifleFrom });
165
177
  await Order.populate(order.id);
166
- return await Order.populate(order.id);
178
+ let fullOrder = await Order.populate(order.id);
179
+ getEmitter_1.default().emit("http-api:before-response-order-update", fullOrder);
180
+ return fullOrder;
167
181
  },
168
182
  },
169
183
  },