Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update job listing feature #623

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

alexindevs
Copy link
Contributor

This PR implements an API endpoint to update job post details, allowing users to modify existing job listings in case of omissions or errors.

Changes

  • Added a new PATCH endpoint at api/v1/jobs/:id
  • Implemented authentication and authorization checks
  • Added input validation for request body
  • Updated JobsService with new update method
  • Added error handling for non-existent jobs
  • Implemented unit tests for the new functionality

Technical Details

  • Endpoint: PATCH api/v1/jobs/:id

  • Authentication: Bearer token required in Authorization header

  • Request body:

     {
      "title": "Software Engineer",
      "description": "Responsible for developing and maintaining web applications.",
      "location": "New York, NY",
      "deadline": "2024-12-31T23:59:59Z",
      "salary_range": "30k_to_50k",
      "job_type": "full-time",
      "job_mode": "remote",
      "company_name": "Tech Corp"
    }

    Note: All fields are optional for updates. Only provided fields will be updated.

  • Successful response (200 OK):

     {
      "message": "Job details updated successfully",
      "status_code": 200,
      "data": {
        "title": "Software Engineer",
        "description": "Responsible for developing and maintaining web applications.",
        "location": "New York, NY",
        "deadline": "2024-12-31T23:59:59Z",
        "salary_range": "30k_to_50k",
        "job_type": "full-time",
        "job_mode": "remote",
        "company_name": "Tech Corp",
        "is_deleted": false
      }
    }
  • Error response (400 Bad Request):

    {
      "status_code": 400,
      "message": ["validation error message"],
      "error": "Bad Request"
    }

Testing

  • Added unit tests for JobsService update method
  • Tested successful update scenario
  • Tested error handling for non-existent jobs

Checklist

  • Implemented PATCH endpoint at api/v1/jobs/:id
  • Added authentication and authorization checks
  • Implemented input validation
  • Updated JobsService with update method
  • Added error handling for non-existent jobs
  • Implemented unit tests
  • Ensured compliance with security standards

Related Issues

Closes #158

@alexindevs alexindevs requested a review from Heba-WebDev August 5, 2024 21:54
@Heba-WebDev
Copy link
Contributor

Please update the title, all small letters

@alexindevs alexindevs changed the title feat: Update Job Listing Feature feat: update job listing feature Aug 5, 2024
Comment on lines +58 to +60
async update(@Param('id') id: string, @Body() updateJobDto: Partial<JobDto>) {
return this.jobService.update(id, updateJobDto);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async update(@Param('id') id: string, @Body() updateJobDto: Partial<JobDto>) {
return this.jobService.update(id, updateJobDto);
}
async updateJobById(@Param('id') id: string, @Body() updateJobDto: Partial<JobDto>) {
return this.jobService.updateJobById(id, updateJobDto);
}

@@ -69,6 +69,27 @@ export class JobsService {
data: job,
};
}

async update(id: string, updateJobDto: Partial<JobDto>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async update(id: string, updateJobDto: Partial<JobDto>) {
async updateJobById(id: string, updateJobDto: Partial<JobDto>) {

@@ -48,4 +48,14 @@ export class JobsController {
async delete(@Param('id') id: string) {
return this.jobService.delete(id);
}

@UseGuards(JobGuard)
@Patch('/:id')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the forward slash

@ApiResponse({ status: 200, description: 'Job updated successfully' })
@ApiResponse({ status: 403, description: 'You do not have permission to perform this action' })
@ApiResponse({ status: 404, description: 'Job not found' })
async update(@Param('id') id: string, @Body() updateJobDto: Partial<JobDto>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add UUID validation pipe to ensure id is of type UUID string.

async update(id: string, updateJobDto: Partial<JobDto>) {
const job = await this.jobRepository.findOne({ where: { id } });
if (!job) {
throw new NotFoundException({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use provided custom http exception handler

throw new NotFoundException({
status_code: 404,
status: 'Not found Exception',
message: 'Job not found',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use constants where possible. This makes code cleaner and maintainable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] Update A job post by Id
4 participants