-
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
942f478
commit b360a8d
Showing
23 changed files
with
510 additions
and
77 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
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,22 @@ | ||
import { Controller, Get, Query } from '@nestjs/common'; | ||
import { ApiOkResponse, ApiQuery, ApiTags } from '@nestjs/swagger'; | ||
import { JobEntity } from './job.entity'; | ||
import { JobsService } from './jobs.service'; | ||
|
||
@ApiTags('jobs') | ||
@Controller('jobs') | ||
export class JobsController { | ||
constructor(private readonly jobsService: JobsService) {} | ||
|
||
@ApiOkResponse({ type: JobEntity, isArray: true }) | ||
@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,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { PrismaService } from 'src/database/connection.service'; | ||
import { SearchModule } from '../search/search.module'; | ||
import { JobsController } from './jobs.controller'; | ||
import { JobsService } from './jobs.service'; | ||
|
||
@Module({ | ||
imports: [SearchModule], | ||
controllers: [JobsController], | ||
providers: [JobsService, PrismaService], | ||
}) | ||
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,26 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Job } from '@prisma/client'; | ||
import { PrismaService } from 'src/database/connection.service'; | ||
import { SearchService } from '../search/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(); | ||
await this.searchService.addDocuments(jobs); | ||
|
||
if (search) { | ||
const results = await this.searchService.search(search); | ||
jobs = results.hits.map((hit) => hit._formatted as Job); | ||
} | ||
|
||
return jobs; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { SearchService } from './search.service'; | ||
|
||
@Module({ | ||
providers: [SearchService], | ||
exports: [SearchService] | ||
}) | ||
export class SearchModule {} |
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,44 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Job } from '@prisma/client'; | ||
import { EnqueuedTask, Index, MeiliSearch, SearchResponse } from 'meilisearch'; | ||
|
||
@Injectable() | ||
export class SearchService { | ||
private SearchClient: MeiliSearch; | ||
|
||
constructor() { | ||
this.SearchClient = new MeiliSearch({ | ||
host: 'http://meilisearch:7700', | ||
}) | ||
|
||
this.SearchClient.createIndex('jobs', { primaryKey: 'id'}) | ||
} | ||
|
||
private getIndex(): Index { | ||
return this.SearchClient.index('jobs'); | ||
} | ||
|
||
async addDocuments(docs: Job[]): Promise<EnqueuedTask> { | ||
const index = this.getIndex(); | ||
|
||
try { | ||
return await index.addDocuments(docs); | ||
} catch(e) { | ||
console.log('Error adding documents'); | ||
throw e; | ||
} | ||
} | ||
|
||
async search(query: string): Promise<SearchResponse> { | ||
const index = this.getIndex(); | ||
|
||
return await index.searchGet( | ||
query, | ||
{ | ||
attributesToHighlight: ['title'], | ||
attributesToSearchOn: ['title'], | ||
attributesToRetrieve: ['*'], | ||
} | ||
); | ||
} | ||
} |
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,14 @@ | ||
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 { SearchModule } from './api/search/search.module'; | ||
import { SearchService } from './api/search/search.service'; | ||
import { DatabaseModule } from './database/database.module'; | ||
import { SampleController } from './api/sample/sample.controller'; | ||
|
||
@Module({ | ||
imports: [DatabaseModule], | ||
controllers: [SampleController], | ||
providers: [], | ||
imports: [DatabaseModule, JobsModule, SearchModule], | ||
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,16 @@ | ||
import { faker } from '@faker-js/faker'; | ||
|
||
const customers = []; | ||
|
||
for (let i = 0; i < 20; i ++) { | ||
customers.push({ | ||
id: i + 1, | ||
firstName: faker.person.firstName(), | ||
lastName: faker.person.lastName(), | ||
email: faker.internet.email(), | ||
contact: faker.phone.number('+63 9# ### ## ##'), | ||
address: faker.location.streetAddress(true) | ||
}) | ||
} | ||
|
||
export { customers }; |
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,19 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { PaymentMethod } from '@prisma/client'; | ||
|
||
const jobs = []; | ||
const paymentMethod = Object.values(PaymentMethod); | ||
|
||
for (let i = 0; i < 20; i ++) { | ||
const j = i + 1; | ||
jobs.push({ | ||
id: j, | ||
title: faker.lorem.words(), | ||
type: faker.lorem.word(), | ||
personInChargeId: faker.number.int({ min: 1, max: 10 }), | ||
customerId: j, | ||
paymentMethod: faker.helpers.arrayElement(paymentMethod) | ||
}) | ||
} | ||
|
||
export { 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { faker } from '@faker-js/faker'; | ||
|
||
const users = []; | ||
|
||
for (let i = 0; i < 10; i ++) { | ||
users.push({ | ||
id: i + 1, | ||
firstName: faker.person.firstName(), | ||
lastName: faker.person.lastName(), | ||
email: faker.internet.email(), | ||
}) | ||
} | ||
|
||
export { users }; |
Oops, something went wrong.