@ozdao/prometheus-framework 0.2.138 → 0.2.139

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. package/dist/auth.server.js +29 -14
  2. package/dist/auth.server.mjs +29 -14
  3. package/dist/community.server.js +3 -3
  4. package/dist/community.server.mjs +3 -3
  5. package/dist/events.server.js +3 -3
  6. package/dist/events.server.mjs +3 -3
  7. package/dist/files.server.js +3 -3
  8. package/dist/files.server.mjs +3 -3
  9. package/dist/gallery.server.js +4 -4
  10. package/dist/gallery.server.mjs +4 -4
  11. package/dist/index-DNI4aUP2.js +259 -0
  12. package/dist/index-Tcyehi73.mjs +260 -0
  13. package/dist/orders.server.js +9 -8
  14. package/dist/orders.server.mjs +9 -8
  15. package/dist/organizations.server.js +31 -15
  16. package/dist/organizations.server.mjs +31 -15
  17. package/dist/products.server.js +37 -5
  18. package/dist/products.server.mjs +37 -5
  19. package/dist/prometheus-framework/src/components/Completion/Completion.vue.cjs +1 -1
  20. package/dist/prometheus-framework/src/components/Completion/Completion.vue.js +19 -19
  21. package/dist/prometheus-framework/src/components/FieldBig/FieldBig.vue.cjs +1 -1
  22. package/dist/prometheus-framework/src/components/FieldBig/FieldBig.vue.js +1 -1
  23. package/dist/prometheus-framework/src/modules/auth/components/layouts/Auth.vue.cjs +1 -1
  24. package/dist/prometheus-framework/src/modules/auth/components/layouts/Auth.vue.js +2 -2
  25. package/dist/prometheus-framework/src/modules/auth/components/pages/EnterCode.vue.cjs +1 -1
  26. package/dist/prometheus-framework/src/modules/auth/components/pages/EnterCode.vue.js +1 -1
  27. package/dist/prometheus-framework/src/modules/auth/components/pages/EnterPassword.vue.cjs +1 -1
  28. package/dist/prometheus-framework/src/modules/auth/components/pages/EnterPassword.vue.js +2 -2
  29. package/dist/prometheus-framework/src/modules/auth/components/pages/Invite.vue.cjs +1 -1
  30. package/dist/prometheus-framework/src/modules/auth/components/pages/Invite.vue.js +32 -31
  31. package/dist/prometheus-framework/src/modules/auth/components/pages/ResetPassword.vue.cjs +1 -1
  32. package/dist/prometheus-framework/src/modules/auth/components/pages/ResetPassword.vue.js +2 -2
  33. package/dist/prometheus-framework/src/modules/auth/components/pages/SignIn.vue.cjs +1 -1
  34. package/dist/prometheus-framework/src/modules/auth/components/pages/SignIn.vue.js +2 -2
  35. package/dist/prometheus-framework/src/modules/auth/components/pages/SignUp.vue.cjs +1 -1
  36. package/dist/prometheus-framework/src/modules/auth/components/pages/SignUp.vue.js +2 -2
  37. package/dist/prometheus-framework/src/modules/auth/store/auth.cjs +1 -1
  38. package/dist/prometheus-framework/src/modules/auth/store/auth.js +50 -47
  39. package/dist/prometheus-framework/src/modules/community/components/pages/Community.vue.cjs +1 -1
  40. package/dist/prometheus-framework/src/modules/community/components/pages/Community.vue.js +2 -2
  41. package/dist/prometheus-framework/src/modules/community/components/pages/CreateBlogPost.vue.cjs +1 -1
  42. package/dist/prometheus-framework/src/modules/community/components/pages/CreateBlogPost.vue.js +2 -2
  43. package/dist/prometheus-framework/src/modules/community/components/sections/HotPosts.vue.cjs +1 -1
  44. package/dist/prometheus-framework/src/modules/community/components/sections/HotPosts.vue.js +1 -1
  45. package/dist/prometheus-framework/src/modules/constructor/components/elements/Embed.vue.cjs +1 -1
  46. package/dist/prometheus-framework/src/modules/constructor/components/elements/Embed.vue.js +1 -1
  47. package/dist/prometheus-framework/src/modules/events/components/elements/ButtonCheck.vue.cjs +1 -1
  48. package/dist/prometheus-framework/src/modules/events/components/elements/ButtonCheck.vue.js +1 -1
  49. package/dist/prometheus-framework/src/modules/events/components/elements/ButtonJoin.vue.cjs +1 -1
  50. package/dist/prometheus-framework/src/modules/events/components/elements/ButtonJoin.vue.js +1 -1
  51. package/dist/prometheus-framework/src/modules/events/components/pages/EditEvent.vue.cjs +1 -1
  52. package/dist/prometheus-framework/src/modules/events/components/pages/EditEvent.vue.js +2 -2
  53. package/dist/prometheus-framework/src/modules/events/components/pages/EditEventTickets.vue.cjs +1 -1
  54. package/dist/prometheus-framework/src/modules/events/components/pages/EditEventTickets.vue.js +2 -2
  55. package/dist/prometheus-framework/src/modules/gallery/components/sections/BackofficeGallery.vue.cjs +1 -1
  56. package/dist/prometheus-framework/src/modules/gallery/components/sections/BackofficeGallery.vue.js +2 -2
  57. package/dist/prometheus-framework/src/modules/globals/components/blocks/BlockSearch.vue.cjs +1 -1
  58. package/dist/prometheus-framework/src/modules/globals/components/blocks/BlockSearch.vue.js +1 -1
  59. package/dist/prometheus-framework/src/modules/globals/components/blocks/CardHeader.vue.cjs +1 -1
  60. package/dist/prometheus-framework/src/modules/globals/components/blocks/CardHeader.vue.js +1 -1
  61. package/dist/prometheus-framework/src/modules/legal/components/pages/Legal.vue.cjs +1 -1
  62. package/dist/prometheus-framework/src/modules/legal/components/pages/Legal.vue.js +2 -2
  63. package/dist/prometheus-framework/src/modules/marketplace/store/marketplace.cjs +1 -1
  64. package/dist/prometheus-framework/src/modules/marketplace/store/marketplace.js +1 -1
  65. package/dist/prometheus-framework/src/modules/orders/components/pages/OrderCreateBackoffice.vue.cjs +1 -1
  66. package/dist/prometheus-framework/src/modules/orders/components/pages/OrderCreateBackoffice.vue.js +14 -14
  67. package/dist/prometheus-framework/src/modules/orders/components/sections/FormAddCustomer.vue.cjs +1 -1
  68. package/dist/prometheus-framework/src/modules/orders/components/sections/FormAddCustomer.vue.js +4 -4
  69. package/dist/prometheus-framework/src/modules/orders/components/sections/FormCustomerDetails.vue.cjs +1 -1
  70. package/dist/prometheus-framework/src/modules/orders/components/sections/FormCustomerDetails.vue.js +1 -1
  71. package/dist/prometheus-framework/src/modules/orders/components/sections/FormDelivery.vue.cjs +1 -1
  72. package/dist/prometheus-framework/src/modules/orders/components/sections/FormDelivery.vue.js +1 -1
  73. package/dist/prometheus-framework/src/modules/organizations/components/blocks/CardOrganization.vue.cjs +1 -1
  74. package/dist/prometheus-framework/src/modules/organizations/components/blocks/CardOrganization.vue.js +41 -38
  75. package/dist/prometheus-framework/src/modules/organizations/components/elements/ButtonToggleMembership.vue.cjs +1 -1
  76. package/dist/prometheus-framework/src/modules/organizations/components/elements/ButtonToggleMembership.vue.js +1 -1
  77. package/dist/prometheus-framework/src/modules/organizations/components/pages/DepartmentEdit.vue.cjs +1 -1
  78. package/dist/prometheus-framework/src/modules/organizations/components/pages/DepartmentEdit.vue.js +2 -2
  79. package/dist/prometheus-framework/src/modules/organizations/components/pages/Members.vue.cjs +1 -1
  80. package/dist/prometheus-framework/src/modules/organizations/components/pages/Members.vue.js +121 -112
  81. package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationEdit.vue.cjs +1 -1
  82. package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationEdit.vue.js +2 -2
  83. package/dist/prometheus-framework/src/modules/organizations/components/sections/DetailsTab.vue.cjs +1 -1
  84. package/dist/prometheus-framework/src/modules/organizations/components/sections/DetailsTab.vue.js +15 -14
  85. package/dist/prometheus-framework/src/modules/organizations/components/sections/Documents.vue.cjs +1 -1
  86. package/dist/prometheus-framework/src/modules/organizations/components/sections/Documents.vue.js +2 -2
  87. package/dist/prometheus-framework/src/modules/organizations/components/sections/MembersAdd.vue.cjs +1 -1
  88. package/dist/prometheus-framework/src/modules/organizations/components/sections/MembersAdd.vue.js +120 -60
  89. package/dist/prometheus-framework/src/modules/organizations/components/sections/Organizations.vue.cjs +1 -1
  90. package/dist/prometheus-framework/src/modules/organizations/components/sections/Organizations.vue.js +2 -2
  91. package/dist/prometheus-framework/src/modules/organizations/store/invites.cjs +1 -1
  92. package/dist/prometheus-framework/src/modules/organizations/store/invites.js +25 -24
  93. package/dist/prometheus-framework/src/modules/products/components/blocks/CardPosition.vue.cjs +1 -1
  94. package/dist/prometheus-framework/src/modules/products/components/blocks/CardPosition.vue.js +1 -1
  95. package/dist/prometheus-framework/src/modules/products/components/blocks/LeftoverPositions.vue.cjs +1 -1
  96. package/dist/prometheus-framework/src/modules/products/components/blocks/LeftoverPositions.vue.js +1 -1
  97. package/dist/prometheus-framework/src/modules/products/components/blocks/ListPositions.vue.cjs +1 -1
  98. package/dist/prometheus-framework/src/modules/products/components/blocks/ListPositions.vue.js +1 -1
  99. package/dist/prometheus-framework/src/modules/products/components/pages/Categories.vue.cjs +1 -1
  100. package/dist/prometheus-framework/src/modules/products/components/pages/Categories.vue.js +1 -1
  101. package/dist/prometheus-framework/src/modules/products/components/pages/CategoryEdit.vue.cjs +1 -1
  102. package/dist/prometheus-framework/src/modules/products/components/pages/CategoryEdit.vue.js +2 -2
  103. package/dist/prometheus-framework/src/modules/products/components/pages/EditLeftover.vue.cjs +1 -1
  104. package/dist/prometheus-framework/src/modules/products/components/pages/EditLeftover.vue.js +1 -1
  105. package/dist/prometheus-framework/src/modules/products/components/pages/ProductEdit.vue.cjs +1 -1
  106. package/dist/prometheus-framework/src/modules/products/components/pages/ProductEdit.vue.js +2 -2
  107. package/dist/prometheus-framework/src/modules/products/components/sections/EditModifications.vue.cjs +1 -1
  108. package/dist/prometheus-framework/src/modules/products/components/sections/EditModifications.vue.js +1 -1
  109. package/dist/prometheus-framework/src/modules/products/components/sections/EditProductInfo.vue.cjs +1 -1
  110. package/dist/prometheus-framework/src/modules/products/components/sections/EditProductInfo.vue.js +2 -2
  111. package/dist/prometheus-framework/src/modules/products/components/sections/SectionProduct.vue.cjs +1 -1
  112. package/dist/prometheus-framework/src/modules/products/components/sections/SectionProduct.vue.js +1 -1
  113. package/dist/prometheus-framework/src/modules/reports/components/sections/FormReport.vue.cjs +1 -1
  114. package/dist/prometheus-framework/src/modules/reports/components/sections/FormReport.vue.js +1 -1
  115. package/dist/prometheus-framework/src/modules/spots/components/blocks/SpotMemberModify.vue.cjs +1 -1
  116. package/dist/prometheus-framework/src/modules/spots/components/blocks/SpotMemberModify.vue.js +1 -1
  117. package/dist/prometheus-framework/src/modules/spots/components/layouts/Spots.vue.cjs +1 -1
  118. package/dist/prometheus-framework/src/modules/spots/components/layouts/Spots.vue.js +3 -3
  119. package/dist/prometheus-framework/src/modules/spots/components/pages/Map.vue.cjs +1 -1
  120. package/dist/prometheus-framework/src/modules/spots/components/pages/Map.vue.js +66 -67
  121. package/dist/prometheus-framework/src/modules/spots/components/pages/SpotEdit.vue.cjs +1 -1
  122. package/dist/prometheus-framework/src/modules/spots/components/pages/SpotEdit.vue.js +2 -2
  123. package/dist/prometheus-framework/src/modules/users/components/pages/Profile.vue.cjs +1 -1
  124. package/dist/prometheus-framework/src/modules/users/components/pages/Profile.vue.js +2 -2
  125. package/dist/prometheus-framework/src/modules/users/components/pages/ProfileEdit.vue.cjs +1 -1
  126. package/dist/prometheus-framework/src/modules/users/components/pages/ProfileEdit.vue.js +78 -74
  127. package/dist/prometheus-framework/src/modules/wallet/views/components/blocks/CardDeposit.vue.cjs +1 -1
  128. package/dist/prometheus-framework/src/modules/wallet/views/components/blocks/CardDeposit.vue.js +1 -1
  129. package/dist/prometheus-framework/src/modules/wallet/views/components/blocks/CryptoDeposit.vue.cjs +1 -1
  130. package/dist/prometheus-framework/src/modules/wallet/views/components/blocks/CryptoDeposit.vue.js +1 -1
  131. package/dist/prometheus-framework/src/modules/wallet/views/components/pages/Wallet.vue.cjs +1 -1
  132. package/dist/prometheus-framework/src/modules/wallet/views/components/pages/Wallet.vue.js +1 -1
  133. package/dist/reports.server.js +0 -3
  134. package/dist/reports.server.mjs +0 -3
  135. package/dist/style.css +1 -1
  136. package/dist/wallet.server.js +5 -5
  137. package/dist/wallet.server.mjs +8 -8
  138. package/package.json +1 -1
  139. package/src/components/Completion/Completion.vue +29 -30
  140. package/src/modules/auth/components/pages/Invite.vue +4 -2
  141. package/src/modules/auth/controllers/auth.controller.js +30 -12
  142. package/src/modules/auth/middlewares/authJwt.js +80 -0
  143. package/src/modules/{middlewares/server → auth/middlewares}/index.js +1 -3
  144. package/src/modules/{middlewares/server → auth/middlewares}/verifyAccesses.js +1 -1
  145. package/src/modules/auth/routes/auth.routes.js +2 -2
  146. package/src/modules/auth/routes/twofa.routes.js +1 -1
  147. package/src/modules/auth/store/auth.js +9 -0
  148. package/src/modules/chats/routes/chats.routes.js +1 -1
  149. package/src/modules/community/routes/blog.routes.js +2 -2
  150. package/src/modules/events/routes/events.routes.js +2 -2
  151. package/src/modules/files/routes/files.routes.js +2 -2
  152. package/src/modules/gallery/routes/gallery.routes.js +4 -5
  153. package/src/modules/globals/services/globals.crud.js +2 -2
  154. package/src/modules/marketplace/store/marketplace.js +1 -1
  155. package/src/modules/orders/components/pages/OrderCreateBackoffice.vue +2 -2
  156. package/src/modules/orders/components/sections/FormAddCustomer.vue +2 -2
  157. package/src/modules/orders/controllers/orders.controller.js +1 -0
  158. package/src/modules/orders/routes/applications.routes.js +2 -2
  159. package/src/modules/orders/routes/orders.routes.js +2 -2
  160. package/src/modules/organizations/components/blocks/CardOrganization.vue +9 -7
  161. package/src/modules/organizations/components/pages/Members.vue +26 -15
  162. package/src/modules/organizations/components/sections/DetailsTab.vue +1 -1
  163. package/src/modules/organizations/components/sections/MembersAdd.vue +101 -43
  164. package/src/modules/organizations/controllers/invites.controller.js +18 -13
  165. package/src/modules/organizations/controllers/memberships.controller.js +16 -9
  166. package/src/modules/organizations/controllers/organizations.controller.js +3 -4
  167. package/src/modules/organizations/models/membership.model.js +2 -0
  168. package/src/modules/organizations/models/organization.model.js +4 -0
  169. package/src/modules/organizations/routes/invites.routes.js +2 -2
  170. package/src/modules/organizations/store/invites.js +2 -1
  171. package/src/modules/products/controllers/leftovers.controller.js +1 -1
  172. package/src/modules/products/middlewares/index.js +11 -0
  173. package/src/modules/products/routes/categories.routes.js +2 -2
  174. package/src/modules/reports/routes/reports.routes.js +2 -2
  175. package/src/modules/spots/components/layouts/Spots.vue +2 -2
  176. package/src/modules/spots/components/pages/Map.vue +79 -78
  177. package/src/modules/users/components/pages/ProfileEdit.vue +37 -22
  178. package/src/modules/wallet/controllers/routes/payments.routes.js +2 -2
  179. package/src/modules/wallet/controllers/routes/rewards.routes.js +2 -2
  180. package/src/modules/middlewares/server/authJwt.js +0 -68
  181. /package/src/modules/{middlewares/server → auth/middlewares}/authSecret.js +0 -0
  182. /package/src/modules/{middlewares/server → auth/middlewares}/verifyInvites.js +0 -0
  183. /package/src/modules/{middlewares/server → auth/middlewares}/verifySignUp.js +0 -0
  184. /package/src/modules/{middlewares/server → auth/middlewares}/verifyUser.js +0 -0
  185. /package/src/modules/globals/services/{globals.cashe.js → globals.cache.js} +0 -0
  186. /package/src/modules/{middlewares/server → products/middlewares}/verifyCategory.js +0 -0
@@ -0,0 +1,260 @@
1
+ import require$$0 from "jsonwebtoken";
2
+ import require$$0$1 from "crypto";
3
+ import require$$0$2 from "mongodb";
4
+ var authJwt;
5
+ var hasRequiredAuthJwt;
6
+ function requireAuthJwt() {
7
+ if (hasRequiredAuthJwt) return authJwt;
8
+ hasRequiredAuthJwt = 1;
9
+ const jwt = require$$0;
10
+ const middlewareFactory = (db) => {
11
+ const User = db.user;
12
+ const Role = db.role;
13
+ const verifyToken = (continueOnFail = false) => {
14
+ return async (req, res, next) => {
15
+ try {
16
+ if (!req.cookies.user) {
17
+ req.userId = null;
18
+ if (continueOnFail) {
19
+ return next();
20
+ } else {
21
+ return res.status(401).send({ message: "Unauthorized: No user cookie" });
22
+ }
23
+ }
24
+ let user = JSON.parse(req.cookies.user);
25
+ let token = req.headers["x-access-token"] || user.accessToken;
26
+ if (!token) {
27
+ req.userId = null;
28
+ if (continueOnFail) {
29
+ return next();
30
+ } else {
31
+ return res.status(401).send({ message: "Unauthorized: No token provided" });
32
+ }
33
+ }
34
+ const decoded = jwt.verify(token, process.env.SECRET_KEY);
35
+ req.userId = decoded._id;
36
+ next();
37
+ } catch (err) {
38
+ console.log(err);
39
+ req.userId = null;
40
+ if (continueOnFail) {
41
+ next();
42
+ } else {
43
+ res.status(401).send({ message: "Unauthorized: Invalid token" });
44
+ }
45
+ }
46
+ };
47
+ };
48
+ const checkRole = (roleToCheck) => async (req, res, next) => {
49
+ try {
50
+ const user = await User.findById(req.userId).exec();
51
+ if (!user) {
52
+ return res.status(404).send({ message: "User Not found." });
53
+ }
54
+ const roles = await Role.find({ _id: { $in: user.roles } }).exec();
55
+ for (let role of roles) {
56
+ if (role.name === roleToCheck) {
57
+ next();
58
+ return;
59
+ }
60
+ }
61
+ res.status(403).send({ message: `Require ${roleToCheck} Role!` });
62
+ } catch (err) {
63
+ res.status(500).send({ message: err.message });
64
+ }
65
+ };
66
+ const isAdmin = checkRole("admin");
67
+ const isModerator = checkRole("moderator");
68
+ return {
69
+ verifyToken,
70
+ isAdmin,
71
+ isModerator
72
+ };
73
+ };
74
+ authJwt = middlewareFactory;
75
+ return authJwt;
76
+ }
77
+ var authSecret;
78
+ var hasRequiredAuthSecret;
79
+ function requireAuthSecret() {
80
+ if (hasRequiredAuthSecret) return authSecret;
81
+ hasRequiredAuthSecret = 1;
82
+ const crypto = require$$0$1;
83
+ const middlewareFactory = () => {
84
+ const verifySecret = (method, endpoint, secret) => async (req, res, next) => {
85
+ const requestSignature = req.headers.signature;
86
+ const signature = crypto.createHmac("sha256", secret).update(method + endpoint).digest("hex");
87
+ if (signature === requestSignature) {
88
+ return next();
89
+ }
90
+ res.status(403).send("Forbidden");
91
+ };
92
+ return { verifySecret };
93
+ };
94
+ authSecret = middlewareFactory;
95
+ return authSecret;
96
+ }
97
+ var verifySignUp;
98
+ var hasRequiredVerifySignUp;
99
+ function requireVerifySignUp() {
100
+ if (hasRequiredVerifySignUp) return verifySignUp;
101
+ hasRequiredVerifySignUp = 1;
102
+ const middlewareFactory = (db) => {
103
+ const User = db.user;
104
+ db.role;
105
+ const checkDuplicateUsernameOrEmail = async (req, res, next) => {
106
+ const { type, email, phone } = req.body;
107
+ console.log(req.body);
108
+ let query;
109
+ if (type === "phone" && phone) {
110
+ query = { phone };
111
+ }
112
+ if (type === "email" && email) {
113
+ query = { email };
114
+ }
115
+ try {
116
+ const user = await User.findOne(query).exec();
117
+ if (user) {
118
+ console.log(`USER_ALREADY_REGISTERED`);
119
+ res.status(400).send({ errorCode: "USER_ALREADY_REGISTERED" });
120
+ return;
121
+ }
122
+ next();
123
+ } catch (err) {
124
+ console.log(err);
125
+ res.status(500).send({ message: err.message });
126
+ }
127
+ };
128
+ const checkRolesExisted = (req, res, next) => {
129
+ if (req.body.roles) {
130
+ for (let i = 0; i < req.body.roles.length; i++) {
131
+ if (!ROLES.includes(req.body.roles[i])) {
132
+ console.log(`Failed! Role ${req.body.roles[i]} does not exist!`);
133
+ res.status(400).send({
134
+ message: `Failed! Role ${req.body.roles[i]} does not exist!`
135
+ });
136
+ return;
137
+ }
138
+ }
139
+ }
140
+ next();
141
+ };
142
+ return {
143
+ checkDuplicateUsernameOrEmail,
144
+ checkRolesExisted
145
+ };
146
+ };
147
+ verifySignUp = middlewareFactory;
148
+ return verifySignUp;
149
+ }
150
+ var verifyUser;
151
+ var hasRequiredVerifyUser;
152
+ function requireVerifyUser() {
153
+ if (hasRequiredVerifyUser) return verifyUser;
154
+ hasRequiredVerifyUser = 1;
155
+ const middlewareFactory = (db) => {
156
+ const User = db.user;
157
+ db.role;
158
+ const checkUserExist = async (req, res, next) => {
159
+ const { type, email, phone } = req.body;
160
+ let query;
161
+ if (type === "phone" && phone) {
162
+ query = { phone };
163
+ }
164
+ if (type === "email" && email) {
165
+ query = { email };
166
+ }
167
+ try {
168
+ const user = await User.findOne(query).exec();
169
+ if (!user) {
170
+ console.log(query);
171
+ res.status(400).send({ errorCode: "USER_NOT_REGISTERED_YET" });
172
+ return;
173
+ }
174
+ next();
175
+ } catch (err) {
176
+ res.status(500).send({ message: err.message });
177
+ }
178
+ };
179
+ return {
180
+ checkUserExist
181
+ };
182
+ };
183
+ verifyUser = middlewareFactory;
184
+ return verifyUser;
185
+ }
186
+ var verifyInvites;
187
+ var hasRequiredVerifyInvites;
188
+ function requireVerifyInvites() {
189
+ if (hasRequiredVerifyInvites) return verifyInvites;
190
+ hasRequiredVerifyInvites = 1;
191
+ const { ObjectId } = require$$0$2;
192
+ const middlewareFactory = (db) => {
193
+ const User = db.user;
194
+ const Invite = db.invite;
195
+ const Membership = db.membership;
196
+ const checkInviteExist = async (req, res, next) => {
197
+ for (let invite of req.body.invites) {
198
+ let query;
199
+ if (invite.contact.includes("@")) {
200
+ query = { invitedEmail: invite.contact };
201
+ } else {
202
+ query = { invitedPhone: invite.contact };
203
+ }
204
+ query["owner.target"] = req.body.owner.target;
205
+ const userInvite = await Invite.findOne(query).exec();
206
+ if (userInvite) {
207
+ console.log(userInvite);
208
+ res.status(400).send({ message: "Инвайт c таким email или телефоном уже создан!" });
209
+ return;
210
+ }
211
+ }
212
+ next();
213
+ };
214
+ const checkUsersExist = async (req, res, next) => {
215
+ for (let invite of req.body.invites) {
216
+ let query;
217
+ if (invite.contact.includes("@")) {
218
+ query = { email: invite.contact };
219
+ } else {
220
+ query = { phone: invite.contact };
221
+ }
222
+ const user = await User.findOne(query).exec();
223
+ console.log(req.params);
224
+ if (user) {
225
+ const membership = await Membership.findOne({ user: new ObjectId(user._id), "owner.target": req.body.owner.target }).exec();
226
+ if (membership) {
227
+ console.log(membership);
228
+ res.status(400).send({ message: "Пользователь с таким email или телефоном уже добавлен в организацию!" });
229
+ return;
230
+ }
231
+ }
232
+ }
233
+ next();
234
+ };
235
+ return {
236
+ checkInviteExist,
237
+ checkUsersExist
238
+ };
239
+ };
240
+ verifyInvites = middlewareFactory;
241
+ return verifyInvites;
242
+ }
243
+ const middlewareIndexFactory = (db) => {
244
+ const authJwt2 = requireAuthJwt()(db);
245
+ const authSecret2 = requireAuthSecret()();
246
+ const verifySignUp2 = requireVerifySignUp()(db);
247
+ const verifyUser2 = requireVerifyUser()(db);
248
+ const verifyInvites2 = requireVerifyInvites()(db);
249
+ return {
250
+ authJwt: authJwt2,
251
+ authSecret: authSecret2,
252
+ verifySignUp: verifySignUp2,
253
+ verifyUser: verifyUser2,
254
+ verifyInvites: verifyInvites2
255
+ };
256
+ };
257
+ var middlewares = middlewareIndexFactory;
258
+ export {
259
+ middlewares as m
260
+ };
@@ -5,7 +5,7 @@ const profile_schema = require("./profile.schema-CkOhhf37.js");
5
5
  const credentials_schema = require("./credentials.schema-B-KD_ozQ.js");
6
6
  const queryProcessor = require("./queryProcessor-iewDZq_f.js");
7
7
  const mailing = require("./mailing-BX0q8DIs.js");
8
- const index = require("./index-CDbtWkBj.js");
8
+ const index = require("./index-DNI4aUP2.js");
9
9
  const require$$0 = require("node-cache");
10
10
  const applyOwnershipSchema$1 = ownership_schema.ownership_schema;
11
11
  var order_model = (db) => {
@@ -261,6 +261,7 @@ async function sendOrderMessage(orderData) {
261
261
  const controllerFactory$1 = (db) => {
262
262
  const Order = db.order;
263
263
  const Customer = db.customer;
264
+ const Leftover = db.leftover;
264
265
  const create = async (req, res) => {
265
266
  const orderData = req.body;
266
267
  req.userId || req.body.creator.target;
@@ -409,10 +410,10 @@ const controllerFactory$1 = (db) => {
409
410
  };
410
411
  var orders_controller = controllerFactory$1;
411
412
  const controllerFactory = orders_controller;
412
- const middlewareFactory = index.server;
413
+ const middlewareFactoryAuth = index.middlewares;
413
414
  var orders_routes = function(app, db, origins, publicPath) {
414
415
  const controller = controllerFactory(db);
415
- middlewareFactory(db);
416
+ middlewareFactoryAuth(db);
416
417
  app.post(
417
418
  "/api/orders/create",
418
419
  // [
@@ -441,7 +442,7 @@ var orders_routes = function(app, db, origins, publicPath) {
441
442
  };
442
443
  const NodeCache = require$$0;
443
444
  const stdTTL = 60 * 5;
444
- class Cache {
445
+ let Cache$1 = class Cache {
445
446
  constructor(ttlSeconds = stdTTL) {
446
447
  this.cache = new NodeCache({ stdTTL: ttlSeconds });
447
448
  }
@@ -457,8 +458,8 @@ class Cache {
457
458
  async flush() {
458
459
  this.cache.flushAll();
459
460
  }
460
- }
461
- var globals_cashe = Cache;
461
+ };
462
+ var globals_cache = Cache$1;
462
463
  let Logger$1 = class Logger {
463
464
  static logModel = null;
464
465
  constructor(db) {
@@ -494,12 +495,12 @@ let Logger$1 = class Logger {
494
495
  };
495
496
  var globals_logger = Logger$1;
496
497
  const globalsQuery = queryProcessor.queryProcessor;
497
- const Cashe = globals_cashe;
498
+ const Cache2 = globals_cache;
498
499
  const Logger2 = globals_logger;
499
500
  let CRUD$1 = class CRUD {
500
501
  constructor(basePath, app, db, model) {
501
502
  this.model = model;
502
- this.cache = new Cashe();
503
+ this.cache = new Cache2();
503
504
  this.logger = new Logger2(db);
504
505
  this.app = app;
505
506
  this.basePath = basePath;
@@ -4,7 +4,7 @@ import { p as profile_schema } from "./profile.schema-24ZpZQJe.mjs";
4
4
  import { c as credentials_schema } from "./credentials.schema-C9dmNy7o.mjs";
5
5
  import { q as queryProcessor } from "./queryProcessor-DQSFR9YA.mjs";
6
6
  import { m as mailing } from "./mailing-Cdp8NXhP.mjs";
7
- import { s as server } from "./index-C-8xOJnM.mjs";
7
+ import { m as middlewares } from "./index-Tcyehi73.mjs";
8
8
  import require$$0 from "node-cache";
9
9
  const applyOwnershipSchema$1 = ownership_schema;
10
10
  var order_model = (db) => {
@@ -260,6 +260,7 @@ async function sendOrderMessage(orderData) {
260
260
  const controllerFactory$1 = (db) => {
261
261
  const Order = db.order;
262
262
  const Customer = db.customer;
263
+ const Leftover = db.leftover;
263
264
  const create = async (req, res) => {
264
265
  const orderData = req.body;
265
266
  req.userId || req.body.creator.target;
@@ -408,10 +409,10 @@ const controllerFactory$1 = (db) => {
408
409
  };
409
410
  var orders_controller = controllerFactory$1;
410
411
  const controllerFactory = orders_controller;
411
- const middlewareFactory = server;
412
+ const middlewareFactoryAuth = middlewares;
412
413
  var orders_routes = function(app, db, origins, publicPath) {
413
414
  const controller = controllerFactory(db);
414
- middlewareFactory(db);
415
+ middlewareFactoryAuth(db);
415
416
  app.post(
416
417
  "/api/orders/create",
417
418
  // [
@@ -440,7 +441,7 @@ var orders_routes = function(app, db, origins, publicPath) {
440
441
  };
441
442
  const NodeCache = require$$0;
442
443
  const stdTTL = 60 * 5;
443
- class Cache {
444
+ let Cache$1 = class Cache {
444
445
  constructor(ttlSeconds = stdTTL) {
445
446
  this.cache = new NodeCache({ stdTTL: ttlSeconds });
446
447
  }
@@ -456,8 +457,8 @@ class Cache {
456
457
  async flush() {
457
458
  this.cache.flushAll();
458
459
  }
459
- }
460
- var globals_cashe = Cache;
460
+ };
461
+ var globals_cache = Cache$1;
461
462
  let Logger$1 = class Logger {
462
463
  static logModel = null;
463
464
  constructor(db) {
@@ -493,12 +494,12 @@ let Logger$1 = class Logger {
493
494
  };
494
495
  var globals_logger = Logger$1;
495
496
  const globalsQuery = queryProcessor;
496
- const Cashe = globals_cashe;
497
+ const Cache2 = globals_cache;
497
498
  const Logger2 = globals_logger;
498
499
  let CRUD$1 = class CRUD {
499
500
  constructor(basePath, app, db, model) {
500
501
  this.model = model;
501
- this.cache = new Cashe();
502
+ this.cache = new Cache2();
502
503
  this.logger = new Logger2(db);
503
504
  this.app = app;
504
505
  this.basePath = basePath;
@@ -9,7 +9,7 @@ const require$$5 = require("@googlemaps/google-maps-services-js");
9
9
  const addMembersQuantity$1 = require("./addMembersQuantity-B8UgqlUM.js");
10
10
  const queryProcessor = require("./queryProcessor-iewDZq_f.js");
11
11
  const mailing = require("./mailing-BX0q8DIs.js");
12
- const index = require("./index-CDbtWkBj.js");
12
+ const index = require("./index-DNI4aUP2.js");
13
13
  const engagement_schema = require("./engagement.schema-D-9md46B.js");
14
14
  const ownership_schema = require("./ownership.schema-DN0SlQL6.js");
15
15
  const credentials_schema = require("./credentials.schema-B-KD_ozQ.js");
@@ -101,7 +101,6 @@ const controllerFactory$5 = (db) => {
101
101
  const sort = {
102
102
  ...sortParam === "distance" ? { "distanceExist": -1 } : {},
103
103
  [sortParam]: sortOrder === "desc" ? -1 : 1,
104
- "numberOfProducts": -1,
105
104
  "_id": 1
106
105
  };
107
106
  console.log(sort);
@@ -179,7 +178,7 @@ const controllerFactory$5 = (db) => {
179
178
  console.log(err);
180
179
  return res.status(500).send({ message: "Error occurred while geocoding." });
181
180
  }
182
- const radius = city ? 500 : state ? 1e3 : 5e3;
181
+ const radius = city ? 25 : state ? 50 : 250;
183
182
  matchConditions.push({
184
183
  "spots.location.coordinates": {
185
184
  $geoWithin: {
@@ -212,9 +211,9 @@ const controllerFactory$5 = (db) => {
212
211
  if (locationRadius) {
213
212
  radius = parseFloat(locationRadius) / earthRadiusKm;
214
213
  } else if (city) {
215
- radius = 500 / earthRadiusKm;
214
+ radius = 25 / earthRadiusKm;
216
215
  } else if (state) {
217
- radius = 1e3 / earthRadiusKm;
216
+ radius = 50 / earthRadiusKm;
218
217
  } else {
219
218
  radius = null;
220
219
  }
@@ -451,6 +450,7 @@ const ObjectId = require$$0.Types.ObjectId;
451
450
  const queryProcessorGlobals = queryProcessor.queryProcessor;
452
451
  const controllerFactory$4 = (db) => {
453
452
  const Membership = db.membership;
453
+ const Department = db.department;
454
454
  const read = async (req, res) => {
455
455
  try {
456
456
  let search = req.query.search;
@@ -537,15 +537,18 @@ const controllerFactory$4 = (db) => {
537
537
  };
538
538
  const deleteMembership = async (req, res) => {
539
539
  const { _id, type, target, user: user2, role } = req.body;
540
- console.log(req.body);
541
540
  try {
542
- const membership = _id ? await Membership.findOneAndDelete({ _id: new ObjectId(req.body._id) }) : await Membership.findOne({ type, target, user: user2, role });
541
+ const membership = _id ? await Membership.findOneAndDelete({ _id: new ObjectId(_id) }) : await Membership.findOneAndDelete({ type, target, user: user2, role });
543
542
  if (!membership) {
544
543
  return res.status(404).send({ errorCode: "MEMBERSHIP_NOT_FOUND" });
545
- } else {
546
- await Membership.deleteOne({ _id: membership._id });
547
- res.status(200).send(membership);
548
544
  }
545
+ if (membership.type === "organization") {
546
+ await Department.updateMany(
547
+ { organization: target },
548
+ { $pull: { members: { user: user2 } } }
549
+ );
550
+ }
551
+ res.status(200).send(membership);
549
552
  } catch (error) {
550
553
  console.log(error);
551
554
  res.status(500).send({ errorCode: "SERVER_ERROR" });
@@ -591,9 +594,14 @@ const сontrollerFactory = (db) => {
591
594
  const creator = req.body.creator;
592
595
  const owner = req.body.owner;
593
596
  const list = req.body.invites;
597
+ const createdInvites = [];
598
+ const createdMemberships = [];
594
599
  try {
595
600
  for (let invite of list) {
596
601
  let user2 = null;
602
+ if (!invite || !invite.contact) {
603
+ continue;
604
+ }
597
605
  if (invite.contact.includes("@")) {
598
606
  user2 = await User.findOne({ email: invite.contact });
599
607
  } else {
@@ -607,7 +615,8 @@ const сontrollerFactory = (db) => {
607
615
  role: "member",
608
616
  label: "member"
609
617
  });
610
- await membership.save();
618
+ const savedMembership = await membership.save();
619
+ createdMemberships.push(savedMembership);
611
620
  } else {
612
621
  const newInvite = new Invite({
613
622
  code: uuid(),
@@ -618,10 +627,11 @@ const сontrollerFactory = (db) => {
618
627
  phone: !invite.contact.includes("@") ? invite.contact : null
619
628
  });
620
629
  const savedInvite = await newInvite.save();
630
+ createdInvites.push(savedInvite);
621
631
  if (savedInvite.email !== null) {
622
632
  const to = savedInvite.email;
623
633
  const subject = "You have been added to the organization";
624
- const text = `You have been invited to join an organization on ${process.env.APP_NAME}! Use this link to register: ${process.env.API_URL}/auth/invite?inviteCode=${newInvite.code}&type=email"`;
634
+ const text = `You have been invited to join an organization on ${process.env.APP_NAME}! Use this link to register: ${process.env.API_URL}/auth/invite?inviteCode=${newInvite.code}&type=email`;
625
635
  await sendEmail(to, subject, text);
626
636
  }
627
637
  if (savedInvite.phone !== null) {
@@ -631,7 +641,11 @@ const сontrollerFactory = (db) => {
631
641
  }
632
642
  }
633
643
  }
634
- res.status(200).json({ message: "Invites sent successfully!" });
644
+ res.status(200).json({
645
+ message: "Invites sent successfully!",
646
+ createdInvites,
647
+ createdMemberships
648
+ });
635
649
  } catch (error) {
636
650
  console.error(error);
637
651
  res.status(500).json({ message: "Something went wrong" });
@@ -709,10 +723,10 @@ var memberships_routes = function(app, db) {
709
723
  );
710
724
  };
711
725
  const controllerFactory = invites_controller;
712
- const middlewareFactory = index.server;
726
+ const middlewareFactoryAuth = index.middlewares;
713
727
  var invites_routes = function(app, db) {
714
728
  const controller = controllerFactory(db);
715
- const { verifyInvites } = middlewareFactory(db);
729
+ const { verifyInvites } = middlewareFactoryAuth(db);
716
730
  app.get(
717
731
  "/api/invites/get/:_id",
718
732
  controller.getOneByCode
@@ -942,6 +956,7 @@ var organization_model = (db) => {
942
956
  timestamps: true
943
957
  });
944
958
  applyEngagementSchema(OrganizationSchema);
959
+ OrganizationSchema.index({ _id: 1, owner: 1 });
945
960
  const Organization = db.mongoose.model("Organization", OrganizationSchema);
946
961
  return Organization;
947
962
  };
@@ -978,6 +993,7 @@ var membership_model = (mongoose) => {
978
993
  }, {
979
994
  timestamps: true
980
995
  });
996
+ MembershipSchema.index({ user: 1, target: 1 });
981
997
  const Membership = mongoose.model("Membership", MembershipSchema);
982
998
  return Membership;
983
999
  };
@@ -8,7 +8,7 @@ import require$$5 from "@googlemaps/google-maps-services-js";
8
8
  import { a as addUserStatusFields_1, b as addMembersQuantity_1 } from "./addMembersQuantity-BXp_LeQd.mjs";
9
9
  import { q as queryProcessor } from "./queryProcessor-DQSFR9YA.mjs";
10
10
  import { m as mailing } from "./mailing-Cdp8NXhP.mjs";
11
- import { s as server } from "./index-C-8xOJnM.mjs";
11
+ import { m as middlewares } from "./index-Tcyehi73.mjs";
12
12
  import { e as engagement_schema } from "./engagement.schema-CCdSLKd4.mjs";
13
13
  import { o as ownership_schema } from "./ownership.schema-oyx6eNkZ.mjs";
14
14
  import { c as credentials_schema } from "./credentials.schema-C9dmNy7o.mjs";
@@ -100,7 +100,6 @@ const controllerFactory$5 = (db) => {
100
100
  const sort = {
101
101
  ...sortParam === "distance" ? { "distanceExist": -1 } : {},
102
102
  [sortParam]: sortOrder === "desc" ? -1 : 1,
103
- "numberOfProducts": -1,
104
103
  "_id": 1
105
104
  };
106
105
  console.log(sort);
@@ -178,7 +177,7 @@ const controllerFactory$5 = (db) => {
178
177
  console.log(err);
179
178
  return res.status(500).send({ message: "Error occurred while geocoding." });
180
179
  }
181
- const radius = city ? 500 : state ? 1e3 : 5e3;
180
+ const radius = city ? 25 : state ? 50 : 250;
182
181
  matchConditions.push({
183
182
  "spots.location.coordinates": {
184
183
  $geoWithin: {
@@ -211,9 +210,9 @@ const controllerFactory$5 = (db) => {
211
210
  if (locationRadius) {
212
211
  radius = parseFloat(locationRadius) / earthRadiusKm;
213
212
  } else if (city) {
214
- radius = 500 / earthRadiusKm;
213
+ radius = 25 / earthRadiusKm;
215
214
  } else if (state) {
216
- radius = 1e3 / earthRadiusKm;
215
+ radius = 50 / earthRadiusKm;
217
216
  } else {
218
217
  radius = null;
219
218
  }
@@ -450,6 +449,7 @@ const ObjectId = require$$0.Types.ObjectId;
450
449
  const queryProcessorGlobals = queryProcessor;
451
450
  const controllerFactory$4 = (db) => {
452
451
  const Membership = db.membership;
452
+ const Department = db.department;
453
453
  const read = async (req, res) => {
454
454
  try {
455
455
  let search = req.query.search;
@@ -536,15 +536,18 @@ const controllerFactory$4 = (db) => {
536
536
  };
537
537
  const deleteMembership = async (req, res) => {
538
538
  const { _id, type, target, user: user2, role } = req.body;
539
- console.log(req.body);
540
539
  try {
541
- const membership = _id ? await Membership.findOneAndDelete({ _id: new ObjectId(req.body._id) }) : await Membership.findOne({ type, target, user: user2, role });
540
+ const membership = _id ? await Membership.findOneAndDelete({ _id: new ObjectId(_id) }) : await Membership.findOneAndDelete({ type, target, user: user2, role });
542
541
  if (!membership) {
543
542
  return res.status(404).send({ errorCode: "MEMBERSHIP_NOT_FOUND" });
544
- } else {
545
- await Membership.deleteOne({ _id: membership._id });
546
- res.status(200).send(membership);
547
543
  }
544
+ if (membership.type === "organization") {
545
+ await Department.updateMany(
546
+ { organization: target },
547
+ { $pull: { members: { user: user2 } } }
548
+ );
549
+ }
550
+ res.status(200).send(membership);
548
551
  } catch (error) {
549
552
  console.log(error);
550
553
  res.status(500).send({ errorCode: "SERVER_ERROR" });
@@ -590,9 +593,14 @@ const сontrollerFactory = (db) => {
590
593
  const creator = req.body.creator;
591
594
  const owner = req.body.owner;
592
595
  const list = req.body.invites;
596
+ const createdInvites = [];
597
+ const createdMemberships = [];
593
598
  try {
594
599
  for (let invite of list) {
595
600
  let user2 = null;
601
+ if (!invite || !invite.contact) {
602
+ continue;
603
+ }
596
604
  if (invite.contact.includes("@")) {
597
605
  user2 = await User.findOne({ email: invite.contact });
598
606
  } else {
@@ -606,7 +614,8 @@ const сontrollerFactory = (db) => {
606
614
  role: "member",
607
615
  label: "member"
608
616
  });
609
- await membership.save();
617
+ const savedMembership = await membership.save();
618
+ createdMemberships.push(savedMembership);
610
619
  } else {
611
620
  const newInvite = new Invite({
612
621
  code: uuid(),
@@ -617,10 +626,11 @@ const сontrollerFactory = (db) => {
617
626
  phone: !invite.contact.includes("@") ? invite.contact : null
618
627
  });
619
628
  const savedInvite = await newInvite.save();
629
+ createdInvites.push(savedInvite);
620
630
  if (savedInvite.email !== null) {
621
631
  const to = savedInvite.email;
622
632
  const subject = "You have been added to the organization";
623
- const text = `You have been invited to join an organization on ${process.env.APP_NAME}! Use this link to register: ${process.env.API_URL}/auth/invite?inviteCode=${newInvite.code}&type=email"`;
633
+ const text = `You have been invited to join an organization on ${process.env.APP_NAME}! Use this link to register: ${process.env.API_URL}/auth/invite?inviteCode=${newInvite.code}&type=email`;
624
634
  await sendEmail(to, subject, text);
625
635
  }
626
636
  if (savedInvite.phone !== null) {
@@ -630,7 +640,11 @@ const сontrollerFactory = (db) => {
630
640
  }
631
641
  }
632
642
  }
633
- res.status(200).json({ message: "Invites sent successfully!" });
643
+ res.status(200).json({
644
+ message: "Invites sent successfully!",
645
+ createdInvites,
646
+ createdMemberships
647
+ });
634
648
  } catch (error) {
635
649
  console.error(error);
636
650
  res.status(500).json({ message: "Something went wrong" });
@@ -708,10 +722,10 @@ var memberships_routes = function(app, db) {
708
722
  );
709
723
  };
710
724
  const controllerFactory = invites_controller;
711
- const middlewareFactory = server;
725
+ const middlewareFactoryAuth = middlewares;
712
726
  var invites_routes = function(app, db) {
713
727
  const controller = controllerFactory(db);
714
- const { verifyInvites } = middlewareFactory(db);
728
+ const { verifyInvites } = middlewareFactoryAuth(db);
715
729
  app.get(
716
730
  "/api/invites/get/:_id",
717
731
  controller.getOneByCode
@@ -941,6 +955,7 @@ var organization_model = (db) => {
941
955
  timestamps: true
942
956
  });
943
957
  applyEngagementSchema(OrganizationSchema);
958
+ OrganizationSchema.index({ _id: 1, owner: 1 });
944
959
  const Organization = db.mongoose.model("Organization", OrganizationSchema);
945
960
  return Organization;
946
961
  };
@@ -977,6 +992,7 @@ var membership_model = (mongoose) => {
977
992
  }, {
978
993
  timestamps: true
979
994
  });
995
+ MembershipSchema.index({ user: 1, target: 1 });
980
996
  const Membership = mongoose.model("Membership", MembershipSchema);
981
997
  return Membership;
982
998
  };