@ozdao/prometheus-framework 0.1.32 → 0.1.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. package/dist/Chips-41cd6570.mjs +203 -0
  2. package/dist/Chips-c3d7341e.js +1 -0
  3. package/dist/EULA-e05236af.mjs +4210 -0
  4. package/dist/EULA-f5fba925.js +1 -0
  5. package/dist/Feed-046852fc.js +1 -0
  6. package/dist/Feed-4efa2a93.mjs +394 -0
  7. package/dist/Feed-acfbb839.mjs +371 -0
  8. package/dist/Feed-e6e84388.js +1 -0
  9. package/dist/Image-93c3a270.mjs +480 -0
  10. package/dist/Image-de94b883.js +9 -0
  11. package/dist/Product-1892b14a.js +7 -0
  12. package/dist/Product-d3f1d10a.mjs +844 -0
  13. package/dist/ProductEdit-8e779ed8.js +1 -0
  14. package/dist/ProductEdit-ebcc3f98.mjs +306 -0
  15. package/dist/ProfileBlogposts-8c10a505.js +1 -0
  16. package/dist/ProfileBlogposts-a2f7cd4c.mjs +70 -0
  17. package/dist/ProfileEvents-47409c9e.mjs +62 -0
  18. package/dist/ProfileEvents-db12cf78.js +1 -0
  19. package/dist/auth.server.js +4 -4
  20. package/dist/auth.server.mjs +4 -4
  21. package/dist/community.client.cjs +1 -1
  22. package/dist/community.client.js +217 -241
  23. package/dist/community.server.js +2 -2
  24. package/dist/community.server.mjs +2 -2
  25. package/dist/events.client.cjs +1 -1
  26. package/dist/events.client.js +4 -4
  27. package/dist/events.server.js +447 -270
  28. package/dist/events.server.mjs +447 -270
  29. package/dist/files.server.js +1 -1
  30. package/dist/files.server.mjs +1 -1
  31. package/dist/legal.client.cjs +1 -1
  32. package/dist/legal.client.js +1 -1
  33. package/dist/modules/community/components/sections/Feed.vue.d.ts +2 -0
  34. package/dist/organizations.client-76c3660a.mjs +3072 -0
  35. package/dist/organizations.client-ddbf8809.js +3 -0
  36. package/dist/organizations.client.cjs +1 -1
  37. package/dist/organizations.client.js +4 -4
  38. package/dist/organizations.server.js +4 -4
  39. package/dist/organizations.server.mjs +4 -4
  40. package/dist/style.css +1 -1
  41. package/dist/users.client.cjs +1 -1
  42. package/dist/users.client.js +2 -2
  43. package/dist/users.server.js +2 -2
  44. package/dist/users.server.mjs +2 -2
  45. package/package.json +1 -1
  46. package/src/components/CardHeader/CardHeader.vue +3 -3
  47. package/src/modules/community/components/blocks/CardBlogpost.vue +2 -4
  48. package/src/modules/community/components/sections/Feed.vue +44 -39
  49. package/src/modules/community/components/sections/HotPosts.vue +9 -56
  50. package/src/modules/events/components/blocks/CardEvent.vue +0 -2
  51. package/src/modules/events/controllers/events.controller.js +55 -265
  52. package/src/modules/events/controllers/utils/queryProcessor.js +118 -0
  53. package/src/modules/events/models/event.model.js +43 -49
  54. package/src/modules/events/models/event.new.model.js +82 -0
  55. package/src/modules/files/middlewares/server/middlewareMulter.js +1 -0
  56. package/src/modules/globals/controllers/utils/queryProcessor.js +228 -0
  57. package/src/modules/globals/models/common.schema.js +14 -0
  58. package/src/modules/globals/models/engagement.schema.js +10 -0
  59. package/src/modules/globals/models/metadata.schema.js +15 -0
  60. package/src/modules/globals/models/ownership.schema.js +34 -0
  61. package/src/modules/globals/utils/seo-friendly-url.js +28 -0
  62. package/src/modules/legal/components/pages/legal/EULA.vue +0 -3
  63. package/src/modules/products/controllers/categories.controller.js +3 -0
  64. package/src/modules/products/models/category.model.js +63 -13
  65. package/src/modules/products/models/leftover.model.js +38 -17
  66. package/src/modules/products/models/modification.model.js +31 -14
  67. package/src/modules/products/models/product.model.js +37 -38
  68. package/src/modules/products/products.server.js +11 -1
@@ -1,244 +1,381 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const _commonjsHelpers = require("./_commonjsHelpers-3b53548e.js");
4
- const require$$1 = require("mongoose");
4
+ const require$$0 = require("mongoose");
5
5
  const index = require("./index-21dfdbd9.js");
6
6
  require("jsonwebtoken");
7
7
  require("mongodb");
8
- const ObjectId = require$$1.Types.ObjectId;
9
- const middlewareFactory = (db) => {
10
- db.ticket;
11
- const Event = db.event;
12
- db.membership;
13
- const read = async (req, res) => {
14
- console.log(req.query);
15
- const sortParam = req.query.sortParam || "date.start";
16
- const sortOrder = req.query.sortOrder || "desc";
17
- const sort = {
18
- [sortParam]: sortOrder === "desc" ? -1 : 1,
19
- "_id": 1
20
- };
21
- const options = {
22
- skip: parseInt(req.query.skip) || 0,
23
- limit: parseInt(req.query.limit) || 20
24
- };
25
- req.query.status;
26
- const now = /* @__PURE__ */ new Date();
27
- const todayStart = new Date(now.getTime());
28
- todayStart.setHours(0, 0, 0, 0);
29
- const todayEnd = new Date(now.getTime());
30
- todayEnd.setHours(23, 59, 59, 999);
31
- let dateConditions = [];
32
- if (req.query.date) {
33
- const dateString = req.query.date.toString();
34
- const day = parseInt(dateString.substring(0, 2), 10);
35
- const month = parseInt(dateString.substring(2, 4), 10) - 1;
36
- const year = parseInt(dateString.substring(4, 8), 10);
37
- const customDate = new Date(year, month, day);
38
- customDate.setHours(0, 0, 0, 0);
39
- const customDateEnd = new Date(year, month, day);
40
- customDateEnd.setHours(23, 59, 59, 999);
41
- dateConditions.push({ "date.start": { $gte: customDate, $lte: customDateEnd } });
8
+ const ObjectId$1 = require$$0.Types.ObjectId;
9
+ function getTicketsLookupStage() {
10
+ return {
11
+ $lookup: {
12
+ from: "tickets",
13
+ localField: "_id",
14
+ foreignField: "target",
15
+ as: "tickets",
16
+ pipeline: [{
17
+ $lookup: {
18
+ from: "users",
19
+ localField: "user",
20
+ foreignField: "_id",
21
+ as: "user"
22
+ }
23
+ }, {
24
+ $unwind: { path: "$user", preserveNullAndEmptyArrays: true }
25
+ }]
42
26
  }
43
- if (req.query.period) {
44
- let startDate = new Date(now.getTime());
45
- let endDate = new Date(now.getTime());
46
- switch (req.query.period) {
47
- case "today":
48
- startDate.setHours(0, 0, 0, 0);
49
- endDate.setHours(23, 59, 59, 999);
50
- break;
51
- case "week":
52
- endDate.setDate(now.getDate() + 7);
53
- break;
54
- case "month":
55
- endDate.setDate(now.getDate() + 30);
56
- break;
57
- case "year":
58
- endDate.setFullYear(now.getFullYear() + 1);
59
- break;
27
+ };
28
+ }
29
+ function getParticipantsPhotosStage() {
30
+ return {
31
+ $addFields: {
32
+ participantsPhotos: {
33
+ $map: {
34
+ input: "$tickets",
35
+ as: "ticket",
36
+ in: "$$ticket.user.profile.photo"
37
+ }
60
38
  }
61
- dateConditions.push({ "date.start": { $gte: startDate, $lte: endDate } });
62
39
  }
63
- console.log(dateConditions);
64
- if (req.query.periodStart && req.query.periodEnd) {
65
- const periodStart = new Date(req.query.periodStart);
66
- const periodEnd = new Date(req.query.periodEnd);
67
- dateConditions.push({ "date.start": { $gte: periodStart, $lte: periodEnd } });
40
+ };
41
+ }
42
+ function getNumberOfTicketsStage() {
43
+ return {
44
+ $addFields: {
45
+ numberOfTickets: { $size: "$tickets" }
68
46
  }
69
- if (req.query.status) {
70
- const status = req.query.status;
71
- switch (status) {
72
- case "finished":
73
- dateConditions.push({ "date.start": { $lt: now } });
74
- break;
75
- case "today":
76
- dateConditions.push({ "date.start": { $gte: todayStart, $lte: todayEnd } });
77
- break;
78
- case "live":
79
- dateConditions.push({ "date.start": { $lte: now } });
80
- dateConditions.push({ "date.end": { $gte: now } });
81
- break;
82
- case "planned":
83
- dateConditions.push({ "date.start": { $gt: now } });
84
- break;
47
+ };
48
+ }
49
+ function getHasTicketStage(user) {
50
+ if (user) {
51
+ return [{
52
+ $addFields: {
53
+ hasTicket: {
54
+ $in: [new ObjectId$1(user), "$tickets.user._id"]
55
+ }
85
56
  }
57
+ }];
58
+ } else {
59
+ return [];
60
+ }
61
+ }
62
+ function getProjectStage() {
63
+ return {
64
+ $project: {
65
+ _id: 1,
66
+ url: 1,
67
+ cover: 1,
68
+ name: 1,
69
+ status: 1,
70
+ description: 1,
71
+ content: 1,
72
+ owner: 1,
73
+ creator: 1,
74
+ tags: 1,
75
+ date: 1,
76
+ numberOfTickets: 1,
77
+ participantsPhotos: 1,
78
+ hasTicket: 1,
79
+ tickets: 1,
80
+ createdAt: 1
86
81
  }
87
- const matchConditions = [
88
- ...dateConditions.length > 0 ? [{ $and: dateConditions }] : [],
89
- ...req.query.url ? [{ url: req.query.url }] : [],
90
- ...req.query.owner ? [{ "owner.target": new ObjectId(req.query.owner) }] : [],
91
- ...req.query.creator ? [{ "creator.target": new ObjectId(req.query.creator) }] : []
92
- ];
93
- const matchStage = matchConditions.length > 0 ? { $match: { $and: matchConditions } } : null;
94
- console.log(dateConditions);
95
- const stages = [
96
- ...matchStage != null ? [matchStage] : [],
97
- {
98
- $lookup: {
99
- from: "tickets",
100
- // замена memberships на tickets
101
- localField: "_id",
102
- foreignField: "target",
103
- as: "tickets",
104
- pipeline: [{
105
- $lookup: {
106
- from: "users",
107
- localField: "user",
108
- foreignField: "_id",
109
- as: "user"
110
- }
111
- }, {
112
- $unwind: { path: "$user", preserveNullAndEmptyArrays: true }
113
- }]
114
- }
115
- },
116
- {
117
- $addFields: {
118
- participantsPhotos: {
119
- $map: {
120
- input: "$tickets",
121
- as: "ticket",
122
- in: "$$ticket.user.profile.photo"
123
- }
124
- }
125
- }
126
- },
127
- {
128
- $addFields: {
129
- numberOfTickets: { $size: "$tickets" }
130
- }
131
- },
132
- {
133
- $addFields: {
134
- hasTicket: {
135
- $cond: {
136
- if: req.query.user,
137
- then: {
138
- $in: [new db.mongoose.Types.ObjectId(req.query.user), "$tickets.user._id"]
139
- },
140
- else: "$$REMOVE"
141
- }
82
+ };
83
+ }
84
+ function getParticipantStages(participantQuery) {
85
+ const participantId = participantQuery ? new ObjectId$1(participantQuery) : null;
86
+ let stages = [];
87
+ if (participantId) {
88
+ stages.push({
89
+ $addFields: {
90
+ "participantTickets": {
91
+ $filter: {
92
+ input: "$tickets",
93
+ as: "ticket",
94
+ cond: { $eq: ["$$ticket.user._id", participantId] }
142
95
  }
143
96
  }
144
- },
145
- {
146
- $lookup: {
147
- from: "users",
148
- localField: "creator.target",
149
- foreignField: "_id",
150
- as: "creatorUser"
151
- }
152
- },
153
- {
154
- $lookup: {
155
- from: "organizations",
156
- localField: "creator.target",
157
- foreignField: "_id",
158
- as: "creatorOrganization"
159
- }
160
- },
161
- // Для owner
162
- {
163
- $lookup: {
164
- from: "users",
165
- localField: "owner.target",
166
- foreignField: "_id",
167
- as: "ownerUser"
168
- }
169
- },
170
- {
171
- $lookup: {
172
- from: "organizations",
173
- localField: "owner.target",
174
- foreignField: "_id",
175
- as: "ownerOrganization"
97
+ }
98
+ });
99
+ stages.push({
100
+ $match: {
101
+ "participantTickets.0": { $exists: true }
102
+ }
103
+ });
104
+ }
105
+ return stages;
106
+ }
107
+ var queryProcessor$2 = {
108
+ getTicketsLookupStage,
109
+ getParticipantsPhotosStage,
110
+ getNumberOfTicketsStage,
111
+ getHasTicketStage,
112
+ getProjectStage,
113
+ getParticipantStages
114
+ };
115
+ const ObjectId = require$$0.Types.ObjectId;
116
+ function getBasicOptions(query) {
117
+ const { _id, url, owner, creator } = query;
118
+ const conditions = [];
119
+ if (_id) {
120
+ conditions.push({ _id: new ObjectId(_id) });
121
+ }
122
+ if (url) {
123
+ conditions.push({ url });
124
+ }
125
+ if (owner) {
126
+ conditions.push({ "owner.target": new ObjectId(owner) });
127
+ }
128
+ if (creator) {
129
+ conditions.push({ "creator.target": new ObjectId(creator) });
130
+ }
131
+ if (conditions.length > 0) {
132
+ return [{ $match: { $and: conditions } }];
133
+ } else {
134
+ return [];
135
+ }
136
+ }
137
+ function getSortingOptions(query) {
138
+ const sortParam = query.sortParam || "date.start";
139
+ const sortOrder = query.sortOrder || "desc";
140
+ let sort = {
141
+ [sortParam]: sortOrder === "desc" ? -1 : 1,
142
+ "_id": 1
143
+ };
144
+ return [{ $sort: sort }];
145
+ }
146
+ function getPaginationOptions(query) {
147
+ let pagination = {
148
+ skip: parseInt(query.skip) || 0,
149
+ limit: parseInt(query.limit) || 20
150
+ };
151
+ return [{ $skip: pagination.skip }, { $limit: pagination.limit }];
152
+ }
153
+ function getDateConditions(date) {
154
+ if (date) {
155
+ const dateString = date.toString();
156
+ const day = parseInt(dateString.substring(0, 2), 10);
157
+ const month = parseInt(dateString.substring(2, 4), 10) - 1;
158
+ const year = parseInt(dateString.substring(4, 8), 10);
159
+ const customDate = new Date(year, month, day);
160
+ customDate.setHours(0, 0, 0, 0);
161
+ const customDateEnd = new Date(year, month, day);
162
+ customDateEnd.setHours(23, 59, 59, 999);
163
+ return [{ $match: { "date.start": { $gte: customDate, $lte: customDateEnd } } }];
164
+ } else {
165
+ return [];
166
+ }
167
+ }
168
+ function getPeriodConditions(period, periodStart, periodEnd) {
169
+ const now = /* @__PURE__ */ new Date();
170
+ let startDate, endDate;
171
+ if (periodStart && periodEnd) {
172
+ startDate = new Date(periodStart);
173
+ endDate = new Date(periodEnd);
174
+ return [{
175
+ $match: {
176
+ "date.start": {
177
+ $gte: startDate,
178
+ $lte: endDate
176
179
  }
177
- },
178
- {
179
- $addFields: {
180
- "creator.target": {
181
- $cond: [
182
- { $eq: ["$creator.type", "user"] },
183
- { $arrayElemAt: ["$creatorUser", 0] },
184
- { $arrayElemAt: ["$creatorOrganization", 0] }
185
- ]
186
- },
187
- "owner.target": {
188
- $cond: [
189
- { $eq: ["$owner.type", "user"] },
190
- { $arrayElemAt: ["$ownerUser", 0] },
191
- { $arrayElemAt: ["$ownerOrganization", 0] }
192
- ]
193
- }
180
+ }
181
+ }];
182
+ } else if (period) {
183
+ startDate = new Date(now.getTime());
184
+ endDate = new Date(now.getTime());
185
+ switch (period) {
186
+ case "today":
187
+ startDate.setHours(0, 0, 0, 0);
188
+ endDate.setHours(23, 59, 59, 999);
189
+ break;
190
+ case "week":
191
+ endDate.setDate(now.getDate() + 7);
192
+ break;
193
+ case "month":
194
+ endDate.setDate(now.getDate() + 30);
195
+ break;
196
+ case "year":
197
+ endDate.setFullYear(now.getFullYear() + 1);
198
+ break;
199
+ }
200
+ return [{
201
+ $match: {
202
+ "date.start": {
203
+ $gte: startDate,
204
+ $lte: endDate
194
205
  }
206
+ }
207
+ }];
208
+ } else {
209
+ return [];
210
+ }
211
+ }
212
+ function getStatusConditions(status) {
213
+ const now = /* @__PURE__ */ new Date();
214
+ const todayStart = new Date(now.getTime());
215
+ todayStart.setHours(0, 0, 0, 0);
216
+ const todayEnd = new Date(now.getTime());
217
+ todayEnd.setHours(23, 59, 59, 999);
218
+ let matchConditions = [];
219
+ switch (status) {
220
+ case "finished":
221
+ matchConditions.push({ "date.start": { $lt: now } });
222
+ break;
223
+ case "today":
224
+ matchConditions.push({ "date.start": { $gte: todayStart, $lte: todayEnd } });
225
+ break;
226
+ case "live":
227
+ matchConditions.push({ "date.start": { $lte: now } });
228
+ matchConditions.push({ "date.end": { $gte: now } });
229
+ break;
230
+ case "planned":
231
+ matchConditions.push({ "date.start": { $gt: now } });
232
+ break;
233
+ }
234
+ if (matchConditions && matchConditions.length > 0) {
235
+ return [{ $match: { $and: matchConditions } }];
236
+ } else {
237
+ return [];
238
+ }
239
+ }
240
+ function getCreatorUserLookupStage() {
241
+ return {
242
+ $lookup: {
243
+ from: "users",
244
+ localField: "creator.target",
245
+ foreignField: "_id",
246
+ as: "creatorUser"
247
+ }
248
+ };
249
+ }
250
+ function getCreatorOrganizationLookupStage() {
251
+ return {
252
+ $lookup: {
253
+ from: "organizations",
254
+ localField: "creator.target",
255
+ foreignField: "_id",
256
+ as: "creatorOrganization"
257
+ }
258
+ };
259
+ }
260
+ function getOwnerUserLookupStage() {
261
+ return {
262
+ $lookup: {
263
+ from: "users",
264
+ localField: "owner.target",
265
+ foreignField: "_id",
266
+ as: "ownerUser"
267
+ }
268
+ };
269
+ }
270
+ function getOwnerOrganizationLookupStage() {
271
+ return {
272
+ $lookup: {
273
+ from: "organizations",
274
+ localField: "owner.target",
275
+ foreignField: "_id",
276
+ as: "ownerOrganization"
277
+ }
278
+ };
279
+ }
280
+ function getAddFieldsCreatorOwnerStage() {
281
+ return {
282
+ $addFields: {
283
+ "creator.target": {
284
+ $cond: [
285
+ { $eq: ["$creator.type", "user"] },
286
+ { $arrayElemAt: ["$creatorUser", 0] },
287
+ { $arrayElemAt: ["$creatorOrganization", 0] }
288
+ ]
195
289
  },
196
- {
197
- $project: {
198
- _id: 1,
199
- url: 1,
200
- cover: 1,
201
- name: 1,
202
- status: 1,
203
- description: 1,
204
- content: 1,
205
- owner: 1,
206
- creator: 1,
207
- tags: 1,
208
- date: 1,
209
- numberOfTickets: 1,
210
- participantsPhotos: 1,
211
- hasTicket: 1,
212
- tickets: 1,
213
- createdAt: 1
214
- }
290
+ "owner.target": {
291
+ $cond: [
292
+ { $eq: ["$owner.type", "user"] },
293
+ { $arrayElemAt: ["$ownerUser", 0] },
294
+ { $arrayElemAt: ["$ownerOrganization", 0] }
295
+ ]
215
296
  }
216
- ];
217
- const participantId = req.query.participant ? new db.mongoose.Types.ObjectId(req.query.participant) : null;
218
- if (participantId) {
219
- stages.push({
220
- $addFields: {
221
- "participantTickets": {
222
- $filter: {
223
- input: "$tickets",
224
- as: "ticket",
225
- cond: { $eq: ["$$ticket.user._id", participantId] }
226
- }
227
- }
228
- }
229
- });
230
- stages.push({
231
- $match: {
232
- "participantTickets.0": { $exists: true }
233
- }
234
- });
235
297
  }
236
- stages.push({ $sort: sort });
237
- stages.push({ $skip: options.skip });
238
- stages.push({ $limit: options.limit });
298
+ };
299
+ }
300
+ var queryProcessor$1 = {
301
+ getBasicOptions,
302
+ getSortingOptions,
303
+ getPaginationOptions,
304
+ getDateConditions,
305
+ getStatusConditions,
306
+ getPeriodConditions,
307
+ // Creator and Owner
308
+ getCreatorUserLookupStage,
309
+ getCreatorOrganizationLookupStage,
310
+ getOwnerUserLookupStage,
311
+ getOwnerOrganizationLookupStage,
312
+ getAddFieldsCreatorOwnerStage
313
+ };
314
+ function createFriendlyURL$1(str) {
315
+ if (typeof str !== "string") {
316
+ throw new Error("Входные данные должны быть строкой");
317
+ }
318
+ str = str.trim().toLowerCase();
319
+ str = str.replace(/ /g, "-").replace(/[^\w-]+/g, "");
320
+ str = str.replace(/-+/g, "-");
321
+ str = str.replace(/^-+|-+$/g, "");
322
+ return str;
323
+ }
324
+ var seoFriendlyUrl = createFriendlyURL$1;
325
+ require$$0.Types.ObjectId;
326
+ const queryProcessor = queryProcessor$2;
327
+ const queryProcessorGlobals = queryProcessor$1;
328
+ const createFriendlyURL = seoFriendlyUrl;
329
+ const middlewareFactory = (db) => {
330
+ db.ticket;
331
+ const Event = db.event;
332
+ db.membership;
333
+ const read = async (req, res) => {
334
+ let stages = [];
335
+ stages = [
336
+ ...queryProcessorGlobals.getBasicOptions(
337
+ req.query
338
+ ),
339
+ ...queryProcessorGlobals.getDateConditions(
340
+ req.query.date
341
+ ),
342
+ ...queryProcessorGlobals.getPeriodConditions(
343
+ req.query.period,
344
+ req.query.periodStart,
345
+ req.query.periodEnd
346
+ ),
347
+ ...queryProcessorGlobals.getStatusConditions(
348
+ req.query.status
349
+ ),
350
+ // Tickets and Participants
351
+ queryProcessor.getTicketsLookupStage(),
352
+ queryProcessor.getParticipantsPhotosStage(),
353
+ queryProcessor.getNumberOfTicketsStage(),
354
+ ...queryProcessor.getHasTicketStage(
355
+ req.query.user
356
+ ),
357
+ ...queryProcessor.getParticipantStages(
358
+ req.query.participant
359
+ ),
360
+ // For creator
361
+ queryProcessorGlobals.getCreatorUserLookupStage(),
362
+ queryProcessorGlobals.getCreatorOrganizationLookupStage(),
363
+ // For owner
364
+ queryProcessorGlobals.getOwnerUserLookupStage(),
365
+ queryProcessorGlobals.getOwnerOrganizationLookupStage(),
366
+ queryProcessorGlobals.getAddFieldsCreatorOwnerStage(),
367
+ // Get object
368
+ queryProcessor.getProjectStage(),
369
+ // Pagination
370
+ ...queryProcessorGlobals.getSortingOptions(
371
+ req.query
372
+ ),
373
+ ...queryProcessorGlobals.getPaginationOptions(
374
+ req.query
375
+ )
376
+ ];
239
377
  try {
240
- const events = await Event.aggregate(stages);
241
- console.log(events);
378
+ const events = await Event.aggregate(stages).exec();
242
379
  res.status(200).send(events);
243
380
  } catch (err) {
244
381
  console.log(err);
@@ -246,16 +383,16 @@ const middlewareFactory = (db) => {
246
383
  }
247
384
  };
248
385
  const create = async (req, res) => {
249
- try {
386
+ if (req.body._id)
250
387
  delete req.body._id;
251
- req.body.url = req.body.name.toLowerCase().replace(/ /g, "-").replace(/[^\w-]+/g, "");
388
+ try {
389
+ req.body.url = createFriendlyURL(req.body.name);
252
390
  const event = await Event.create(req.body);
253
391
  if (!event) {
254
392
  return res.status(404).send({ message: "Event is not created." });
255
393
  }
256
394
  res.status(200).send(event);
257
395
  } catch (err) {
258
- console.log(err);
259
396
  return res.status(500).send({ message: err.message });
260
397
  }
261
398
  };
@@ -497,44 +634,28 @@ var tickets_routes = function(app, db, origins) {
497
634
  );
498
635
  };
499
636
  const tickets_routes$1 = /* @__PURE__ */ _commonjsHelpers.getDefaultExportFromCjs(tickets_routes);
500
- var event_model = (mongoose) => {
501
- const EventSchema = new mongoose.Schema({
502
- url: {
503
- type: String,
504
- required: true
505
- },
506
- cover: {
507
- type: String
508
- },
509
- name: {
510
- type: String,
511
- required: true
512
- },
637
+ var common_schema = (mongoose) => {
638
+ const CommonSchema2 = new mongoose.Schema({
513
639
  status: {
514
640
  type: String,
515
641
  enum: ["draft", "published", "removed"],
516
642
  default: "draft",
517
643
  required: true
518
- },
519
- description: {
520
- type: String,
521
- required: true
522
- },
523
- content: {
524
- type: Array
525
- },
526
- date: {
527
- start: {
528
- type: Date,
529
- required: true
530
- },
531
- end: {
532
- type: Date
533
- }
534
- },
535
- tags: [{
536
- type: String
537
- }],
644
+ }
645
+ });
646
+ return CommonSchema2;
647
+ };
648
+ var engagement_schema = (db) => {
649
+ const EngagementSchema2 = new db.mongoose.Schema({
650
+ views: {
651
+ type: Number,
652
+ default: 0
653
+ }
654
+ });
655
+ return EngagementSchema2;
656
+ };
657
+ var ownership_schema = (mongoose) => {
658
+ const OwnershipSchema2 = new mongoose.Schema({
538
659
  owner: {
539
660
  type: {
540
661
  type: String,
@@ -542,12 +663,7 @@ var event_model = (mongoose) => {
542
663
  },
543
664
  target: {
544
665
  type: mongoose.Schema.Types.ObjectId,
545
- ref: function(value) {
546
- if (this.owner.type === "user")
547
- return "User";
548
- if (this.owner.type === "organization")
549
- return "Organization";
550
- },
666
+ refPath: "owner.type",
551
667
  required: true
552
668
  }
553
669
  },
@@ -562,13 +678,60 @@ var event_model = (mongoose) => {
562
678
  },
563
679
  target: {
564
680
  type: mongoose.Schema.Types.ObjectId,
565
- ref: function(value) {
566
- if (this.owner.type === "user")
567
- return "User";
568
- if (this.owner.type === "organization")
569
- return "Organization";
570
- },
681
+ refPath: "creator.type",
682
+ required: true
683
+ }
684
+ }
685
+ });
686
+ return OwnershipSchema2;
687
+ };
688
+ var metadata_schema = (mongoose) => {
689
+ const MetadataSchema2 = new mongoose.Schema({
690
+ url: {
691
+ type: String,
692
+ required: true
693
+ },
694
+ tags: [{
695
+ type: String
696
+ }]
697
+ });
698
+ return MetadataSchema2;
699
+ };
700
+ const CommonSchema = common_schema;
701
+ const EngagementSchema = engagement_schema;
702
+ const OwnershipSchema = ownership_schema;
703
+ const MetadataSchema = metadata_schema;
704
+ var event_model = (db) => {
705
+ const EventSchema = new db.mongoose.Schema({
706
+ ...CommonSchema,
707
+ ...EngagementSchema,
708
+ ...OwnershipSchema,
709
+ ...MetadataSchema,
710
+ // views: {
711
+ // type: Number,
712
+ // default: 0
713
+ // },
714
+ cover: {
715
+ type: String
716
+ },
717
+ name: {
718
+ type: String,
719
+ required: true
720
+ },
721
+ description: {
722
+ type: String,
723
+ required: true
724
+ },
725
+ content: {
726
+ type: Array
727
+ },
728
+ date: {
729
+ start: {
730
+ type: Date,
571
731
  required: true
732
+ },
733
+ end: {
734
+ type: Date
572
735
  }
573
736
  }
574
737
  }, {
@@ -577,7 +740,21 @@ var event_model = (mongoose) => {
577
740
  }
578
741
  });
579
742
  EventSchema.index({ "url": 1, "name": 1, "date.start": 1, "date.end": -1, "tags": 1, "owner.target": 1, "creator.target": 1 });
580
- const Event = mongoose.model("Event", EventSchema);
743
+ EventSchema.post("aggregate", async function(docs) {
744
+ console.log(EventSchema);
745
+ if (docs.length > 0) {
746
+ console.log("Post-aggregate hook triggered");
747
+ try {
748
+ await Promise.all(docs.map(async (doc) => {
749
+ console.log(doc._id);
750
+ const updatedViews = await db.event.findOneAndUpdate({ _id: doc._id }, { $inc: { views: 1 } }).exec();
751
+ }));
752
+ } catch (error) {
753
+ console.error("Error updating views:", error);
754
+ }
755
+ }
756
+ });
757
+ const Event = db.mongoose.model("Event", EventSchema);
581
758
  return Event;
582
759
  };
583
760
  const event_model$1 = /* @__PURE__ */ _commonjsHelpers.getDefaultExportFromCjs(event_model);