MCPcopy Create free account
hub / github.com/async-labs/async / archive

Method archive

api/server/models/Discussion.ts:285–315  ·  view source on GitHub ↗
({ userId, discussionId, action })

Source from the content-addressed store, hash-verified

283
284 // inside `app`, make sure that Comment cannot be added to the Archived Discussion
285 public static async archive({ userId, discussionId, action }): Promise<any> {
286 if (!discussionId || !action) {
287 throw new Error('Bad data');
288 }
289
290 const discussion = await this.findById(discussionId).setOptions({ lean: true });
291
292 if (!discussion) {
293 throw new Error('Not found');
294 }
295
296 await this.checkPermission({ userId, teamId: discussion.teamId, discussion });
297
298 let isDiscussionArchived;
299
300 if (action === 'archive') {
301 isDiscussionArchived = true;
302 } else if (action === 'unarchive') {
303 isDiscussionArchived = false;
304 }
305
306 await this.findOneAndUpdate(
307 { _id: discussionId },
308 {
309 isDiscussionArchived,
310 },
311 { runValidators: true, new: true },
312 ).setOptions({ lean: true });
313
314 return { teamId: discussion.teamId };
315 }
316
317 public static async searchByContent({ userId, teamId, whichList, query }) {
318 await this.checkPermission({ userId, teamId });

Callers

nothing calls this directly

Calls 1

checkPermissionMethod · 0.95

Tested by

no test coverage detected