Răsfoiți Sursa

Create page.publish() & page.unpublish()

Shun Miyazawa 2 ani în urmă
părinte
comite
95663229ed

+ 11 - 0
apps/app/src/server/models/page.ts

@@ -140,6 +140,7 @@ const schema = new Schema<PageDocument, PageModel>({
   commentCount: { type: Number, default: 0 },
   expandContentWidth: { type: Boolean },
   wip: { type: Boolean },
+  wipExpiredAt: { type: Date },
   updatedAt: { type: Date, default: Date.now }, // Do not use timetamps for updatedAt because it breaks 'updateMetadata: false' option
   deleteUser: { type: ObjectId, ref: 'User' },
   deletedAt: { type: Date },
@@ -1052,6 +1053,16 @@ schema.methods.calculateAndUpdateLatestRevisionBodyLength = async function(this:
   await this.save();
 };
 
+schema.methods.publish = function() {
+  this.wip = false;
+  this.wipExpiredAt = undefined;
+};
+
+schema.methods.unpublish = function() {
+  this.wip = true;
+  this.wipExpiredAt = new Date();
+};
+
 /*
  * Merge obsolete page model methods and define new methods which depend on crowi instance
  */

+ 3 - 1
apps/app/src/server/service/page/index.ts

@@ -3792,7 +3792,9 @@ class PageService implements IPageService {
     }
 
     // Set wip
-    page.wip = options.wip ?? false;
+    if (options.wip) {
+      page.unpublish();
+    }
 
     // Save
     let savedPage = await page.save();