Просмотр исходного кода

Merge pull request #4393 from weseek/fix/77829-change-model-name

fix: change model name
Yuki Takei 4 лет назад
Родитель
Сommit
e8777b5b75

+ 3 - 3
packages/app/src/server/models/activity.ts

@@ -8,7 +8,7 @@ import { getOrCreateModel, getModelSafely } from '../util/mongoose-utils';
 import loggerFactory from '../../utils/logger';
 import ActivityDefine from '../util/activityDefine';
 
-import Watcher from './watcher';
+import Subscription from './subscription';
 // import { InAppNotification } from './in-app-notification';
 
 const logger = loggerFactory('growi:models:activity');
@@ -184,8 +184,8 @@ module.exports = function(crowi: Crowi) {
     const model: any = await this.model(targetModel).findById(target);
     const [targetUsers, watchUsers, ignoreUsers] = await Promise.all([
       model.getNotificationTargetUsers(),
-      Watcher.getWatchers((target as any) as Types.ObjectId),
-      Watcher.getIgnorers((target as any) as Types.ObjectId),
+      Subscription.getWatchers((target as any) as Types.ObjectId),
+      Subscription.getUnwatchers((target as any) as Types.ObjectId),
     ]);
 
     const unique = array => Object.values(array.reduce((objects, object) => ({ ...objects, [object.toString()]: object }), {}));

+ 21 - 21
packages/app/src/server/models/watcher.ts → packages/app/src/server/models/subscription.ts

@@ -6,10 +6,10 @@ import ActivityDefine from '../util/activityDefine';
 import { getOrCreateModel } from '../util/mongoose-utils';
 
 const STATUS_WATCH = 'WATCH';
-const STATUS_IGNORE = 'IGNORE';
-const STATUSES = [STATUS_WATCH, STATUS_IGNORE];
+const STATUS_UNWATCH = 'UNWATCH';
+const STATUSES = [STATUS_WATCH, STATUS_UNWATCH];
 
-export interface IWatcher {
+export interface ISubscription {
   user: Types.ObjectId
   targetModel: string
   target: Types.ObjectId
@@ -17,20 +17,20 @@ export interface IWatcher {
   createdAt: Date
 
   isWatching(): boolean
-  isIgnoring(): boolean
+  isUnwatching(): boolean
 }
 
-export interface WatcherDocument extends IWatcher, Document {}
+export interface SubscriptionDocument extends ISubscription, Document {}
 
-export interface WatcherModel extends Model<WatcherDocument> {
+export interface SubscriptionModel extends Model<SubscriptionDocument> {
   findByUserIdAndTargetId(userId: Types.ObjectId, targetId: Types.ObjectId): any
   upsertWatcher(user: Types.ObjectId, targetModel: string, target: Types.ObjectId, status: string): any
   watchByPageId(user: Types.ObjectId, pageId: Types.ObjectId, status: string): any
   getWatchers(target: Types.ObjectId): Promise<Types.ObjectId[]>
-  getIgnorers(target: Types.ObjectId): Promise<Types.ObjectId[]>
+  getUnwatchers(target: Types.ObjectId): Promise<Types.ObjectId[]>
 }
 
-const watcherSchema = new Schema<WatcherDocument, WatcherModel>({
+const subscriptionSchema = new Schema<SubscriptionDocument, SubscriptionModel>({
   user: {
     type: Schema.Types.ObjectId,
     ref: 'User',
@@ -55,19 +55,19 @@ const watcherSchema = new Schema<WatcherDocument, WatcherModel>({
   createdAt: { type: Date, default: Date.now },
 });
 
-watcherSchema.methods.isWatching = function() {
+subscriptionSchema.methods.isWatching = function() {
   return this.status === STATUS_WATCH;
 };
 
-watcherSchema.methods.isIgnoring = function() {
-  return this.status === STATUS_IGNORE;
+subscriptionSchema.methods.isUnwatching = function() {
+  return this.status === STATUS_UNWATCH;
 };
 
-watcherSchema.statics.findByUserIdAndTargetId = function(userId, targetId) {
+subscriptionSchema.statics.findByUserIdAndTargetId = function(userId, targetId) {
   return this.findOne({ user: userId, target: targetId });
 };
 
-watcherSchema.statics.upsertWatcher = function(user, targetModel, target, status) {
+subscriptionSchema.statics.upsertWatcher = function(user, targetModel, target, status) {
   const query = { user, targetModel, target };
   const doc = { ...query, status };
   const options = {
@@ -76,24 +76,24 @@ watcherSchema.statics.upsertWatcher = function(user, targetModel, target, status
   return this.findOneAndUpdate(query, doc, options);
 };
 
-watcherSchema.statics.watchByPageId = function(user, pageId, status) {
+subscriptionSchema.statics.watchByPageId = function(user, pageId, status) {
   return this.upsertWatcher(user, 'Page', pageId, status);
 };
 
-watcherSchema.statics.getWatchers = async function(target) {
+subscriptionSchema.statics.getWatchers = async function(target) {
   return this.find({ target, status: STATUS_WATCH }).distinct('user');
 };
 
-watcherSchema.statics.getIgnorers = async function(target) {
-  return this.find({ target, status: STATUS_IGNORE }).distinct('user');
+subscriptionSchema.statics.getUnwatchers = async function(target) {
+  return this.find({ target, status: STATUS_UNWATCH }).distinct('user');
 };
 
-watcherSchema.statics.STATUS_WATCH = function() {
+subscriptionSchema.statics.STATUS_WATCH = function() {
   return STATUS_WATCH;
 };
 
-watcherSchema.statics.STATUS_IGNORE = function() {
-  return STATUS_IGNORE;
+subscriptionSchema.statics.STATUS_UNWATCH = function() {
+  return STATUS_UNWATCH;
 };
 
-export default getOrCreateModel<WatcherDocument, WatcherModel>('Watcher', watcherSchema);
+export default getOrCreateModel<SubscriptionDocument, SubscriptionModel>('Subscription', subscriptionSchema);