@webresto/graphql 1.3.4 → 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,6 @@ exports.default = {
8
8
  sendAction
9
9
  };
10
10
  function sendMessage(orderId, message) {
11
- console.log({ orderId, message });
12
11
  const pubsub = graphql_1.default.getPubsub();
13
12
  pubsub.publish("message", { orderId, message });
14
13
  }
@@ -11,7 +11,6 @@ export {
11
11
  }
12
12
 
13
13
  function sendMessage(orderId: String, message: any) {
14
- console.log({orderId, message})
15
14
  const pubsub = graphql.getPubsub();
16
15
  pubsub.publish("message", {orderId, message});
17
16
  }
@@ -223,17 +223,12 @@ function createType(model) {
223
223
  scalarType = scalarTypes[relationModel.attributes[relationModel.primaryKey].type];
224
224
  const name = sails.models[attributes[prop].model.toLowerCase()].globalId;
225
225
  type += ` ${prop}: ${name}\n`;
226
- // todelete
227
- type += ` ${prop}Id: ${scalarType}\n`;
228
226
  }
229
227
  // COLLECTION SCHEMA GENERATION
230
228
  if (attributes[prop].collection) {
231
229
  scalarType = scalarTypes[attributes[sails.models[attributes[prop].collection.toLowerCase()].primaryKey].type.toLowerCase()];
232
230
  const name = sails.models[attributes[prop].collection.toLowerCase()].globalId;
233
- console.log(1, scalarType);
234
231
  type += ` ${prop}: [${name}]\n`;
235
- // todelete
236
- type += ` ${prop}Ids: ${scalarType}\n`;
237
232
  }
238
233
  }
239
234
  if (customFields[modelName]) {
@@ -488,7 +483,6 @@ function addModelResolver(modelname) {
488
483
  return parent && parent[key];
489
484
  };
490
485
  });
491
- console.log(modelName, resolvers);
492
486
  modelsResolvers[modelName] = resolvers;
493
487
  // Subscription resolver
494
488
  if (!blackList.includes(`${modelName}`) && whiteList[modelname].includes('subscription')) {
@@ -228,20 +228,13 @@ function createType(model) {
228
228
  scalarType = scalarTypes[relationModel.attributes[relationModel.primaryKey].type]
229
229
  const name = sails.models[attributes[prop].model.toLowerCase()].globalId;
230
230
  type += ` ${prop}: ${name}\n`;
231
-
232
- // todelete
233
- type += ` ${prop}Id: ${scalarType}\n`;
234
231
  }
235
232
 
236
233
  // COLLECTION SCHEMA GENERATION
237
234
  if (attributes[prop].collection) {
238
235
  scalarType = scalarTypes[attributes[sails.models[attributes[prop].collection.toLowerCase()].primaryKey].type.toLowerCase()]
239
236
  const name = sails.models[attributes[prop].collection.toLowerCase()].globalId;
240
- console.log(1,scalarType)
241
237
  type += ` ${prop}: [${name}]\n`;
242
-
243
- // todelete
244
- type += ` ${prop}Ids: ${scalarType}\n`;
245
238
  }
246
239
  }
247
240
  if (customFields[modelName]) {
@@ -536,7 +529,6 @@ function addModelResolver(modelname) {
536
529
  };
537
530
  });
538
531
 
539
- console.log(modelName,resolvers)
540
532
  modelsResolvers[modelName] = resolvers;
541
533
 
542
534
 
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.4"
63
+ "version": "1.3.7"
64
64
  }
@@ -16,4 +16,10 @@ export declare const additionalResolver: {
16
16
  Group: {
17
17
  parentGroup: (parent: any, args: any, context: any, info: any) => Promise<any>;
18
18
  };
19
+ Order: {
20
+ dishes: (parent: any, args: any, context: any, info: any) => Promise<any>;
21
+ };
22
+ OrderDish: {
23
+ dish: (parent: any, args: any, context: any, info: any) => Promise<any>;
24
+ };
19
25
  };
@@ -41,7 +41,7 @@ exports.default = {
41
41
  if (args.modifiers) {
42
42
  args.modifiers.forEach((modifier) => {
43
43
  if (modifier.amount === undefined || modifier.id === undefined)
44
- throw new errorWrapper_1.Error(0, "ERROR", `modifier required (amount, id) for dish: ${args.dishId} current values: id: ${modifier.id}, amount: ${modifier.amount}`);
44
+ throw new errorWrapper_1.Error("BAD_DISHMODIFIER", `modifier required (amount, id) for dish: ${args.dishId} current values: id: ${modifier.id}, amount: ${modifier.amount}`);
45
45
  });
46
46
  }
47
47
  if (args.orderId)
@@ -66,7 +66,7 @@ exports.default = {
66
66
  throw new errorWrapper_1.Error(0, "ERROR", `"${dish.name}" является акционным и не может быть добавлено пользователем`);
67
67
  }
68
68
  }
69
- await Order.addDish(order.id, args.dishId, args.amount, args.modifiers || [], args.comment, args.from, args.replace, args.orderDishId);
69
+ await Order.addDish(order.id, args.dishId, args.amount, args.modifiers === undefined ? [] : args.modifiers, args.comment, args.from, args.replace, args.orderDishId);
70
70
  await Order.countCart(order);
71
71
  let fullOrder = await Order.populate(order.id);
72
72
  getEmitter_1.default().emit("http-api:before-response-order-add-dish", fullOrder);
@@ -86,7 +86,7 @@ exports.default = {
86
86
  if (order.paid || order.state === "ORDER") {
87
87
  order = await getNewCart();
88
88
  }
89
- await Order.addDish(order.id, args.dishId, args.amount, args.modifiers || [], args.comment, args.from, args.replace, args.orderDishId);
89
+ await Order.addDish(order.id, args.dishId, args.amount, args.modifiers === undefined ? [] : args.modifiers, args.comment, args.from, args.replace, args.orderDishId);
90
90
  await Order.countCart(order);
91
91
  let fullOrder = await Order.populate(order.id);
92
92
  getEmitter_1.default().emit("http-api:before-response-order-replace-dish", fullOrder);
@@ -45,12 +45,13 @@ export default {
45
45
  fn: async function (parent, args, context) {
46
46
  let order;
47
47
 
48
+
49
+
48
50
  if (args.modifiers) {
49
51
  args.modifiers.forEach((modifier) => {
50
52
  if (modifier.amount === undefined || modifier.id === undefined)
51
53
  throw new Error(
52
- 0,
53
- "ERROR",
54
+ "BAD_DISHMODIFIER",
54
55
  `modifier required (amount, id) for dish: ${args.dishId} current values: id: ${modifier.id}, amount: ${modifier.amount}`
55
56
  );
56
57
  });
@@ -92,7 +93,7 @@ export default {
92
93
  order.id,
93
94
  args.dishId,
94
95
  args.amount,
95
- args.modifiers || [],
96
+ args.modifiers === undefined ? [] : args.modifiers,
96
97
  args.comment,
97
98
  args.from,
98
99
  args.replace,
@@ -127,7 +128,7 @@ export default {
127
128
  order.id,
128
129
  args.dishId,
129
130
  args.amount,
130
- args.modifiers || [],
131
+ args.modifiers === undefined ? [] : args.modifiers,
131
132
  args.comment,
132
133
  args.from,
133
134
  args.replace,
@@ -3,8 +3,8 @@ declare const _default: {
3
3
  checkOrder: {
4
4
  def: string;
5
5
  fn: (parent: any, args: any, context: any) => Promise<void | {
6
+ message: any;
6
7
  order: import("@webresto/core/models/Order").default;
7
- message?: undefined;
8
8
  } | {
9
9
  message: {
10
10
  type: string;
@@ -17,12 +17,22 @@ declare const _default: {
17
17
  sendOrder: {
18
18
  def: string;
19
19
  fn: (parent: any, args: any, context: any) => Promise<{
20
+ order: import("@webresto/core/models/Order").default;
21
+ action: {
22
+ type: string;
23
+ data: {
24
+ redirectLink: string;
25
+ };
26
+ };
27
+ message?: undefined;
28
+ } | {
20
29
  order: import("@webresto/core/models/Order").default;
21
30
  message: {
22
31
  type: string;
23
32
  title: string;
24
33
  message: string;
25
34
  };
35
+ action?: undefined;
26
36
  }>;
27
37
  };
28
38
  };
@@ -21,6 +21,10 @@ exports.default = {
21
21
  if (data.selfService || data.selfDelivery) {
22
22
  isSelfService = true;
23
23
  }
24
+ else {
25
+ if (!data.address)
26
+ throw `Address is required for non self service orders`;
27
+ }
24
28
  try {
25
29
  var order = await Order.findOne(data.orderId);
26
30
  if (!order) {
@@ -64,7 +68,6 @@ exports.default = {
64
68
  await Order.update({ id: order.id }, order).fetch();
65
69
  await Order.check(order.id, data.customer, isSelfService, data.address, data.paymentMethodId);
66
70
  order = await Order.findOne(data.orderId);
67
- console.log(order.dishes);
68
71
  let message;
69
72
  if (order.state === "CHECKOUT") {
70
73
  message = {
@@ -86,7 +89,7 @@ exports.default = {
86
89
  };
87
90
  }
88
91
  }
89
- return eventHelper.sendMessage(args.orderId, message);
92
+ eventHelper.sendMessage(args.orderId, message);
90
93
  return { message: message, order: order };
91
94
  }
92
95
  catch (e) {
@@ -137,14 +140,6 @@ exports.default = {
137
140
  def: "sendOrder(orderId: String!): CheckResponse",
138
141
  fn: async function (parent, args, context) {
139
142
  let data = args;
140
- // if (data.date) {
141
- // let date = moment(data.date)
142
- // if(!date.isValid()){
143
- // return eventHelper.sendMessage(args.orderId,"Please order.date format is ISO (YYYY-MM-DD HH:mm:ss)");
144
- // } else {
145
- // data.date = date.format('YYYY-MM-DD HH:mm:ss');
146
- // }
147
- // }
148
143
  try {
149
144
  var order = await Order.findOne({ id: data.orderId });
150
145
  if (!order) {
@@ -157,52 +152,29 @@ exports.default = {
157
152
  sails.log.error(`${errorMessage}`);
158
153
  throw new errorWrapper_1.Error(0, errorMessage);
159
154
  }
160
- // if (data.comment) order.comment = data.comment;
161
- // if (data.paymentMethodId) {
162
- // if (order.paymentMethod !== data.paymentMethodId) {
163
- // await Order.check(
164
- // order.id,
165
- // null,
166
- // null,
167
- // null,
168
- // data.paymentMethodId
169
- // );
170
- // order = await Order.findOne({ id: data.orderId });
171
- // }
172
- // }
173
- // if (order.paymentMethod) {
174
- // if (!(await PaymentMethod.checkAvailable(order.paymentMethod))) {
175
- // let errorMessage = `Проверка платежной системы завершилась неудачно`;
176
- // eventHelper.sendMessage(args.orderId, {
177
- // type: "error",
178
- // title: "Ошибка",
179
- // message: errorMessage,
180
- // });
181
- // sails.log.error(`${errorMessage}`)
182
- // throw new Error(0,errorMessage);
183
- // }
184
- // if (!(await PaymentMethod.isPaymentPromise(data.paymentMethodId))) {
185
- // try {
186
- // let paymentResponse = await order.payment();
187
- // const action = {
188
- // type: "PaymentRedirect",
189
- // data: {
190
- // redirectLink: paymentResponse.redirectLink,
191
- // },
192
- // };
193
- // eventHelper.sendAction(args.orderId, action);
194
- // return { order: order, action: action };
195
- // } catch (e) {
196
- // eventHelper.sendMessage(args.orderId, {
197
- // type: "error",
198
- // title: "Ошибка",
199
- // message: "Попытка регистрации платежа завершилась неудачно",
200
- // });
201
- // sails.log.error(e);
202
- // throw new Error(0, JSON.stringify(e));
203
- // }
204
- // }
205
- // }
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
+ }
177
+ }
206
178
  await Order.order(order.id);
207
179
  order = await Order.findOne({ id: data.orderId });
208
180
  const message = {
@@ -22,6 +22,8 @@ export default {
22
22
  //@ts-ignore
23
23
  if (data.selfService || data.selfDelivery) {
24
24
  isSelfService = true;
25
+ } else {
26
+ if(!data.address) throw `Address is required for non self service orders`
25
27
  }
26
28
 
27
29
  try {
@@ -80,7 +82,6 @@ export default {
80
82
  );
81
83
 
82
84
  order = await Order.findOne(data.orderId);
83
- console.log(order.dishes)
84
85
 
85
86
  let message;
86
87
 
@@ -105,8 +106,7 @@ export default {
105
106
  }
106
107
  }
107
108
 
108
- return eventHelper.sendMessage(args.orderId, message);
109
-
109
+ eventHelper.sendMessage(args.orderId, message);
110
110
  return { message: message, order: order };
111
111
  } catch (e) {
112
112
  let message = {
@@ -149,15 +149,6 @@ export default {
149
149
  fn: async function (parent, args, context) {
150
150
  let data = args;
151
151
 
152
- // if (data.date) {
153
- // let date = moment(data.date)
154
- // if(!date.isValid()){
155
- // return eventHelper.sendMessage(args.orderId,"Please order.date format is ISO (YYYY-MM-DD HH:mm:ss)");
156
- // } else {
157
- // data.date = date.format('YYYY-MM-DD HH:mm:ss');
158
- // }
159
- // }
160
-
161
152
  try {
162
153
  var order = await Order.findOne({ id: data.orderId });
163
154
  if (!order) {
@@ -171,56 +162,30 @@ export default {
171
162
  throw new Error(0,errorMessage);
172
163
  }
173
164
 
174
- // if (data.comment) order.comment = data.comment;
175
-
176
- // if (data.paymentMethodId) {
177
- // if (order.paymentMethod !== data.paymentMethodId) {
178
- // await Order.check(
179
- // order.id,
180
- // null,
181
- // null,
182
- // null,
183
- // data.paymentMethodId
184
- // );
185
- // order = await Order.findOne({ id: data.orderId });
186
- // }
187
- // }
188
-
189
- // if (order.paymentMethod) {
190
- // if (!(await PaymentMethod.checkAvailable(order.paymentMethod))) {
191
- // let errorMessage = `Проверка платежной системы завершилась неудачно`;
192
- // eventHelper.sendMessage(args.orderId, {
193
- // type: "error",
194
- // title: "Ошибка",
195
- // message: errorMessage,
196
- // });
197
- // sails.log.error(`${errorMessage}`)
198
- // throw new Error(0,errorMessage);
199
- // }
200
-
201
- // if (!(await PaymentMethod.isPaymentPromise(data.paymentMethodId))) {
202
- // try {
203
- // let paymentResponse = await order.payment();
204
- // const action = {
205
- // type: "PaymentRedirect",
206
- // data: {
207
- // redirectLink: paymentResponse.redirectLink,
208
- // },
209
- // };
210
- // eventHelper.sendAction(args.orderId, action);
211
- // return { order: order, action: action };
212
- // } catch (e) {
213
- // eventHelper.sendMessage(args.orderId, {
214
- // type: "error",
215
- // title: "Ошибка",
216
- // message: "Попытка регистрации платежа завершилась неудачно",
217
- // });
218
-
219
- // sails.log.error(e);
220
- // throw new Error(0, JSON.stringify(e));
221
- // }
222
- // }
223
- // }
165
+ if (!(await PaymentMethod.isPaymentPromise(order.paymentMethod))) {
166
+ try {
167
+ let paymentResponse = await Order.payment({id: order.id});
168
+
169
+ const action = {
170
+ type: "PaymentRedirect",
171
+ data: {
172
+ redirectLink: paymentResponse.redirectLink,
173
+ },
174
+ };
175
+ eventHelper.sendAction(args.orderId, action);
176
+ order = await Order.populate(order.id);
177
+ return { order: order, action: action };
178
+ } catch (e) {
179
+ eventHelper.sendMessage(args.orderId, {
180
+ type: "error",
181
+ title: "Ошибка",
182
+ message: "Попытка регистрации платежа завершилась неудачно",
183
+ });
184
+
185
+ sails.log.error(e);
186
+ throw new Error(JSON.stringify(e));
187
+ }
188
+ }
224
189
 
225
190
  await Order.order(order.id);
226
191
  order = await Order.findOne({ id: data.orderId })
@@ -2,7 +2,6 @@ const expect = require("chai").expect;
2
2
  describe('GraphQl', function () {
3
3
  it('Added fields exist in schema', async () => {
4
4
  const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
5
- console.log(graphql);
6
5
  const result = await graphql.getServer().executeOperation({
7
6
  query: '{dish { id } \n group { id }}'
8
7
  });
@@ -4,7 +4,6 @@ describe('GraphQl', function () {
4
4
  it('Added fields exist in schema', async () => {
5
5
 
6
6
  const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
7
- console.log(graphql)
8
7
  const result = await graphql.getServer().executeOperation({
9
8
  query: '{dish { id } \n group { id }}'
10
9
  });
@@ -2,7 +2,6 @@ const expect = require("chai").expect;
2
2
  describe('Send order to restarant', function () {
3
3
  it('Create new', async () => {
4
4
  const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
5
- console.log(graphql);
6
5
  const result = await graphql.getServer().executeOperation({
7
6
  query: `
8
7
  {order(orderId:"test-cart"){
@@ -14,7 +13,6 @@ describe('Send order to restarant', function () {
14
13
  });
15
14
  it('orderAddDish', async () => {
16
15
  const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
17
- console.log(graphql);
18
16
  const result = await graphql.getServer().executeOperation({
19
17
  query: `
20
18
  mutation{orderAddDish(dishId: "df19cbbc-c026-595e-9296-1c8a378da6b3", orderId:"test-cart", amount: 1){
@@ -34,7 +32,6 @@ describe('Send order to restarant', function () {
34
32
  });
35
33
  it('checkOrder', async () => {
36
34
  const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
37
- console.log(graphql);
38
35
  const result = await graphql.getServer().executeOperation({
39
36
  query: `
40
37
  mutation{checkOrder(orderId:"test-cart", paymentMethodId: "", address: {city: "town", street: "test", home: "123"}, customer: {phone: {code: "+1", number: "0000000000"}, name: "Piter Parker"}) {
@@ -59,7 +56,6 @@ describe('Send order to restarant', function () {
59
56
  });
60
57
  it('sendOrder', async () => {
61
58
  const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
62
- console.log(graphql);
63
59
  const result = await graphql.getServer().executeOperation({
64
60
  query: `
65
61
  mutation{sendOrder(orderId:"test-cart") {
@@ -4,7 +4,6 @@ describe('Send order to restarant', function () {
4
4
  it('Create new', async () => {
5
5
 
6
6
  const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
7
- console.log(graphql)
8
7
  const result = await graphql.getServer().executeOperation({
9
8
  query: `
10
9
  {order(orderId:"test-cart"){
@@ -22,7 +21,7 @@ describe('Send order to restarant', function () {
22
21
  it('orderAddDish', async () => {
23
22
 
24
23
  const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
25
- console.log(graphql)
24
+
26
25
  const result = await graphql.getServer().executeOperation({
27
26
  query: `
28
27
  mutation{orderAddDish(dishId: "df19cbbc-c026-595e-9296-1c8a378da6b3", orderId:"test-cart", amount: 1){
@@ -45,7 +44,7 @@ describe('Send order to restarant', function () {
45
44
  it('checkOrder', async () => {
46
45
 
47
46
  const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
48
- console.log(graphql)
47
+
49
48
  const result = await graphql.getServer().executeOperation({
50
49
  query: `
51
50
  mutation{checkOrder(orderId:"test-cart", paymentMethodId: "", address: {city: "town", street: "test", home: "123"}, customer: {phone: {code: "+1", number: "0000000000"}, name: "Piter Parker"}) {
@@ -74,7 +73,7 @@ describe('Send order to restarant', function () {
74
73
  it('sendOrder', async () => {
75
74
 
76
75
  const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
77
- console.log(graphql)
76
+
78
77
  const result = await graphql.getServer().executeOperation({
79
78
  query: `
80
79
  mutation{sendOrder(orderId:"test-cart") {
package/todo.md CHANGED
@@ -1 +1 @@
1
- 1. Add support for multi websoketServer (several tests placed in lib dirrectory)
1
+ 1. Add support for multi websoketServer (several tests placed in lib dirrectory)
package/restApi.http DELETED
@@ -1,11 +0,0 @@
1
- @host = http://127.0.0.1:42777
2
-
3
- @host2 = https://api.lifenadym.webresto.dev
4
-
5
- GET {{host}}/api/0.5/menu
6
-
7
- ###
8
- GET {{host2}}/api/0.5/api/getNomenclature
9
-
10
- ###
11
- GET {{host}}/api/0.5/menu?groupSlug=sousy