@@ -62,7 +62,7 @@ export interface UserNotificationsDBScheme {
6262 /**
6363 * Types of notifications to receive
6464 */
65- whatToReceive : { [ key in UserNotificationType ] : boolean } ;
65+ whatToReceive : { [ key in UserNotificationType ] : boolean } ;
6666}
6767
6868/**
@@ -85,6 +85,11 @@ export enum UserNotificationType {
8585 SystemMessages = 'SystemMessages' ,
8686}
8787
88+ /**
89+ * This structure represents how user projects last visit is stored at the DB (in 'users' collection)
90+ */
91+ type UserProjectsLastVisitDBScheme = Record < string , number > ;
92+
8893/**
8994 * User model
9095 */
@@ -130,6 +135,11 @@ export default class UserModel extends AbstractModel<UserDBScheme> implements Us
130135 */
131136 public notifications ! : UserNotificationsDBScheme ;
132137
138+ /**
139+ * User projects last visit
140+ */
141+ public projectsLastVisit ! : UserProjectsLastVisitDBScheme ;
142+
133143 /**
134144 * Saved bank cards for one-click payments
135145 */
@@ -233,6 +243,33 @@ export default class UserModel extends AbstractModel<UserDBScheme> implements Us
233243 }
234244 }
235245
246+ /**
247+ * Update user's last project visit
248+ *
249+ * @param projectId - project id
250+ * @returns {Promise<number> } - last project visit timestamp
251+ */
252+ public async updateLastProjectVisit ( projectId : string ) : Promise < number > {
253+ const time = Date . now ( ) / 1000 ;
254+
255+ await this . update (
256+ { _id : new ObjectId ( this . _id ) } ,
257+ { [ `projectsLastVisit.${ projectId } ` ] : time }
258+ ) ;
259+
260+ return time ;
261+ }
262+
263+ /**
264+ * Get user's last project visit
265+ *
266+ * @param projectId - project id
267+ * @returns {Promise<number> } - last project visit timestamp
268+ */
269+ public async getLastProjectVisit ( projectId : string ) : Promise < number > {
270+ return this . projectsLastVisit ?. [ projectId ] || 0 ;
271+ }
272+
236273 /**
237274 * Update user profile data
238275 * @param user – user object
@@ -323,7 +360,7 @@ export default class UserModel extends AbstractModel<UserDBScheme> implements Us
323360 * Remove workspace from membership collection
324361 * @param workspaceId - id of workspace to remove
325362 */
326- public async removeWorkspace ( workspaceId : string ) : Promise < { workspaceId : string } > {
363+ public async removeWorkspace ( workspaceId : string ) : Promise < { workspaceId : string } > {
327364 await this . membershipCollection . deleteOne ( {
328365 workspaceId : new ObjectId ( workspaceId ) ,
329366 } ) ;
0 commit comments