@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.
Files changed (142) hide show
  1. package/.gitattributes +2 -0
  2. package/.gitlab-ci.yml +18 -0
  3. package/.vscode/extensions.json +5 -0
  4. package/docs/actions.md +25 -0
  5. package/docs/authorization.md +215 -0
  6. package/docs/captcha.md +71 -0
  7. package/docs/device-id.md +30 -0
  8. package/docs/messages.md +10 -0
  9. package/docs/user.md +54 -0
  10. package/index.d.ts +0 -1
  11. package/index.js +6 -2
  12. package/index.ts +2 -2
  13. package/lib/afterHook.js +8 -0
  14. package/lib/afterHook.ts +9 -0
  15. package/lib/bindTranslations.d.ts +1 -0
  16. package/lib/bindTranslations.js +40 -0
  17. package/lib/bindTranslations.ts +39 -0
  18. package/lib/defaults.d.ts +1 -0
  19. package/lib/defaults.js +49 -10
  20. package/lib/defaults.ts +55 -0
  21. package/lib/eventHelper.d.ts +14 -5
  22. package/lib/eventHelper.js +28 -9
  23. package/lib/eventHelper.ts +41 -8
  24. package/lib/getRecomended.d.ts +1 -0
  25. package/lib/getRecomended.js +29 -0
  26. package/lib/getRecomended.ts +31 -0
  27. package/lib/graphqlHelper.d.ts +3 -4
  28. package/lib/graphqlHelper.js +184 -73
  29. package/lib/graphqlHelper.ts +329 -186
  30. package/lib/jwt.d.ts +10 -0
  31. package/lib/jwt.js +43 -0
  32. package/lib/jwt.ts +61 -0
  33. package/package.json +13 -6
  34. package/src/additionalResolvers.d.ts +72 -9
  35. package/src/additionalResolvers.js +93 -24
  36. package/src/additionalResolvers.ts +105 -34
  37. package/src/graphql.d.ts +5 -3
  38. package/src/graphql.js +170 -37
  39. package/src/graphql.ts +210 -60
  40. package/src/resolvers/bonusProgram.d.ts +32 -0
  41. package/src/resolvers/bonusProgram.js +65 -0
  42. package/src/resolvers/bonusProgram.ts +79 -0
  43. package/src/resolvers/captcha.d.ts +11 -0
  44. package/src/resolvers/captcha.js +19 -0
  45. package/src/resolvers/captcha.ts +16 -0
  46. package/src/resolvers/checkout.d.ts +43 -14
  47. package/src/resolvers/checkout.js +172 -122
  48. package/src/resolvers/checkout.ts +218 -142
  49. package/src/resolvers/dishAndModifier.js +8 -4
  50. package/src/resolvers/dishAndModifier.ts +4 -0
  51. package/src/resolvers/error.d.ts +9 -0
  52. package/src/resolvers/error.js +21 -0
  53. package/src/resolvers/error.ts +21 -0
  54. package/src/resolvers/menu.d.ts +9 -0
  55. package/src/resolvers/menu.js +12 -0
  56. package/src/resolvers/menu.ts +10 -0
  57. package/src/resolvers/order.d.ts +527 -0
  58. package/src/resolvers/order.js +349 -0
  59. package/src/resolvers/order.ts +435 -0
  60. package/src/resolvers/paymentMethod.js +7 -3
  61. package/src/resolvers/paymentMethod.ts +9 -5
  62. package/src/resolvers/pickupPoint.d.ts +1 -0
  63. package/src/resolvers/pickupPoint.js +24 -0
  64. package/src/resolvers/pickupPoint.ts +23 -0
  65. package/src/resolvers/recomended.d.ts +13 -0
  66. package/src/resolvers/recomended.js +80 -0
  67. package/src/resolvers/recomended.ts +86 -0
  68. package/src/resolvers/restrictions.d.ts +37 -1
  69. package/src/resolvers/restrictions.js +100 -15
  70. package/src/resolvers/restrictions.ts +106 -14
  71. package/src/resolvers/streets.d.ts +1 -1
  72. package/src/resolvers/streets.js +1 -4
  73. package/src/resolvers/streets.ts +1 -3
  74. package/src/resolvers/subscriptions.d.ts +4 -4
  75. package/src/resolvers/subscriptions.js +49 -12
  76. package/src/resolvers/subscriptions.ts +59 -14
  77. package/src/resolvers/telemetry.d.ts +14 -0
  78. package/src/resolvers/telemetry.js +25 -0
  79. package/src/resolvers/telemetry.ts +24 -0
  80. package/src/resolvers/user.d.ts +82 -0
  81. package/src/resolvers/user.js +416 -0
  82. package/src/resolvers/user.ts +621 -0
  83. package/src/resolvers/userLocation.d.ts +53 -0
  84. package/src/resolvers/userLocation.js +74 -0
  85. package/src/resolvers/userLocation.ts +125 -0
  86. package/src/resolvers/userOTPrequest.d.ts +21 -0
  87. package/src/resolvers/userOTPrequest.js +57 -0
  88. package/src/resolvers/userOTPrequest.ts +75 -0
  89. package/test/e2e_helper.js +157 -0
  90. package/test/e2e_helper.ts +212 -0
  91. package/test/fixture/config/i18n.js +7 -20
  92. package/test/fixture/config/locales/de.json +1 -0
  93. package/test/fixture/config/locales/en.json +10 -0
  94. package/test/fixture/config/locales/es.json +3 -0
  95. package/test/fixture/config/locales/fr.json +1 -0
  96. package/test/fixture/config/log.js +1 -1
  97. package/test/fixture/package.json +5 -6
  98. package/test/fixture/patches/rttc+10.0.1.patch +17 -0
  99. package/test/integration/captcha.test.js +20 -0
  100. package/test/integration/captcha.test.ts +25 -0
  101. package/test/integration/dish.test.js +35 -0
  102. package/test/integration/dish.test.ts +43 -0
  103. package/test/integration/graphql.test.js +5 -2
  104. package/test/integration/graphql.test.ts +2 -4
  105. package/test/integration/images.test.js +35 -0
  106. package/test/integration/images.test.ts +40 -0
  107. package/test/integration/locale.test.js +26 -0
  108. package/test/integration/locale.test.ts +32 -0
  109. package/test/integration/order.test.js +56 -43
  110. package/test/integration/order.test.ts +59 -59
  111. package/test/integration/subscriptions.test.js +136 -0
  112. package/test/integration/subscriptions.test.ts +162 -0
  113. package/test/integration/user.test.js +249 -0
  114. package/test/integration/user.test.ts +299 -0
  115. package/test/unit/first.test.js +4 -2
  116. package/test/unit/first.test.ts +1 -1
  117. package/test/unit/get-recomended.test.js +56 -0
  118. package/test/unit/get-recomended.test.ts +63 -0
  119. package/translations/de.json +2 -0
  120. package/translations/en.json +3 -0
  121. package/translations/es.json +3 -0
  122. package/translations/fr.json +2 -0
  123. package/translations/ru.json +36 -0
  124. package/tsconfig.json +20 -5
  125. package/types/global.d.ts +30 -0
  126. package/types/global.js +2 -0
  127. package/types/global.ts +31 -0
  128. package/types/primitives.d.ts +19 -0
  129. package/types/references.d.ts +1 -0
  130. package/types/restoGraphQLConfig.d.ts +13 -0
  131. package/lib/afterHook.ts___graphql-transport-ws +0 -138
  132. package/lib/afterHook.ts___graphql-ws +0 -133
  133. package/lib/errorWrapper.d.ts +0 -4
  134. package/lib/errorWrapper.js +0 -13
  135. package/lib/errorWrapper.ts +0 -12
  136. package/notes.md +0 -1976
  137. package/src/resolvers/cart.d.ts +0 -343
  138. package/src/resolvers/cart.js +0 -196
  139. package/src/resolvers/cart.ts +0 -277
  140. package/test/fixture/config/connections.js +0 -9
  141. package/test/integration/sails_not_crash.test.js +0 -3
  142. package/test/integration/sails_not_crash.test.ts +0 -3
package/lib/jwt.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ type AuthData = {
2
+ userId: string;
3
+ deviceId: string;
4
+ sessionId: string;
5
+ };
6
+ export declare class JWTAuth {
7
+ static sign(authData: AuthData): string;
8
+ static verify(token: string): Promise<AuthData>;
9
+ }
10
+ export {};
package/lib/jwt.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JWTAuth = void 0;
4
+ const jwt = require("jsonwebtoken");
5
+ class JWTAuth {
6
+ static sign(authData) {
7
+ return jwt.sign({
8
+ data: authData
9
+ }, process.env.JWT_SECRET, { expiresIn: parseInt(process.env.JWT_TOKEN_EXPIRES_IN) ?? 15 * 24 * 60 * 60 });
10
+ }
11
+ static async verify(token) {
12
+ if (!token) {
13
+ throw `Verify JWT token is: ${token}`;
14
+ }
15
+ let decoded;
16
+ try {
17
+ let jwtData = (jwt.verify(token, process.env.JWT_SECRET));
18
+ decoded = jwtData.data;
19
+ }
20
+ catch (err) {
21
+ sails.log.error(`JWT verify error: `, err);
22
+ throw err;
23
+ }
24
+ if (decoded.userId && decoded.deviceId && decoded.sessionId) {
25
+ if (await User.findOne({ id: decoded.userId })) {
26
+ let device = await UserDevice.findOne({ where: { id: decoded.deviceId, user: decoded.userId, sessionId: decoded.sessionId } });
27
+ if (!device || device.isLogined !== true) {
28
+ throw `Logined device not found`;
29
+ }
30
+ else {
31
+ return decoded;
32
+ }
33
+ }
34
+ else {
35
+ throw `no user with id ${decoded.userId}`;
36
+ }
37
+ }
38
+ else {
39
+ throw `JWT decoded user or device not found`;
40
+ }
41
+ }
42
+ }
43
+ exports.JWTAuth = JWTAuth;
package/lib/jwt.ts ADDED
@@ -0,0 +1,61 @@
1
+ import User from "@webresto/core/models/User"
2
+ import UserDevice from "@webresto/core/models/UserDevice"
3
+
4
+ import * as jwt from 'jsonwebtoken'
5
+
6
+
7
+
8
+ // GEN SECRET
9
+ type AuthData = {
10
+ userId: string
11
+ deviceId: string
12
+ sessionId: string
13
+ }
14
+
15
+ type JWTData = {
16
+ data: AuthData
17
+ iat: number
18
+ exp: number
19
+ }
20
+
21
+
22
+ export class JWTAuth {
23
+ public static sign(authData: AuthData): string {
24
+ return jwt.sign({
25
+ data: authData
26
+ }, process.env.JWT_SECRET, { expiresIn: parseInt(process.env.JWT_TOKEN_EXPIRES_IN) ?? 15 * 24 * 60 * 60 });
27
+
28
+ }
29
+
30
+ public static async verify(token: string): Promise<AuthData>{
31
+
32
+ if (!token) {
33
+ throw `Verify JWT token is: ${token}`
34
+ }
35
+
36
+ let decoded: AuthData;
37
+ try {
38
+ let jwtData = (jwt.verify(token, process.env.JWT_SECRET)) as JWTData
39
+ decoded = jwtData.data
40
+ } catch(err) {
41
+ sails.log.error(`JWT verify error: `, err)
42
+ throw err
43
+ }
44
+
45
+ if(decoded.userId && decoded.deviceId && decoded.sessionId) {
46
+ if (await User.findOne({id: decoded.userId})) {
47
+
48
+ let device = await UserDevice.findOne({where: {id: decoded.deviceId, user: decoded.userId, sessionId: decoded.sessionId}});
49
+ if(!device || device.isLogined !== true) {
50
+ throw `Logined device not found`
51
+ } else {
52
+ return decoded;
53
+ }
54
+ } else {
55
+ throw `no user with id ${decoded.userId}`
56
+ }
57
+ } else {
58
+ throw `JWT decoded user or device not found`
59
+ }
60
+ }
61
+ }
package/package.json CHANGED
@@ -2,29 +2,36 @@
2
2
  "author": {
3
3
  "name": "Webresto"
4
4
  },
5
- "bundleDependencies": false,
5
+ "bundleDependencies": [],
6
6
  "dependencies": {
7
+ "accept-language-parser": "^1.5.0",
7
8
  "apollo-fetch": "^0.7.0",
8
- "apollo-server": "^2.25.2",
9
+ "apollo-server": "^2.26.1",
9
10
  "dataloader": "^2.0.0",
11
+ "fix-esm": "^1.0.1",
10
12
  "graphql": "^15.5.0",
13
+ "jsonwebtoken": "^9.0.0",
11
14
  "waterline-criteria": "^2.0.0"
12
15
  },
13
16
  "devDependencies": {
14
17
  "@42pub/typed-sails": "^1.0.0",
18
+ "@apollo/client": "^3.7.3",
19
+ "@types/accept-language-parser": "^1.5.3",
15
20
  "@types/bluebird": "^3.5.32",
16
21
  "@types/bluebird-global": "^3.5.12",
17
22
  "@types/body-parser": "^1.19.0",
18
23
  "@types/chai": "^4.2.11",
19
24
  "@types/express": "^4.17.7",
20
25
  "@types/faker": "^4.1.12",
26
+ "@types/jsonwebtoken": "^9.0.0",
21
27
  "@types/lodash": "^4.14.157",
22
28
  "@types/mocha": "^8.0.2",
23
29
  "@types/node": "^14.14.35",
24
- "@types/uuid": "^8.0.0",
25
30
  "@types/waterline": "^0.13.4",
26
- "@webresto/core": "^1.0.0",
31
+ "@webresto/core": "^1.3.27-alpha",
27
32
  "chai": "^4.2.0",
33
+ "cross-fetch": "^3.1.5",
34
+ "crypto-puzzle": "^4.0.0",
28
35
  "dotenv": "^16.0.0",
29
36
  "faker": "^4.1.0",
30
37
  "mocha": "^8.1.1",
@@ -56,9 +63,9 @@
56
63
  },
57
64
  "scripts": {
58
65
  "gendoc": "apidoc -o apidoc/ && apidoc-markdown2 -p apidoc -o docs/api.md",
59
- "test": "mocha -r ts-node/register test/bootstrap.ts './test/{,!(fixture)/**}/*.test.ts' --exit",
66
+ "test": "mocha -r ts-node/register test/bootstrap.ts './test/{,!(fixture)/**}/*.test.ts' --exit --grep=${PATTERN}",
60
67
  "test:js": "mocha test/bootstrap.js './test/{,!(fixture)/**}/*.test.js' --exit",
61
68
  "test:init": "cd ./test/fixture && npm i --no-package-lock --prefix ./ && cd -"
62
69
  },
63
- "version": "1.3.6"
70
+ "version": "1.3.8"
64
71
  }
@@ -1,25 +1,88 @@
1
1
  export declare const additionalResolver: {
2
2
  GroupModifier: {
3
- group: (parent: any, args: any, context: any, info: any) => Promise<any>;
3
+ modifierId: (parent: {
4
+ modifierId?: string;
5
+ id?: string; /** here id means rmsID */
6
+ }, args: any, context: {
7
+ dataloaders: WeakMap<object, any>;
8
+ }, info: {
9
+ fieldNodes: any;
10
+ }) => Promise<any>;
11
+ group: (parent: {
12
+ modifierId?: string;
13
+ id?: string; /** here id means rmsID */
14
+ }, args: any, context: {
15
+ dataloaders: WeakMap<object, any>;
16
+ }, info: {
17
+ fieldNodes: any;
18
+ }) => Promise<any>;
4
19
  };
5
20
  Modifier: {
6
- dish: (parent: any, args: any, context: any, info: any) => Promise<any>;
21
+ modifierId: (parent: {
22
+ modifierId?: string;
23
+ id?: string; /** here id means rmsID */
24
+ }, args: any, context: {
25
+ dataloaders: WeakMap<object, any>;
26
+ }, info: {
27
+ fieldNodes: any;
28
+ }) => Promise<any>;
29
+ dish: (parent: {
30
+ modifierId?: string;
31
+ id?: string; /** here id means rmsID */
32
+ }, args: any, context: {
33
+ dataloaders: WeakMap<object, any>;
34
+ }, info: {
35
+ fieldNodes: any;
36
+ }) => Promise<any>;
7
37
  };
8
38
  OrderModifier: {
9
- dish: (parent: any, args: any, context: any, info: any) => Promise<any>;
10
- group: (parent: any, args: any) => Promise<any>;
39
+ dish: (parent: {
40
+ id: string;
41
+ modifierId: string;
42
+ }, args: any, context: any, info: any) => Promise<any>;
43
+ group: (parent: {
44
+ id: string;
45
+ groupId: string;
46
+ }, args: any) => Promise<any>;
11
47
  };
12
48
  Dish: {
13
- parentGroup: (parent: any, args: any, context: any, info: any) => Promise<any>;
14
- images: (parent: any, args: any, context: any, info: any) => Promise<any>;
49
+ parentGroup: (parent: {
50
+ parentGroup: any;
51
+ }, args: any, context: {
52
+ dataloaders: WeakMap<object, any>;
53
+ }, info: {
54
+ fieldNodes: any;
55
+ }) => Promise<any>;
56
+ images: (parent: {
57
+ id: any;
58
+ }, args: any, context: {
59
+ dataloaders: WeakMap<object, any>;
60
+ }, info: {
61
+ fieldNodes: any;
62
+ }) => Promise<any>;
15
63
  };
16
64
  Group: {
17
- parentGroup: (parent: any, args: any, context: any, info: any) => Promise<any>;
65
+ parentGroup: (parent: {
66
+ parentGroup: any;
67
+ }, args: any, context: {
68
+ dataloaders: WeakMap<object, any>;
69
+ }, info: {
70
+ fieldNodes: any;
71
+ }) => Promise<any>;
18
72
  };
19
73
  Order: {
20
- dishes: (parent: any, args: any, context: any, info: any) => Promise<any>;
74
+ dishes: (parent: {
75
+ dishes: any;
76
+ id: any;
77
+ }, args: any, context: any, info: any) => Promise<any>;
21
78
  };
22
79
  OrderDish: {
23
- dish: (parent: any, args: any, context: any, info: any) => Promise<any>;
80
+ dish: (parent: {
81
+ dish: any;
82
+ }, args: any, context: {
83
+ dataloaders: WeakMap<object, any>;
84
+ }, info: {
85
+ fieldNodes: any;
86
+ }) => Promise<any>;
24
87
  };
25
88
  };
@@ -4,8 +4,29 @@ exports.additionalResolver = void 0;
4
4
  const DataLoader = require('dataloader');
5
5
  exports.additionalResolver = {
6
6
  GroupModifier: {
7
+ modifierId: async (parent, args, context, info) => {
8
+ if (parent.modifierId)
9
+ return parent.modifierId;
10
+ if (!context.dataloaders)
11
+ context.dataloaders = new WeakMap();
12
+ const dataloaders = context.dataloaders;
13
+ let dl = dataloaders.get(info.fieldNodes);
14
+ if (!dl) {
15
+ dl = new DataLoader(async (id) => {
16
+ const rows = await Group.find({
17
+ rmsId: id, isDeleted: false
18
+ });
19
+ const sortedInIdsOrder = id.map((id) => rows.find(x => {
20
+ return x.rmsId === id;
21
+ }));
22
+ return sortedInIdsOrder;
23
+ });
24
+ dataloaders.set(info.fieldNodes, dl);
25
+ }
26
+ return (await dl.load(parent.id)).id;
27
+ },
7
28
  group: async (parent, args, context, info) => {
8
- if (!parent.modifierId)
29
+ if (!parent.modifierId && !parent.id)
9
30
  return;
10
31
  if (!context.dataloaders)
11
32
  context.dataloaders = new WeakMap();
@@ -13,43 +34,85 @@ exports.additionalResolver = {
13
34
  let dl = dataloaders.get(info.fieldNodes);
14
35
  if (!dl) {
15
36
  dl = new DataLoader(async (ids) => {
16
- const rows = await Group.find({ id: ids });
17
- const sortedInIdsOrder = ids.map(id => rows.find(x => x.id === id));
37
+ const rows = await Group.find({
38
+ where: {
39
+ or: [{ id: ids, isDeleted: false }, { rmsId: ids, isDeleted: false }]
40
+ }
41
+ });
42
+ const sortedInIdsOrder = ids.map((id) => rows.find(x => x.id === id));
18
43
  return sortedInIdsOrder;
19
44
  });
20
45
  dataloaders.set(info.fieldNodes, dl);
21
46
  }
22
- return dl.load(parent.modifierId);
23
- },
47
+ return await dl.load(parent.modifierId ? parent.modifierId : parent.id);
48
+ }
24
49
  },
25
50
  Modifier: {
51
+ modifierId: async (parent, args, context, info) => {
52
+ if (parent.modifierId)
53
+ return parent.modifierId;
54
+ if (!context.dataloaders)
55
+ context.dataloaders = new WeakMap();
56
+ const dataloaders = context.dataloaders;
57
+ let dl = dataloaders.get(info.fieldNodes);
58
+ if (!dl) {
59
+ dl = new DataLoader(async (id) => {
60
+ const rows = await Dish.find({
61
+ rmsId: id, balance: { "!=": 0 }, isDeleted: false
62
+ });
63
+ const sortedInIdsOrder = id.map((id) => rows.find(x => {
64
+ return x.rmsId === id;
65
+ }));
66
+ return sortedInIdsOrder;
67
+ });
68
+ dataloaders.set(info.fieldNodes, dl);
69
+ }
70
+ return (await dl.load(parent.id)).id;
71
+ },
26
72
  dish: async (parent, args, context, info) => {
27
- if (!parent.modifierId)
73
+ if (!parent.modifierId && !parent.id)
28
74
  return;
29
75
  if (!context.dataloaders)
30
76
  context.dataloaders = new WeakMap();
31
77
  const dataloaders = context.dataloaders;
32
78
  let dl = dataloaders.get(info.fieldNodes);
33
79
  if (!dl) {
34
- dl = new DataLoader(async (ids) => {
35
- const rows = await Dish.find({ id: ids, balance: { "!=": 0 }, isDeleted: false });
36
- const sortedInIdsOrder = ids.map(id => rows.find(x => x.id === id));
80
+ dl = new DataLoader(async (id) => {
81
+ const rows = await Dish.find({ where: { or: [
82
+ { id: id, balance: { "!=": 0 }, isDeleted: false },
83
+ { rmsId: id, balance: { "!=": 0 }, isDeleted: false }
84
+ ] }
85
+ });
86
+ const sortedInIdsOrder = id.map((id) => rows.find(x => {
87
+ return x.id === id ? x.id === id : x.rmsId === id ? x.rmsId === id : false;
88
+ }));
37
89
  return sortedInIdsOrder;
38
90
  });
39
- // ложим инстанс дата-лоадера в WeakMap для повторного использования
40
91
  dataloaders.set(info.fieldNodes, dl);
41
92
  }
42
- // юзаем метод `load` из нашего дата-лоадера
43
- return dl.load(parent.modifierId);
44
- // return await Dish.findOne({id: parent.modifierId}).populateAll();
93
+ return await dl.load(parent.modifierId ? parent.modifierId : parent.id);
45
94
  }
46
95
  },
47
96
  OrderModifier: {
48
97
  dish: async (parent, args, context, info) => {
49
- return (await Dish.find({ id: parent.id, balance: { "!=": 0 }, isDeleted: false }).populateAll())[0];
98
+ if (!parent.id && !parent.modifierId)
99
+ return null;
100
+ return (await Dish.find({ where: { or: [
101
+ { id: parent.id, balance: { "!=": 0 }, isDeleted: false },
102
+ { rmsId: parent.id, balance: { "!=": 0 }, isDeleted: false }
103
+ ] }
104
+ // @ts-ignore //TODO: Deprecated populateAll
105
+ }).populateAll())[0];
50
106
  },
51
107
  group: async (parent, args) => {
52
- return (await Group.find({ id: parent.groupId, isDeleted: false }).populateAll())[0];
108
+ if (!parent.id && !parent.groupId)
109
+ return null;
110
+ return (await Group.find({ where: {
111
+ or: [{ id: parent.groupId, isDeleted: false }, { rmsId: parent.id, isDeleted: false }]
112
+ }
113
+ }
114
+ // @ts-ignore //TODO: Deprecated populateAll
115
+ ).populateAll())[0];
53
116
  }
54
117
  },
55
118
  Dish: {
@@ -65,14 +128,20 @@ exports.additionalResolver = {
65
128
  }
66
129
  let dl = dataloaders.get(info.fieldNodes);
67
130
  if (!dl) {
68
- dl = new DataLoader(async (id) => {
69
- return await Group.find(id);
131
+ dl = new DataLoader(async (ids) => {
132
+ // Waterline can return data not by ids array sorting
133
+ return (await Group.find(ids)).sort((a, b) => ids.indexOf(a.id) - ids.indexOf(b.id));
70
134
  });
71
135
  dataloaders.set(info.fieldNodes, dl);
72
136
  }
73
137
  return await dl.load(parent.parentGroup);
74
138
  },
75
139
  images: async (parent, args, context, info) => {
140
+ const sortImages = (images) => {
141
+ return images.sort((a, b) => {
142
+ return (+new Date(b.uploadDate) - +new Date(a.uploadDate));
143
+ });
144
+ };
76
145
  if (!parent.id)
77
146
  return;
78
147
  if (!context.dataloaders)
@@ -82,12 +151,12 @@ exports.additionalResolver = {
82
151
  if (!dl) {
83
152
  dl = new DataLoader(async (ids) => {
84
153
  const rows = await Dish.find({ id: ids }).populate('images');
85
- const images = ids.map(id => { var _a; return (_a = rows.find(x => x.id === id)) === null || _a === void 0 ? void 0 : _a.images; });
154
+ const images = ids.map((id) => rows.find(x => x.id === id)?.images);
86
155
  return images;
87
156
  });
88
157
  dataloaders.set(info.fieldNodes, dl);
89
158
  }
90
- return await dl.load(parent.id);
159
+ return sortImages(await dl.load(parent.id));
91
160
  }
92
161
  },
93
162
  Group: {
@@ -103,8 +172,8 @@ exports.additionalResolver = {
103
172
  }
104
173
  let dl = dataloaders.get(info.fieldNodes);
105
174
  if (!dl) {
106
- dl = new DataLoader(async (id) => {
107
- return await Group.find(id);
175
+ dl = new DataLoader(async (ids) => {
176
+ return (await Group.find(ids)).sort((a, b) => ids.indexOf(a.id) - ids.indexOf(b.id));
108
177
  });
109
178
  dataloaders.set(info.fieldNodes, dl);
110
179
  }
@@ -131,12 +200,12 @@ exports.additionalResolver = {
131
200
  }
132
201
  let dl = dataloaders.get(info.fieldNodes);
133
202
  if (!dl) {
134
- dl = new DataLoader(async (dishId) => {
135
- return await Dish.find({ id: dishId }).sort('id ASC');
203
+ dl = new DataLoader(async (ids) => {
204
+ return (await Dish.find(ids)).sort((a, b) => ids.indexOf(a.id) - ids.indexOf(b.id));
136
205
  });
137
206
  dataloaders.set(info.fieldNodes, dl);
138
207
  }
139
208
  return await dl.load(parent.dish);
140
209
  },
141
- },
210
+ }
142
211
  };