-
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
0 parents
commit ab73892
Showing
76 changed files
with
11,497 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: 'tsconfig.json', | ||
tsconfigRootDir: __dirname, | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint/eslint-plugin', 'import'], | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:prettier/recommended', | ||
], | ||
root: true, | ||
env: { | ||
node: true, | ||
jest: true, | ||
}, | ||
ignorePatterns: ['.eslintrc.js'], | ||
rules: { | ||
'@typescript-eslint/interface-name-prefix': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/explicit-module-boundary-types': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'import/order': [ | ||
'error', | ||
{ | ||
groups: ['builtin', 'external', 'internal', 'parent', 'sibling'], | ||
pathGroups: [ | ||
{ | ||
pattern: '@nestjs/**', | ||
group: 'external', | ||
position: 'before', | ||
}, | ||
], | ||
'newlines-between': 'always', | ||
pathGroupsExcludedImportTypes: ['builtin'], | ||
alphabetize: { | ||
order: 'asc', | ||
caseInsensitive: true, | ||
}, | ||
}, | ||
], | ||
'import/newline-after-import': ['error', { count: 1 }], | ||
}, | ||
}; |
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,2 @@ | ||
|
||
* text=auto eol=lf |
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,58 @@ | ||
# compiled output | ||
/dist | ||
/node_modules | ||
/build | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
pnpm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# OS | ||
.DS_Store | ||
|
||
# Tests | ||
/coverage | ||
/.nyc_output | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
|
||
# IDE - VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# temp directory | ||
.temp | ||
.tmp | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
my-docs.md |
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,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
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 @@ | ||
{ | ||
"cSpell.words": ["dtos"], | ||
"workbench.editor.customLabels.patterns": { | ||
"**/app/**/page.tsx": "PAGE: ${dirname}", | ||
"**/libs/contracts/src/**/*.ts": "Lib contracts ${filename}", | ||
"**/apps/api-gateway/src/**/*.controller.ts": "GATEWAY ${dirname} Module Controller", | ||
"**/apps/api-gateway/src/**/*.service.ts": " GATEWAY ${dirname} Module Service", | ||
"**/apps/api-gateway/src/app.module.ts": "GATEWAY App Module", | ||
"**/apps/api-gateway/src/main.ts": "Gateway Main Entry", | ||
"**/apps/api-gateway/src/**/*.module.ts": "GATEWAY ${dirname} Module", | ||
"**/apps/*/src/*/*.service.ts": "MICRO APP ${dirname} Service", | ||
"**/apps/*/src/*/*.controller.ts": "MICRO APP ${dirname} Controller", | ||
"**/apps/*/src/*/*.module.ts ": "MICRO APP ${dirname} Module", | ||
"**/apps/*/src/main.ts": "MICRO APP ${dirname(1)} Main Entry", | ||
" **/apps/*/src/*-app.module.ts": "MICRO APP ${dirname(1)} app module", | ||
"**/apps/*/src/*/*repository.ts": "MICRO APP ${dirname} Repository", | ||
"**/libs/contracts/src/*/index.ts": " Lib ${dirname} contracts ", | ||
"**/libs/common/DB/src/repositories/*repository.ts": "Lib common ${dirname(2)} Module Repository", | ||
"**/libs/common/*/src/schemas/*schema.ts": "Lib common ${dirname(2)} ${filename} Schema", | ||
"**/libs/common/*/src/*module.ts": "Lib common ${dirname(1)} Module" | ||
} | ||
} |
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 @@ | ||
### Create an .env file in the | ||
`libs/common/DB/.env` | ||
``` | ||
DATABASE_PASSWORD= | ||
DATABASE_NAME= | ||
DATABASE_USER= | ||
MONGODB_URL= | ||
``` |
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,10 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { ClientConfigModule } from './client-config'; | ||
import { PropertiesModule } from './properties/properties.module'; | ||
import { UsersModule } from './users/users.module'; | ||
|
||
@Module({ | ||
imports: [UsersModule, PropertiesModule, ClientConfigModule], | ||
}) | ||
export class AppModule {} |
20 changes: 20 additions & 0 deletions
20
apps/api-gateway/src/client-config/client-config.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
|
||
import * as Joi from 'joi'; | ||
|
||
import { ClientConfigService } from './client-config.service'; | ||
|
||
@Module({ | ||
imports: [ | ||
ConfigModule.forRoot({ | ||
validationSchema: Joi.object({ | ||
USERS_CLIENT_PORT: Joi.number().default(3001), | ||
PROPERTIES_CLIENT_PORT: Joi.number().default(3002), | ||
}), | ||
}), | ||
], | ||
providers: [ClientConfigService], | ||
exports: [ClientConfigService], | ||
}) | ||
export class ClientConfigModule {} |
30 changes: 30 additions & 0 deletions
30
apps/api-gateway/src/client-config/client-config.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,30 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { ClientOptions, Transport } from '@nestjs/microservices'; | ||
|
||
@Injectable() | ||
export class ClientConfigService { | ||
constructor(private configService: ConfigService) {} | ||
getPropertiesClientPort() { | ||
return this.configService.get<number>('PROPERTIES_CLIENT_PORT'); | ||
} | ||
getUsersClientPort() { | ||
return this.configService.get<number>('USERS_CLIENT_PORT'); | ||
} | ||
getPropertiesClientOptions(): ClientOptions { | ||
return { | ||
transport: Transport.TCP, | ||
options: { | ||
port: this.getPropertiesClientPort(), | ||
}, | ||
}; | ||
} | ||
getUsersClientOptions(): ClientOptions { | ||
return { | ||
transport: Transport.TCP, | ||
options: { | ||
port: this.getUsersClientPort(), | ||
}, | ||
}; | ||
} | ||
} |
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,2 @@ | ||
export * from './client-config.module'; | ||
export * from './client-config.service'; |
18 changes: 18 additions & 0 deletions
18
apps/api-gateway/src/common/filters/rpc-exception.filter.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,18 @@ | ||
import { Catch, RpcExceptionFilter, ArgumentsHost } from '@nestjs/common'; | ||
import { RpcException } from '@nestjs/microservices'; | ||
|
||
import { Observable, throwError } from 'rxjs'; | ||
|
||
@Catch(RpcException) | ||
export class RPCExceptionFilter implements RpcExceptionFilter<RpcException> { | ||
catch(exception: RpcException, host: ArgumentsHost): Observable<any> { | ||
const response = host.switchToHttp().getResponse(); | ||
console.log(response); | ||
const status = 500; | ||
|
||
return throwError(() => ({ | ||
statusCode: status, | ||
message: exception.message || 'Internal Server Error', | ||
})); | ||
} | ||
} |
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,10 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
|
||
import { AppModule } from './app.module'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
|
||
await app.listen(3000); | ||
} | ||
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 @@ | ||
export const PROPERTIES_CLIENT = Symbol('PROPERTIES_CLIENT'); |
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 @@ | ||
export class CreatePropertyDto { | ||
name: string; | ||
description: string; | ||
price: number; | ||
bedrooms: number; | ||
bathrooms: number; | ||
} |
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,4 @@ | ||
export class PropertyDto { | ||
id: number; | ||
description: 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { PartialType } from '@nestjs/mapped-types'; | ||
|
||
import { CreatePropertyDto } from './create-property.dto'; | ||
|
||
export class UpdatePropertyDto extends PartialType(CreatePropertyDto) {} |
21 changes: 21 additions & 0 deletions
21
apps/api-gateway/src/properties/properties.controller.spec.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,21 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
|
||
import { PropertiesController } from './properties.controller'; | ||
import { PropertiesService } from './properties.service'; | ||
|
||
describe('PropertiesController', () => { | ||
let controller: PropertiesController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [PropertiesController], | ||
providers: [PropertiesService], | ||
}).compile(); | ||
|
||
controller = module.get<PropertiesController>(PropertiesController); | ||
}); | ||
|
||
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,46 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Post, | ||
Body, | ||
Patch, | ||
Param, | ||
Delete, | ||
} from '@nestjs/common'; | ||
|
||
import { CreatePropertyDto } from './dtos/create-property.dto'; | ||
import { UpdatePropertyDto } from './dtos/update-property.dto'; | ||
import { PropertiesService } from './properties.service'; | ||
|
||
@Controller('properties') | ||
export class PropertiesController { | ||
constructor(private readonly propertiesService: PropertiesService) {} | ||
|
||
@Post() | ||
create(@Body() createPropertyDto: CreatePropertyDto) { | ||
return this.propertiesService.create(createPropertyDto); | ||
} | ||
|
||
@Get() | ||
findAll() { | ||
return this.propertiesService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
findOne(@Param('id') id: string) { | ||
return this.propertiesService.findOne(+id); | ||
} | ||
|
||
@Patch(':id') | ||
update( | ||
@Param('id') id: string, | ||
@Body() updatePropertyDto: UpdatePropertyDto, | ||
) { | ||
return this.propertiesService.update(+id, updatePropertyDto); | ||
} | ||
|
||
@Delete(':id') | ||
remove(@Param('id') id: string) { | ||
return this.propertiesService.remove(+id); | ||
} | ||
} |
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 { Module } from '@nestjs/common'; | ||
import { ClientsModule } from '@nestjs/microservices'; | ||
|
||
import { ClientConfigModule } from '../client-config'; | ||
import { ClientConfigService } from '../client-config'; | ||
|
||
import { PROPERTIES_CLIENT } from './constants'; | ||
import { PropertiesController } from './properties.controller'; | ||
import { PropertiesService } from './properties.service'; | ||
|
||
@Module({ | ||
imports: [ | ||
ClientConfigModule, | ||
ClientsModule.registerAsync([ | ||
{ | ||
name: PROPERTIES_CLIENT, | ||
imports: [ClientConfigModule], | ||
useFactory: async (configService: ClientConfigService) => { | ||
return { | ||
...configService.getPropertiesClientOptions(), | ||
}; | ||
}, | ||
inject: [ClientConfigService], | ||
}, | ||
]), | ||
], | ||
controllers: [PropertiesController], | ||
providers: [PropertiesService], | ||
}) | ||
export class PropertiesModule {} |
19 changes: 19 additions & 0 deletions
19
apps/api-gateway/src/properties/properties.service.spec.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,19 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
|
||
import { PropertiesService } from './properties.service'; | ||
|
||
describe('PropertiesService', () => { | ||
let service: PropertiesService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [PropertiesService], | ||
}).compile(); | ||
|
||
service = module.get<PropertiesService>(PropertiesService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
Oops, something went wrong.