|
@@ -5,7 +5,7 @@ import {
|
|
|
import mongoosePaginate from 'mongoose-paginate-v2';
|
|
import mongoosePaginate from 'mongoose-paginate-v2';
|
|
|
|
|
|
|
|
import {
|
|
import {
|
|
|
- ISnapshot, AllSupportedAction, SupportedActionType,
|
|
|
|
|
|
|
+ IActivity, ISnapshot, AllSupportedAction, SupportedActionType,
|
|
|
AllSupportedTargetModel, SupportedTargetModelType,
|
|
AllSupportedTargetModel, SupportedTargetModelType,
|
|
|
AllSupportedEventModel, SupportedEventModelType,
|
|
AllSupportedEventModel, SupportedEventModelType,
|
|
|
} from '~/interfaces/activity';
|
|
} from '~/interfaces/activity';
|
|
@@ -14,8 +14,11 @@ import loggerFactory from '../../utils/logger';
|
|
|
|
|
|
|
|
import Subscription from './subscription';
|
|
import Subscription from './subscription';
|
|
|
|
|
|
|
|
|
|
+
|
|
|
const logger = loggerFactory('growi:models:activity');
|
|
const logger = loggerFactory('growi:models:activity');
|
|
|
|
|
|
|
|
|
|
+type CreateActivityParameterType = Pick<IActivity, 'user' | 'createdAt' | 'ip' | 'endpoint' | 'snapshot'>
|
|
|
|
|
+type UpdateActivityParameterType = Omit<IActivity, 'user' | 'createdAt' | 'ip' | 'endpoint'>
|
|
|
export interface ActivityDocument extends Document {
|
|
export interface ActivityDocument extends Document {
|
|
|
_id: Types.ObjectId
|
|
_id: Types.ObjectId
|
|
|
user: Types.ObjectId
|
|
user: Types.ObjectId
|
|
@@ -112,6 +115,18 @@ activitySchema.methods.getNotificationTargetUsers = async function() {
|
|
|
return activeNotificationUsers;
|
|
return activeNotificationUsers;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+activitySchema.statics.createByParameters = async function(parameters: CreateActivityParameterType): Promise<IActivity> {
|
|
|
|
|
+ const activity = await this.create(parameters) as unknown as IActivity;
|
|
|
|
|
+
|
|
|
|
|
+ return activity;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+activitySchema.statics.updateByParameters = async function(activityId: string, parameters: UpdateActivityParameterType): Promise<IActivity> {
|
|
|
|
|
+ const activity = await this.findOneAndUpdate({ _id: activityId }, parameters, { new: true }) as unknown as IActivity;
|
|
|
|
|
+
|
|
|
|
|
+ return activity;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
activitySchema.statics.getPaginatedActivity = async function(limit: number, offset: number, query) {
|
|
activitySchema.statics.getPaginatedActivity = async function(limit: number, offset: number, query) {
|
|
|
const paginateResult = await this.paginate(
|
|
const paginateResult = await this.paginate(
|
|
|
query,
|
|
query,
|