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