@underpostnet/underpost 2.96.1 → 2.97.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -64,20 +64,39 @@ const DocumentService = {
64
64
  const lastDoc = await Document.findOne(queryPayload, '_id').sort({ createdAt: 1 });
65
65
  const lastId = lastDoc ? lastDoc._id : null;
66
66
 
67
+ // Add totalCopyShareLinkCount to each document
68
+ const dataWithCounts = data.map((doc) => {
69
+ const docObj = doc.toObject ? doc.toObject() : doc;
70
+ return {
71
+ ...docObj,
72
+ totalCopyShareLinkCount: DocumentDto.getTotalCopyShareLinkCount(doc),
73
+ };
74
+ });
75
+
67
76
  return {
68
- data,
77
+ data: dataWithCounts,
69
78
  lastId,
70
79
  };
71
80
  }
72
81
 
73
82
  switch (req.params.id) {
74
- default:
75
- return await Document.find({
83
+ default: {
84
+ const data = await Document.find({
76
85
  userId: req.auth.user._id,
77
86
  ...(req.params.id ? { _id: req.params.id } : undefined),
78
87
  })
79
88
  .populate(DocumentDto.populate.file())
80
89
  .populate(DocumentDto.populate.mdFile());
90
+
91
+ // Add totalCopyShareLinkCount to each document
92
+ return data.map((doc) => {
93
+ const docObj = doc.toObject ? doc.toObject() : doc;
94
+ return {
95
+ ...docObj,
96
+ totalCopyShareLinkCount: DocumentDto.getTotalCopyShareLinkCount(doc),
97
+ };
98
+ });
99
+ }
81
100
  }
82
101
  },
83
102
  delete: async (req, res, options) => {
@@ -131,6 +150,45 @@ const DocumentService = {
131
150
  }
132
151
  }
133
152
  },
153
+ patch: async (req, res, options) => {
154
+ /** @type {import('./document.model.js').DocumentModel} */
155
+ const Document = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.models.Document;
156
+
157
+ if (req.path.includes('/copy-share-link')) {
158
+ const document = await Document.findById(req.params.id);
159
+ if (!document) throw new Error('Document not found');
160
+
161
+ const now = new Date();
162
+ const year = now.getFullYear();
163
+ const month = now.getMonth() + 1; // 0-indexed
164
+ const day = now.getDate();
165
+
166
+ // Find existing entry for this year/month/day
167
+ const existingEventIndex = document.share?.copyShareLinkEvent?.findIndex(
168
+ (event) => event.year === year && event.month === month && event.day === day,
169
+ );
170
+
171
+ if (existingEventIndex !== undefined && existingEventIndex >= 0) {
172
+ // Increment existing count
173
+ document.share.copyShareLinkEvent[existingEventIndex].count += 1;
174
+ } else {
175
+ // Create new entry
176
+ if (!document.share) document.share = {};
177
+ if (!document.share.copyShareLinkEvent) document.share.copyShareLinkEvent = [];
178
+ document.share.copyShareLinkEvent.push({
179
+ year,
180
+ month,
181
+ day,
182
+ count: 1,
183
+ });
184
+ }
185
+
186
+ await document.save();
187
+ return document;
188
+ }
189
+
190
+ throw new Error('Invalid patch endpoint');
191
+ },
134
192
  };
135
193
 
136
194
  export { DocumentService };