-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6454a9a
commit d49b988
Showing
20 changed files
with
1,034 additions
and
371 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { OmitType } from "@nestjs/swagger"; | ||
import { IsString } from "class-validator"; | ||
import { UserDto } from "../../user/dtos/user.dto"; | ||
import { Exclude, Expose } from "class-transformer"; | ||
|
||
export class PersonInChargeDto extends OmitType(UserDto, [ | ||
"createdAt", | ||
"updatedAt", | ||
]) { | ||
@Exclude() | ||
createdAt: Date; | ||
|
||
@Exclude() | ||
updatedAt: Date; | ||
|
||
@Expose() | ||
@IsString() | ||
get fullname(): string | undefined { | ||
return `${this.firstName} ${this.lastName}`; | ||
} | ||
|
||
constructor(partial: Partial<PersonInChargeDto>) { | ||
super(); | ||
Object.assign(this, partial); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,87 @@ | ||
import { Job } from '@prisma/client'; | ||
import { ApiTags } from '@nestjs/swagger'; | ||
import { BadRequestException, Body, Controller, Get, NotFoundException, Param, ParseIntPipe, Post, UsePipes, ValidationPipe } from '@nestjs/common'; | ||
import { Job } from "@prisma/client"; | ||
import { ApiTags } from "@nestjs/swagger"; | ||
import { | ||
BadRequestException, | ||
Body, | ||
ClassSerializerInterceptor, | ||
Controller, | ||
Get, | ||
NotFoundException, | ||
Param, | ||
ParseIntPipe, | ||
Post, | ||
UseInterceptors, | ||
UsePipes, | ||
ValidationPipe, | ||
} from "@nestjs/common"; | ||
|
||
import { JobService } from './job.service'; | ||
import { JobService } from "./job.service"; | ||
|
||
import { CreateJobWithCustomerAndSchedulesDto } from './dtos/create-job-with-customer-and-schedule.dto'; | ||
import { CreateJobWithCustomerAndSchedulesDto } from "./dtos/create-job-with-customer-and-schedule.dto"; | ||
import { PersonInChargeDto } from "./dtos/person-in-charge.dto"; | ||
|
||
@ApiTags('job') | ||
@Controller('job') | ||
@ApiTags("job") | ||
@Controller("job") | ||
export class JobController { | ||
constructor( | ||
private readonly jobService: JobService | ||
) { } | ||
|
||
@Post() | ||
@UsePipes(new ValidationPipe()) | ||
async create(@Body() options: CreateJobWithCustomerAndSchedulesDto): Promise<Job> { | ||
const job = await this.jobService.createJobWithCustomerAndSchedules(options); | ||
|
||
if (!job ) { | ||
throw new BadRequestException("Something went wrong. Job not created.") | ||
} | ||
|
||
return job; | ||
constructor(private readonly jobService: JobService) {} | ||
|
||
@Get("types") | ||
async findAllTypes(): Promise<string[]> { | ||
const types = await this.jobService.findAllTypes(); | ||
|
||
if (types.length === 0) { | ||
throw new NotFoundException("No job types found."); | ||
} | ||
|
||
@Get() | ||
async findAll(): Promise<Job[]> { | ||
const jobs = await this.jobService.findAll() | ||
return types; | ||
} | ||
|
||
@Get("personInCharge") | ||
@UseInterceptors(ClassSerializerInterceptor) | ||
async findAllPersonInCharge(): Promise<PersonInChargeDto[]> { | ||
const person = await this.jobService.findAllPersonInCharge(); | ||
|
||
if (jobs == 0) { | ||
throw new NotFoundException("No job found.") | ||
} | ||
return jobs | ||
if (person.length === 0) { | ||
throw new NotFoundException("No person in charge found."); | ||
} | ||
|
||
@Get('/:id') | ||
async findOne(@Param('id', ParseIntPipe) id: number): Promise<Job> { | ||
const job = await this.jobService.findOne({ id }) | ||
return person.map((person) => new PersonInChargeDto({ ...person })); | ||
} | ||
|
||
if (!job) { | ||
throw new NotFoundException("No job found.") | ||
} | ||
@Post() | ||
@UsePipes(new ValidationPipe()) | ||
async create( | ||
@Body() options: CreateJobWithCustomerAndSchedulesDto, | ||
): Promise<Job> { | ||
const job = await this.jobService.createJobWithCustomerAndSchedules( | ||
options, | ||
); | ||
|
||
return job | ||
if (!job) { | ||
throw new BadRequestException("Something went wrong. Job not created."); | ||
} | ||
|
||
return job; | ||
} | ||
|
||
@Get() | ||
async findAll(): Promise<Job[]> { | ||
const jobs = await this.jobService.findAll(); | ||
|
||
if (jobs == 0) { | ||
throw new NotFoundException("No job found."); | ||
} | ||
return jobs; | ||
} | ||
|
||
@Get("/:id") | ||
async findOne(@Param("id", ParseIntPipe) id: number): Promise<Job> { | ||
const job = await this.jobService.findOne({ id }); | ||
|
||
if (!job) { | ||
throw new NotFoundException("No job found."); | ||
} | ||
|
||
return job; | ||
} | ||
} |
Oops, something went wrong.