-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
54 changed files
with
2,099 additions
and
64 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 @@ | ||
{ | ||
"language": "ts", | ||
"collection": "@nestjs/schematics", | ||
"sourceRoot": "src" | ||
} |
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 @@ | ||
{ | ||
"watch": ["apps/mc-mock-server/src"], | ||
"ext": "ts", | ||
"ignore": ["src/**/*.spec.ts"], | ||
"exec": "node --inspect-brk -r tsconfig-paths/register apps/mc-mocks-server/src/main.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,5 @@ | ||
{ | ||
"watch": ["dist"], | ||
"ext": "js", | ||
"exec": "node dist/main" | ||
} |
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 @@ | ||
{ | ||
"name": "@mc/mocks-server", | ||
"version": "0.0.0-PLACEHOLDER", | ||
"description": "MC Mocks Server", | ||
"keywords": [ | ||
"angular", | ||
"nest", | ||
"ptsecurity" | ||
], | ||
"peerDependencies": { | ||
"@nestjs/common": "^6.0.0", | ||
"@nestjs/core": "^6.0.0", | ||
"@nestjs/platform-express": "^6.0.0", | ||
"@nestjs/typeorm": "^6.1.3", | ||
"sqlite": "^3.0.3" | ||
}, | ||
"sideEffects": false | ||
} |
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 @@ | ||
export const environment = { | ||
production: true, | ||
|
||
server: { | ||
host: process.env.HOST || '0.0.0.0', | ||
domainUrl: process.env.DOMAIN_URL || 'http://localhost:4545', | ||
port: process.env.PORT || 4545, // tslint:disable-line | ||
globalPrefix: '/api' | ||
} | ||
|
||
}; |
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,23 @@ | ||
// This file can be replaced during build by using the `fileReplacements` array. | ||
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. | ||
// The list of file replacements can be found in `angular.json`. | ||
|
||
export const environment = { | ||
production: false, | ||
|
||
server: { | ||
host: 'localhost', | ||
domainUrl: 'http://localhost:4545', | ||
port: 4545, | ||
globalPrefix: '/api' | ||
} | ||
}; | ||
|
||
/* | ||
* For easier debugging in development mode, you can import the following file | ||
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. | ||
* | ||
* This import should be commented out in production mode because it will have a negative impact | ||
* on performance if an error is thrown. | ||
*/ | ||
// import 'zone.js/dist/zone-error'; // Included with Angular CLI. |
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,17 @@ | ||
import { Logger } from '@nestjs/common'; | ||
import { NestFactory } from '@nestjs/core'; | ||
|
||
import { AppModule } from './modules/app/app.module'; | ||
|
||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule, {cors: true, logger: true}); | ||
const globalPrefix = 'api'; | ||
app.setGlobalPrefix(globalPrefix); | ||
const port = process.env.port || 4545; | ||
await app.listen(port, () => { | ||
Logger.log(`Listening at http://localhost: ${port}/${globalPrefix}`); | ||
}); | ||
} | ||
|
||
bootstrap(); |
22 changes: 22 additions & 0 deletions
22
apps/mc-mocks-server/src/modules/app/app.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,22 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AppController } from './app.controller'; | ||
import { AppService } from './app.service'; | ||
|
||
describe('AppController', () => { | ||
let appController: AppController; | ||
|
||
beforeEach(async () => { | ||
const app: TestingModule = await Test.createTestingModule({ | ||
controllers: [AppController], | ||
providers: [AppService] | ||
}).compile(); | ||
|
||
appController = app.get<AppController>(AppController); | ||
}); | ||
|
||
describe('root', () => { | ||
it('should return "Hello World!"', () => { | ||
expect(appController.getHello()).toBe('Hello World!'); | ||
}); | ||
}); | ||
}); |
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,13 @@ | ||
import { Controller, Get } from '@nestjs/common'; | ||
import { AppService } from './app.service'; | ||
|
||
|
||
@Controller() | ||
export class AppController { | ||
constructor(private readonly appService: AppService) {} | ||
|
||
@Get() | ||
getHello(): string { | ||
return this.appService.getHello(); | ||
} | ||
} |
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,25 @@ | ||
import { UsersModule } from '@libs/mocks/users'; | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
|
||
import { AppController } from './app.controller'; | ||
import { AppService } from './app.service'; | ||
import { VulnerabilitiesModule } from '../vulnerabilities/vulnerabilities.module'; | ||
|
||
|
||
@Module({ | ||
imports: [ | ||
TypeOrmModule.forRoot({ | ||
type: 'sqlite', | ||
database: 'tmp/db.sql', | ||
entities: [`${__dirname}/**/*.entity{.ts,.js}`, `**/*.entity{.ts, .js}`], | ||
logging: true, | ||
synchronize: true | ||
}), | ||
UsersModule, | ||
VulnerabilitiesModule | ||
], | ||
controllers: [AppController], | ||
providers: [AppService] | ||
}) | ||
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class AppService { | ||
getHello(): string { | ||
return 'Hello World!'; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
apps/mc-mocks-server/src/modules/vulnerabilities/vulnerabilities.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,39 @@ | ||
import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Post, Put } from '@nestjs/common'; | ||
import { VulnerabilitiesService } from './vulnerabilities.service'; | ||
import { VulnerabilityDto } from './vulnerability.dto'; | ||
|
||
|
||
@Controller('vulnerabilities') | ||
export class VulnerabilitiesController { | ||
constructor(private vulnerabilitiesService: VulnerabilitiesService) {} | ||
|
||
@Get() | ||
@HttpCode(HttpStatus.OK) | ||
findAll() { | ||
return this.vulnerabilitiesService.getList(); | ||
} | ||
|
||
@Get(':id') | ||
@HttpCode(HttpStatus.PARTIAL_CONTENT) | ||
find(@Param()id: string) { | ||
return this.vulnerabilitiesService.getOne(id); | ||
} | ||
|
||
@Post() | ||
@HttpCode(HttpStatus.CREATED) | ||
create(@Body() vulnerabilityDto: Partial<VulnerabilityDto>) { | ||
return this.vulnerabilitiesService.create(vulnerabilityDto); | ||
} | ||
|
||
@Put(':id') | ||
@HttpCode(HttpStatus.ACCEPTED) | ||
update(@Param()id: string, @Body()item) { | ||
return this.vulnerabilitiesService.update(id, item); | ||
} | ||
|
||
@Delete(':id') | ||
@HttpCode(HttpStatus.NO_CONTENT) | ||
remove(@Param()id: string) { | ||
return this.vulnerabilitiesService.remove(id); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
apps/mc-mocks-server/src/modules/vulnerabilities/vulnerabilities.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,23 @@ | ||
|
||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
|
||
import { VulnerabilitiesController } from './vulnerabilities.controller'; | ||
import { VulnerabilitiesService } from './vulnerabilities.service'; | ||
import { Vulnerability } from './vulnerability.entity'; | ||
|
||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([Vulnerability])], | ||
controllers: [VulnerabilitiesController], | ||
providers: [VulnerabilitiesService] | ||
}) | ||
export class VulnerabilitiesModule { | ||
constructor(private vulnerabilitiesService: VulnerabilitiesService) { | ||
this.vulnerabilitiesService.count().then((res: number) => { | ||
if (res === 0) { | ||
this.vulnerabilitiesService.generateInitial(); | ||
} | ||
}); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
apps/mc-mocks-server/src/modules/vulnerabilities/vulnerabilities.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,53 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import * as faker from 'faker'; | ||
import { Repository } from 'typeorm'; | ||
|
||
import { Vulnerability } from './vulnerability.entity'; | ||
|
||
|
||
@Injectable() | ||
export class VulnerabilitiesService { | ||
constructor(@InjectRepository(Vulnerability) private readonly repository: Repository<Vulnerability>) {} | ||
|
||
async getList(): Promise<Vulnerability[] | []> { | ||
return this.repository.find(); | ||
} | ||
|
||
async getOne(id: string): Promise<Vulnerability | null> { | ||
return this.repository.findOneOrFail(id); | ||
} | ||
|
||
async create(vulnerability: Partial<Vulnerability>) { | ||
return this.repository.save(vulnerability); | ||
} | ||
|
||
async update(id: string, item: Partial<Vulnerability>) { | ||
return this.repository.update({id}, item); | ||
} | ||
|
||
async remove(id: string) { | ||
return this.repository.delete({id}); | ||
} | ||
|
||
async count(): Promise<number> { | ||
return this.repository.count(); | ||
} | ||
|
||
generateInitial() { | ||
const data = []; | ||
|
||
for (let i = 0; i < 15; i += 1) { | ||
data.push({ | ||
name: faker.hacker.abbreviation(), | ||
description: faker.hacker.phrase(), | ||
records: [{ | ||
name: faker.hacker.noun(), | ||
description: faker.hacker.adjective() | ||
}] | ||
}); | ||
} | ||
|
||
return this.repository.save(data); | ||
} | ||
} |
Oops, something went wrong.