-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Tusharmahajan12/new_feb27
Issue #236101 Application status CRUD api created and updated code
- Loading branch information
Showing
7 changed files
with
248 additions
and
18 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/modules/application_statuses/application-statuses.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Post, | ||
Body, | ||
Param, | ||
Patch, | ||
Delete, | ||
Res, | ||
} from "@nestjs/common"; | ||
import { ApplicationStatusesService } from "./application-statuses.service"; | ||
import { CreateApplicationStatusDto } from "./dto/create-application-status.dto"; | ||
import { UpdateApplicationStatusDto } from "./dto/update-application-status.dto"; | ||
|
||
@Controller("application-statuses") | ||
export class ApplicationStatusesController { | ||
constructor(private readonly service: ApplicationStatusesService) {} | ||
|
||
@Post() | ||
create(@Body() createDto: CreateApplicationStatusDto, @Res() res: any) { | ||
return this.service.create(createDto, res); | ||
} | ||
|
||
@Get() | ||
findAll(@Res() res: any) { | ||
return this.service.findAll(res); | ||
} | ||
|
||
@Get(":id") | ||
findOne(@Param("id") id: string,res: any) { | ||
return this.service.findOne(id,res); | ||
} | ||
|
||
@Patch(":id") | ||
update( | ||
@Param("id") id: string, | ||
@Body() updateDto: UpdateApplicationStatusDto, | ||
res: any | ||
) { | ||
return this.service.update(id, updateDto,res); | ||
} | ||
|
||
@Delete(":id") | ||
remove(@Param("id") id: string,res: any) { | ||
return this.service.remove(id,res); | ||
} | ||
} |
166 changes: 166 additions & 0 deletions
166
src/modules/application_statuses/application-statuses.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { Injectable, HttpStatus } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { ApplicationStatus } from './entities/application_status.entity'; | ||
import { CreateApplicationStatusDto } from './dto/create-application-status.dto'; | ||
import { UpdateApplicationStatusDto } from './dto/update-application-status.dto'; | ||
import APIResponse from 'modules/common/responses/response'; | ||
|
||
@Injectable() | ||
export class ApplicationStatusesService { | ||
constructor( | ||
@InjectRepository(ApplicationStatus) | ||
private readonly applicationStatusRepository: Repository<ApplicationStatus> | ||
) {} | ||
|
||
async create(createDto: CreateApplicationStatusDto, res: any): Promise<any> { | ||
try { | ||
const newStatus = this.applicationStatusRepository.create(createDto); | ||
const savedStatus = await this.applicationStatusRepository.save( | ||
newStatus | ||
); | ||
return APIResponse.success( | ||
res, | ||
'Application Status created successfully', | ||
savedStatus, | ||
HttpStatus.OK, | ||
'New Application Status Added' | ||
); | ||
} catch (error) { | ||
return APIResponse.error( | ||
res, | ||
'Failed to create Application Status', | ||
'ERROR_CREATE_APPLICATION_STATUS', | ||
'Error Creating Application Status', | ||
HttpStatus.INTERNAL_SERVER_ERROR | ||
); | ||
} | ||
} | ||
|
||
async findAll(res: any): Promise<any> { | ||
try { | ||
const savedStatus = await this.applicationStatusRepository.find(); | ||
return APIResponse.success( | ||
res, | ||
'Application Status created successfully', | ||
savedStatus, | ||
HttpStatus.OK, | ||
'New Application Status Added' | ||
); | ||
} catch (error) { | ||
return APIResponse.error( | ||
res, | ||
'Failed to retrieve Application Statuses', | ||
'ERROR_FETCH_APPLICATION_STATUSES', | ||
'Error Fetching Application Statuses', | ||
HttpStatus.INTERNAL_SERVER_ERROR | ||
); | ||
} | ||
} | ||
|
||
async findOne(id: string, res: any): Promise<any> { | ||
try { | ||
const status = await this.applicationStatusRepository.findOne({ | ||
where: { id }, | ||
}); | ||
if (!status) { | ||
return APIResponse.error( | ||
res, | ||
`Application status with ID ${id} not found`, | ||
'ERROR_FETCH_APPLICATION_STATUS', | ||
'Error Fetching Application Status', | ||
HttpStatus.NOT_FOUND | ||
); | ||
} | ||
|
||
return APIResponse.success( | ||
res, | ||
'Application Status created successfully', | ||
status, | ||
HttpStatus.OK, | ||
'New Application Status Added' | ||
); | ||
} catch (error) { | ||
return APIResponse.error( | ||
res, | ||
`Application status with ID ${id} not found`, | ||
'ERROR_FETCH_APPLICATION_STATUS', | ||
'Error Fetching Application Status', | ||
HttpStatus.NOT_FOUND | ||
); | ||
} | ||
} | ||
|
||
async update( | ||
id: string, | ||
updateDto: UpdateApplicationStatusDto, | ||
res: any | ||
): Promise<any> { | ||
try { | ||
const existingStatus = await this.findOne(id, res); // Check if exists | ||
|
||
if (!existingStatus) { | ||
return APIResponse.error( | ||
res, | ||
`Application status with ID ${id} not found`, | ||
'ERROR_UPDATE_APPLICATION_STATUS', | ||
'Error Updating Application Status', | ||
HttpStatus.NOT_FOUND | ||
); | ||
} | ||
|
||
await this.applicationStatusRepository.update(id, updateDto); | ||
const updatedStatus = await this.findOne(id, res); // Fetch updated record | ||
|
||
return APIResponse.success( | ||
res, | ||
'Application Status updated successfully', | ||
updatedStatus, | ||
HttpStatus.OK, | ||
'Application Status Updated' | ||
); | ||
} catch (error) { | ||
return APIResponse.error( | ||
res, | ||
'An error occurred while updating application status', | ||
'ERROR_UPDATE_APPLICATION_STATUS', | ||
'Error Updating Application Status', | ||
HttpStatus.INTERNAL_SERVER_ERROR | ||
); | ||
} | ||
} | ||
|
||
async remove(id: string, res: any): Promise<any> { | ||
try { | ||
const existingStatus = await this.findOne(id, res); // Check if it exists | ||
|
||
if (!existingStatus) { | ||
return APIResponse.error( | ||
res, | ||
`Application status with ID ${id} not found`, | ||
'ERROR_DELETE_APPLICATION_STATUS', | ||
'Error Deleting Application Status', | ||
HttpStatus.NOT_FOUND | ||
); | ||
} | ||
|
||
await this.applicationStatusRepository.delete(id); | ||
|
||
return APIResponse.success( | ||
res, | ||
'Application Status deleted successfully', | ||
null, | ||
HttpStatus.OK, | ||
'Application Status Deleted' | ||
); | ||
} catch (error) { | ||
return APIResponse.error( | ||
res, | ||
'An error occurred while deleting application status', | ||
'ERROR_DELETE_APPLICATION_STATUS', | ||
'Error Deleting Application Status', | ||
HttpStatus.INTERNAL_SERVER_ERROR | ||
); | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/modules/application_statuses/application_statuses.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { ApplicationStatus } from './entities/application_status.entity'; | ||
import { ApplicationStatusesService } from './application-statuses.service'; | ||
import { ApplicationStatusesController } from './application-statuses.controller'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([ApplicationStatus])], | ||
providers: [ApplicationStatusesService], | ||
controllers: [ApplicationStatusesController], | ||
exports: [TypeOrmModule], | ||
}) | ||
export class ApplicationStatusesModule {} |
7 changes: 7 additions & 0 deletions
7
src/modules/application_statuses/dto/create-application-status.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { IsNotEmpty, IsString } from "class-validator"; | ||
|
||
export class CreateApplicationStatusDto { | ||
@IsNotEmpty() | ||
@IsString() | ||
status?: string; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/modules/application_statuses/dto/update-application-status.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { PartialType } from "@nestjs/mapped-types"; | ||
import { CreateApplicationStatusDto } from "./create-application-status.dto"; | ||
|
||
export class UpdateApplicationStatusDto extends PartialType( | ||
CreateApplicationStatusDto | ||
) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters