-
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.
setup swagger, seeder and GET endpoint
- Loading branch information
1 parent
942f478
commit 0a25300
Showing
22 changed files
with
692 additions
and
38 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,5 @@ | ||
import { PartialType } from '@nestjs/mapped-types'; | ||
|
||
export class CreateJobDto {} | ||
|
||
export class UpdateJobDto extends PartialType(CreateJobDto) {} |
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,37 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { Job, PaymentMethod, Schedule, Tag } from '@prisma/client'; | ||
|
||
export class JobEntity implements Job { | ||
@ApiProperty() | ||
id: number; | ||
|
||
@ApiProperty() | ||
title: string; | ||
|
||
@ApiProperty() | ||
type: string; | ||
|
||
@ApiProperty({ nullable: true }) | ||
remarks: string; | ||
|
||
@ApiProperty() | ||
personInChargeId: number; | ||
|
||
@ApiProperty() | ||
customerId: number; | ||
|
||
@ApiProperty() | ||
paymentMethod: PaymentMethod; | ||
|
||
@ApiProperty({ nullable: true }) | ||
tags: Tag[] | ||
|
||
@ApiProperty({ nullable: true }) | ||
schedules: Schedule[] | ||
|
||
@ApiProperty() | ||
createdAt: Date; | ||
|
||
@ApiProperty() | ||
updatedAt: Date; | ||
} |
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,20 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { JobsController } from './jobs.controller'; | ||
import { JobsService } from './jobs.service'; | ||
|
||
describe('JobsController', () => { | ||
let controller: JobsController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [JobsController], | ||
providers: [JobsService], | ||
}).compile(); | ||
|
||
controller = module.get<JobsController>(JobsController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
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,20 @@ | ||
import { Controller, Get, Query } from '@nestjs/common'; | ||
import { ApiQuery, ApiTags } from '@nestjs/swagger'; | ||
import { JobsService } from './jobs.service'; | ||
|
||
@ApiTags('jobs') | ||
@Controller('jobs') | ||
export class JobsController { | ||
constructor(private readonly jobsService: JobsService) {} | ||
|
||
@ApiQuery({ | ||
name: 'search', | ||
required: false, | ||
type: String, | ||
description: "Optional search keyword" | ||
}) | ||
@Get() | ||
async findAll(@Query('search') search: string) { | ||
return await this.jobsService.findAll(search); | ||
} | ||
} |
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,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { PrismaService } from 'src/database/connection.service'; | ||
import { SearchService } from 'src/services/externalService/search.service'; | ||
import { JobsController } from './jobs.controller'; | ||
import { JobsService } from './jobs.service'; | ||
|
||
@Module({ | ||
controllers: [JobsController], | ||
providers: [JobsService, PrismaService, SearchService], | ||
}) | ||
export class JobsModule {} |
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,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { JobsService } from './jobs.service'; | ||
|
||
describe('JobsService', () => { | ||
let service: JobsService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [JobsService], | ||
}).compile(); | ||
|
||
service = module.get<JobsService>(JobsService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
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,30 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Job } from '@prisma/client'; | ||
import { PrismaService } from 'src/database/connection.service'; | ||
import { SearchService } from 'src/services/externalService/search.service'; | ||
|
||
@Injectable() | ||
export class JobsService { | ||
constructor( | ||
private prisma: PrismaService, | ||
private searchService: SearchService | ||
){} | ||
|
||
async findAll(search?: string): Promise<Job[] | null> { | ||
let jobs: Job[] = []; | ||
|
||
jobs = await this.prisma.job.findMany(); | ||
|
||
if (search) { | ||
await this.searchService.addDocuments(jobs); | ||
const results = await this.searchService.search(search); | ||
|
||
console.log(results); | ||
|
||
const jobIds = results.hits.map(hit => parseInt(hit.id)); | ||
jobs = jobs.filter(job => jobIds.includes(job.id)); | ||
} | ||
|
||
return jobs; | ||
} | ||
} |
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,7 +1,7 @@ | ||
import { SampleUser } from '@prisma/client'; | ||
// import { SampleUser } from '@prisma/client'; | ||
|
||
export class SampleUserEntity implements SampleUser { | ||
id: number; | ||
name: string; | ||
email: string; | ||
} | ||
// export class SampleUserEntity implements SampleUser { | ||
// id: number; | ||
// name: string; | ||
// email: string; | ||
// } |
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,10 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { JobsController } from './api/jobs/jobs.controller'; | ||
import { JobsModule } from './api/jobs/jobs.module'; | ||
import { JobsService } from './api/jobs/jobs.service'; | ||
import { DatabaseModule } from './database/database.module'; | ||
import { SampleController } from './api/sample/sample.controller'; | ||
import { SearchService } from './services/externalService/search.service'; | ||
|
||
@Module({ | ||
imports: [DatabaseModule], | ||
controllers: [SampleController], | ||
providers: [], | ||
imports: [DatabaseModule, JobsModule], | ||
controllers: [JobsController], | ||
providers: [JobsService, SearchService], | ||
}) | ||
export class AppModule {} |
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,8 +1,19 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; | ||
import { AppModule } from './app.module'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
|
||
const config = new DocumentBuilder() | ||
.setTitle('Sim-JMS') | ||
.setDescription('This is the API documentation for sim-jms') | ||
.setVersion('1.0') | ||
.build(); | ||
|
||
const document = SwaggerModule.createDocument(app, config); | ||
SwaggerModule.setup('api', app, document); | ||
|
||
await app.listen(4000); | ||
} | ||
bootstrap(); |
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,82 @@ | ||
export const customers = [ | ||
{ | ||
id: 1, | ||
firstName: "John", | ||
lastName: "Doe", | ||
email: "johndoe@gmail.com", | ||
contact: "+639876543210", | ||
address: "8741 VonRueden Highway, West Virginia", | ||
}, | ||
{ | ||
id: 2, | ||
firstName: "Jane", | ||
lastName: "Smith", | ||
email: "janesmith@gmail.com", | ||
contact: "+630123546788", | ||
address: "King Apt 906, Tennessee", | ||
}, | ||
{ | ||
id: 3, | ||
firstName: "Michael", | ||
lastName: "Smith", | ||
email: "michaelsmith@gmail.com", | ||
contact: "+63444543210", | ||
address: "986 Senger Drive, Lake Aliza", | ||
}, | ||
{ | ||
id: 4, | ||
firstName: "Ana", | ||
lastName: "Rogers", | ||
email: "anarogers@gmail.com", | ||
contact: "+639277543210", | ||
address: "580 Stroman Heights, Davismouth", | ||
}, | ||
{ | ||
id: 5, | ||
firstName: "Kelly", | ||
lastName: "Nier", | ||
email: "kellynier@gmail.com", | ||
contact: "+639123746890", | ||
address: "55934 Veronica Knoll, South Dakota", | ||
}, | ||
{ | ||
id: 6, | ||
firstName: "Curtis", | ||
lastName: "Hegmann", | ||
email: "curtishegmann@gmail.com", | ||
contact: "+639277543321", | ||
address: "123 Murray Village, Nebraska", | ||
}, | ||
{ | ||
id: 7, | ||
firstName: "Hassan", | ||
lastName: "Connel", | ||
email: "hassanconnel@gmail.com", | ||
contact: "+639274343321", | ||
address: "389 Larkin Circle, Abbotport", | ||
}, | ||
{ | ||
id: 8, | ||
firstName: "Ray", | ||
lastName: "Summers", | ||
email: "raysummers@gmail.com", | ||
contact: "+639200343321", | ||
address: "5327 Constance Harbors, West Marina", | ||
}, | ||
{ | ||
id: 9, | ||
firstName: "Alice", | ||
lastName: "Hills", | ||
email: "alicehills@gmail.com", | ||
contact: "+63231567891", | ||
address: "544 Bertrand Row, Kansas", | ||
}, | ||
{ | ||
id: 10, | ||
firstName: "Sheila", | ||
lastName: "Comb", | ||
email: "sheilacomb@gmail.com", | ||
contact: "+63231567800", | ||
address: "2029 Kuhlman Expressway, West Virginia", | ||
}, | ||
] |
Oops, something went wrong.