File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -109,25 +109,6 @@ export class DbHelper {
109109 await this . workspacesCollection . bulkWrite ( operations ) ;
110110 }
111111
112- /**
113- * Method to change workspace isBlocked state
114- *
115- * @param workspaceId - id of the workspace to be changed
116- * @param isBlocked - new isBlocked state of the workspace
117- */
118- public async changeWorkspaceBlockedState ( workspaceId : string , isBlocked : boolean ) : Promise < void > {
119- const result = await this . workspacesCollection . updateOne (
120- { _id : new ObjectId ( workspaceId ) } ,
121- {
122- $set : {
123- isBlocked,
124- } ,
125- }
126- ) ;
127-
128- console . log ( 'result of changeWorkspaceBlockedState' , JSON . stringify ( result ) ) ;
129- }
130-
131112 /**
132113 * Returns total event counts for last billing period
133114 *
Original file line number Diff line number Diff line change @@ -128,7 +128,10 @@ export default class LimiterWorker extends Worker {
128128 const workspaceProjects = await this . dbHelper . getProjects ( event . workspaceId ) ;
129129 const projectIds = workspaceProjects . map ( project => project . _id . toString ( ) ) ;
130130
131- await this . dbHelper . changeWorkspaceBlockedState ( event . workspaceId , true ) ;
131+ const { updatedWorkspace } = await this . prepareWorkspaceUsageUpdate ( workspace , workspaceProjects ) ;
132+
133+ updatedWorkspace . isBlocked = true ;
134+ await this . dbHelper . updateWorkspacesEventsCountAndIsBlocked ( [ updatedWorkspace ] ) ;
132135
133136 this . logger . info ( 'workspace blocked in db ' , event . workspaceId )
134137
@@ -170,7 +173,8 @@ export default class LimiterWorker extends Worker {
170173 return ;
171174 }
172175
173- await this . dbHelper . changeWorkspaceBlockedState ( event . workspaceId , false ) ;
176+ updatedWorkspace . isBlocked = false ;
177+
174178 await this . dbHelper . updateWorkspacesEventsCountAndIsBlocked ( [ updatedWorkspace ] ) ;
175179 await this . redis . removeBannedProjects ( projectIds ) ;
176180
Original file line number Diff line number Diff line change @@ -272,34 +272,6 @@ describe('DbHelper', () => {
272272 } ) ;
273273 } ) ;
274274
275- describe ( 'changeWorkspaceBlockedState' , ( ) => {
276- test ( 'Should change workspace blocked state' , async ( ) => {
277- /**
278- * Arrange
279- */
280- const workspace = createWorkspaceMock ( {
281- plan : mockedPlans . eventsLimit10 ,
282- billingPeriodEventsCount : 0 ,
283- lastChargeDate : new Date ( ) ,
284- isBlocked : false ,
285- } ) ;
286-
287- await workspaceCollection . insertOne ( workspace ) ;
288-
289- /**
290- * Act
291- */
292- await dbHelper . changeWorkspaceBlockedState ( workspace . _id . toString ( ) , true ) ;
293-
294- /**
295- * Assert
296- */
297- const updatedWorkspace = await workspaceCollection . findOne ( { _id : workspace . _id } ) ;
298-
299- expect ( updatedWorkspace . isBlocked ) . toBe ( true ) ;
300- } ) ;
301- } ) ;
302-
303275 describe ( 'getEventsCountByProject' , ( ) => {
304276 test ( 'Should count events and repetitions for a project' , async ( ) => {
305277 /**
You can’t perform that action at this time.
0 commit comments