Skip to content

Commit

Permalink
[TM-1531] add clear endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
egrojMonroy committed Dec 9, 2024
1 parent 389299d commit d9ba351
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions apps/job-service/src/jobs/delayed-jobs.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller, Get, NotFoundException, Param, UnauthorizedException, Request } from '@nestjs/common';
import { Controller, Get, NotFoundException, Param, UnauthorizedException, Request, Patch } from '@nestjs/common';
import { ApiException } from '@nanogiants/nestjs-swagger-api-exception-decorator';
import { ApiOperation } from '@nestjs/swagger';
import { User } from '@terramatch-microservices/database/entities';
import { Op } from 'sequelize';
import { JsonApiResponse } from '@terramatch-microservices/common/decorators';
import {
buildJsonApi,
Expand Down Expand Up @@ -63,4 +63,27 @@ export class DelayedJobsController {
.addData(pathUUID, new DelayedJobDto(job))
.document.serialize();
}
}

@Patch('clear')
@ApiOperation({
operationId: 'clearNonPendingJobs',
description: 'Set isCleared to true for all jobs where status is not pending.',
})
@ApiException(() => UnauthorizedException, {
description: 'Authentication failed.',
})
async clearNonPendingJobs(@Request() { authenticatedUserId }): Promise<{ message: string }> {
const updatedCount = await DelayedJob.update(
{ isCleared: true },
{
where: {
isCleared: false,
status: { [Op.ne]: 'pending' },
createdBy: authenticatedUserId,
},
}
);

return { message: `${updatedCount[0]} jobs have been cleared.` };
}
}

0 comments on commit d9ba351

Please sign in to comment.