Init Nest-Neo4j
This commit is contained in:
73
Nest/README.md
Normal file
73
Nest/README.md
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<p align="center">
|
||||||
|
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
||||||
|
[circleci-url]: https://circleci.com/gh/nestjs/nest
|
||||||
|
|
||||||
|
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
||||||
|
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
||||||
|
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
|
||||||
|
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
||||||
|
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
|
||||||
|
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
||||||
|
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
||||||
|
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
||||||
|
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
|
||||||
|
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
||||||
|
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
|
||||||
|
</p>
|
||||||
|
<!--[](https://opencollective.com/nest#backer)
|
||||||
|
[](https://opencollective.com/nest#sponsor)-->
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running the app
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# development
|
||||||
|
$ npm run start
|
||||||
|
|
||||||
|
# watch mode
|
||||||
|
$ npm run start:dev
|
||||||
|
|
||||||
|
# production mode
|
||||||
|
$ npm run start:prod
|
||||||
|
```
|
||||||
|
|
||||||
|
## Test
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# unit tests
|
||||||
|
$ npm run test
|
||||||
|
|
||||||
|
# e2e tests
|
||||||
|
$ npm run test:e2e
|
||||||
|
|
||||||
|
# test coverage
|
||||||
|
$ npm run test:cov
|
||||||
|
```
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||||
|
|
||||||
|
## Stay in touch
|
||||||
|
|
||||||
|
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
|
||||||
|
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||||
|
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Nest is [MIT licensed](LICENSE).
|
||||||
5
Nest/nest-cli.json
Normal file
5
Nest/nest-cli.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/nest-cli",
|
||||||
|
"collection": "@nestjs/schematics",
|
||||||
|
"sourceRoot": "src"
|
||||||
|
}
|
||||||
8862
Nest/package-lock.json
generated
Normal file
8862
Nest/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
54
Nest/package.json
Normal file
54
Nest/package.json
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
{
|
||||||
|
"name": "nest-neo4j",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "",
|
||||||
|
"author": "",
|
||||||
|
"private": true,
|
||||||
|
"license": "UNLICENSED",
|
||||||
|
"scripts": {
|
||||||
|
"prebuild": "rimraf dist",
|
||||||
|
"build": "nest build",
|
||||||
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||||
|
"start": "nest start",
|
||||||
|
"start:dev": "nest start --watch",
|
||||||
|
"start:debug": "nest start --debug --watch",
|
||||||
|
"start:prod": "node dist/main"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@nestjs/common": "^9.0.0",
|
||||||
|
"@nestjs/config": "^2.2.0",
|
||||||
|
"@nestjs/core": "^9.0.0",
|
||||||
|
"@nestjs/jwt": "^9.0.0",
|
||||||
|
"@nestjs/mapped-types": "*",
|
||||||
|
"@nestjs/passport": "^9.0.0",
|
||||||
|
"@nestjs/platform-express": "^9.0.0",
|
||||||
|
"bcrypt": "^5.0.1",
|
||||||
|
"class-transformer": "^0.5.1",
|
||||||
|
"class-validator": "^0.13.2",
|
||||||
|
"neo4j-driver": "^5.0.1",
|
||||||
|
"passport": "^0.6.0",
|
||||||
|
"passport-jwt": "^4.0.0",
|
||||||
|
"passport-local": "^1.0.0",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^3.0.2",
|
||||||
|
"rxjs": "^7.2.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@nestjs/cli": "^9.0.0",
|
||||||
|
"@nestjs/schematics": "^9.0.0",
|
||||||
|
"@nestjs/testing": "^9.0.0",
|
||||||
|
"@types/bcrypt": "^5.0.0",
|
||||||
|
"@types/express": "^4.17.13",
|
||||||
|
"@types/node": "^16.0.0",
|
||||||
|
"@types/passport-jwt": "^3.0.6",
|
||||||
|
"@types/passport-local": "^1.0.34",
|
||||||
|
"@types/supertest": "^2.0.11",
|
||||||
|
"prettier": "^2.3.2",
|
||||||
|
"source-map-support": "^0.5.20",
|
||||||
|
"supertest": "^6.1.3",
|
||||||
|
"ts-loader": "^9.2.3",
|
||||||
|
"ts-node": "^10.0.0",
|
||||||
|
"tsconfig-paths": "4.1.0",
|
||||||
|
"typescript": "^4.7.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
19
Nest/src/app.controller.ts
Normal file
19
Nest/src/app.controller.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||||
|
import { AppService } from './app.service';
|
||||||
|
import { JwtAuthGuard } from './auth/jwt.guard';
|
||||||
|
|
||||||
|
@Controller()
|
||||||
|
export class AppController {
|
||||||
|
constructor(private readonly appService: AppService) {}
|
||||||
|
@Get()
|
||||||
|
async getHello(): Promise<string> {
|
||||||
|
const greeting = await this.appService.getHello();
|
||||||
|
return greeting;
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(JwtAuthGuard)
|
||||||
|
@Get('/protected')
|
||||||
|
async getProtected() {
|
||||||
|
return 'PROTECTED';
|
||||||
|
}
|
||||||
|
}
|
||||||
33
Nest/src/app.module.ts
Normal file
33
Nest/src/app.module.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||||
|
import { AppController } from './app.controller';
|
||||||
|
import { Neo4jModule } from './neo4j/neo4j.module';
|
||||||
|
import { AuthModule } from './auth/auth.module';
|
||||||
|
import { UserModule } from './user/user.module';
|
||||||
|
import { Neo4jConfig } from './neo4j/neo4j-cfg.interface';
|
||||||
|
import { AppService } from './app.service';
|
||||||
|
import { StdZhModule } from './std_zh/std_zh.module';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
ConfigModule.forRoot({ isGlobal: true }),
|
||||||
|
Neo4jModule.forRootAsync({
|
||||||
|
imports: [ConfigModule],
|
||||||
|
inject: [ConfigService],
|
||||||
|
useFactory: (configService: ConfigService): Neo4jConfig => ({
|
||||||
|
scheme: configService.get('NEO_SCHEME'),
|
||||||
|
host: configService.get('NEO_HOST'),
|
||||||
|
port: configService.get('NEO_PORT'),
|
||||||
|
username: configService.get('NEO_USER'),
|
||||||
|
password: configService.get('NEO_PASS'),
|
||||||
|
database: configService.get('NEO_DB'),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
AuthModule,
|
||||||
|
UserModule,
|
||||||
|
StdZhModule,
|
||||||
|
],
|
||||||
|
controllers: [AppController],
|
||||||
|
providers: [AppService],
|
||||||
|
})
|
||||||
|
export class AppModule {}
|
||||||
21
Nest/src/app.service.ts
Normal file
21
Nest/src/app.service.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { Node } from 'neo4j-driver';
|
||||||
|
import { Neo4jService } from 'src/neo4j/neo4j.service';
|
||||||
|
|
||||||
|
export type User = Node;
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class AppService {
|
||||||
|
constructor(private readonly neo4jService: Neo4jService) {}
|
||||||
|
|
||||||
|
async getHello(): Promise<string> {
|
||||||
|
const result = await this.neo4jService.read(
|
||||||
|
`MATCH (n) RETURN count(n) AS count`,
|
||||||
|
{},
|
||||||
|
);
|
||||||
|
|
||||||
|
const count = result.records[0].get('count');
|
||||||
|
|
||||||
|
return `${count} nodes in the database`;
|
||||||
|
}
|
||||||
|
}
|
||||||
27
Nest/src/auth/Dto/credentials.dto.ts
Normal file
27
Nest/src/auth/Dto/credentials.dto.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { Type } from 'class-transformer';
|
||||||
|
import { IsDate, IsEmail, IsNotEmpty, MaxDate } from 'class-validator';
|
||||||
|
|
||||||
|
export class LoginDto {
|
||||||
|
username?: string;
|
||||||
|
@IsEmail()
|
||||||
|
email?: string;
|
||||||
|
@IsNotEmpty()
|
||||||
|
password: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class RegisterDto {
|
||||||
|
@IsNotEmpty()
|
||||||
|
username?: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsEmail()
|
||||||
|
email: string;
|
||||||
|
@IsNotEmpty()
|
||||||
|
password: string;
|
||||||
|
@IsNotEmpty()
|
||||||
|
fullname: string;
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsDate()
|
||||||
|
@Type(() => Date)
|
||||||
|
birthday: Date;
|
||||||
|
}
|
||||||
28
Nest/src/auth/auth.controller.ts
Normal file
28
Nest/src/auth/auth.controller.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { Body, Controller, Post, UseGuards, Request } from '@nestjs/common';
|
||||||
|
import { UserService } from 'src/user/user.service';
|
||||||
|
import { LocalAuthGuard } from './auth.guard';
|
||||||
|
import { AuthService } from './auth.service';
|
||||||
|
import { RegisterDto } from './Dto/credentials.dto';
|
||||||
|
|
||||||
|
@Controller('auth')
|
||||||
|
export class AuthController {
|
||||||
|
constructor(
|
||||||
|
private readonly userService: UserService,
|
||||||
|
private readonly authService: AuthService,
|
||||||
|
) {}
|
||||||
|
@Post('register')
|
||||||
|
async postRegister(@Body() registerDto: RegisterDto) {
|
||||||
|
const user = await this.userService.create(registerDto);
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
@UseGuards(LocalAuthGuard)
|
||||||
|
@Post('login')
|
||||||
|
async postLogin(@Request() request) {
|
||||||
|
const { user } = request;
|
||||||
|
const { access_token } = await this.authService.signToken(user);
|
||||||
|
return {
|
||||||
|
...user,
|
||||||
|
access_token,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
5
Nest/src/auth/auth.guard.ts
Normal file
5
Nest/src/auth/auth.guard.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class LocalAuthGuard extends AuthGuard('local') {}
|
||||||
19
Nest/src/auth/auth.module.ts
Normal file
19
Nest/src/auth/auth.module.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { AuthService } from './auth.service';
|
||||||
|
import { AuthController } from './auth.controller';
|
||||||
|
import { UserModule } from 'src/user/user.module';
|
||||||
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
|
import { LocalStrategy } from './local.strategy';
|
||||||
|
import { JwtStrategy } from './jwt.strategy';
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
UserModule,
|
||||||
|
JwtModule.register({
|
||||||
|
secret: process.env.JWT_SECRET || 'changeme',
|
||||||
|
signOptions: { expiresIn: '600s' },
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
providers: [AuthService, LocalStrategy, JwtStrategy],
|
||||||
|
controllers: [AuthController],
|
||||||
|
})
|
||||||
|
export class AuthModule {}
|
||||||
35
Nest/src/auth/auth.service.ts
Normal file
35
Nest/src/auth/auth.service.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||||
|
import { User, UserService } from 'src/user/user.service';
|
||||||
|
import { JwtService } from '@nestjs/jwt';
|
||||||
|
|
||||||
|
import { compare } from 'bcrypt';
|
||||||
|
@Injectable()
|
||||||
|
export class AuthService {
|
||||||
|
constructor(
|
||||||
|
private readonly userService: UserService,
|
||||||
|
private readonly jwtService: JwtService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async validateUser(username: string, password: string): Promise<User> {
|
||||||
|
const user = await this.userService.findByUsername(username);
|
||||||
|
if (user && (await this.compare(password, user.properties.password))) {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
throw new UnauthorizedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
async signToken(user: User) {
|
||||||
|
const { id, email, username } = user.properties;
|
||||||
|
return {
|
||||||
|
access_token: this.jwtService.sign({
|
||||||
|
sub: id,
|
||||||
|
email,
|
||||||
|
username,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async compare(plain: string, hashed: string): Promise<boolean> {
|
||||||
|
return await compare(plain, hashed);
|
||||||
|
}
|
||||||
|
}
|
||||||
5
Nest/src/auth/jwt.guard.ts
Normal file
5
Nest/src/auth/jwt.guard.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class JwtAuthGuard extends AuthGuard('jwt') {}
|
||||||
20
Nest/src/auth/jwt.strategy.ts
Normal file
20
Nest/src/auth/jwt.strategy.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||||
|
import { PassportStrategy } from '@nestjs/passport';
|
||||||
|
import { Strategy, ExtractJwt } from 'passport-jwt';
|
||||||
|
import { User, UserService } from 'src/user/user.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||||
|
constructor(private readonly userService: UserService) {
|
||||||
|
super({
|
||||||
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||||
|
ignoreExpiration: false,
|
||||||
|
secretOrKey: process.env.JWT_SECRET || 'changeme',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async validate(payload: any): Promise<User> {
|
||||||
|
const user = await this.userService.findByUsername(payload.username);
|
||||||
|
if (user) return user;
|
||||||
|
throw new UnauthorizedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
20
Nest/src/auth/local.strategy.ts
Normal file
20
Nest/src/auth/local.strategy.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { PassportStrategy } from '@nestjs/passport';
|
||||||
|
import { Strategy } from 'passport-local';
|
||||||
|
import { Neo4jService } from 'src/neo4j/neo4j.service';
|
||||||
|
import { AuthService } from './auth.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class LocalStrategy extends PassportStrategy(Strategy) {
|
||||||
|
constructor(
|
||||||
|
private readonly neo4jService: Neo4jService,
|
||||||
|
private readonly authService: AuthService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
async validate(username: string, password: string): Promise<any> {
|
||||||
|
const user = await this.authService.validateUser(username, password);
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Nest/src/main.ts
Normal file
11
Nest/src/main.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { ValidationPipe } from '@nestjs/common';
|
||||||
|
import { NestFactory } from '@nestjs/core';
|
||||||
|
import { AppModule } from './app.module';
|
||||||
|
|
||||||
|
async function bootstrap() {
|
||||||
|
const app = await NestFactory.create(AppModule);
|
||||||
|
app.useGlobalPipes(new ValidationPipe());
|
||||||
|
|
||||||
|
await app.listen(process.env.APP_PORT || 3000);
|
||||||
|
}
|
||||||
|
bootstrap();
|
||||||
9
Nest/src/neo4j/neo4j-cfg.interface.ts
Normal file
9
Nest/src/neo4j/neo4j-cfg.interface.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export type Neo4jScheme = 'neo4j' | 'neo4j+s' | 'neo4j+ssc' | 'bolt' | 'bolt+s' | 'bolt+ssc';
|
||||||
|
export interface Neo4jConfig {
|
||||||
|
scheme: Neo4jScheme;
|
||||||
|
host: string;
|
||||||
|
port: number | string;
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
database?: string;
|
||||||
|
}
|
||||||
2
Nest/src/neo4j/neo4j.constans.ts
Normal file
2
Nest/src/neo4j/neo4j.constans.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export const NEO4J_CONFIG: string = 'NEO4J_CONFIG'
|
||||||
|
export const NEO4J_DRIVER: string = 'NEO4J_DRIVER'
|
||||||
51
Nest/src/neo4j/neo4j.module.ts
Normal file
51
Nest/src/neo4j/neo4j.module.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { DynamicModule, Module, Provider } from '@nestjs/common';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import { Neo4jConfig } from './neo4j-cfg.interface';
|
||||||
|
import { NEO4J_CONFIG, NEO4J_DRIVER } from './neo4j.constans';
|
||||||
|
import { Neo4jService } from './neo4j.service';
|
||||||
|
import { createDriver } from './neo4j.utilities';
|
||||||
|
|
||||||
|
@Module({})
|
||||||
|
export class Neo4jModule {
|
||||||
|
static forRoot(config: Neo4jConfig): DynamicModule {
|
||||||
|
return {
|
||||||
|
module: Neo4jModule,
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: NEO4J_CONFIG,
|
||||||
|
useValue: config,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: NEO4J_DRIVER,
|
||||||
|
inject: [NEO4J_CONFIG],
|
||||||
|
useFactory: async (config: Neo4jConfig) => await createDriver(config),
|
||||||
|
},
|
||||||
|
Neo4jService,
|
||||||
|
],
|
||||||
|
exports: [Neo4jService],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
static forRootAsync(configProvider): DynamicModule {
|
||||||
|
return {
|
||||||
|
module: Neo4jModule,
|
||||||
|
global: true,
|
||||||
|
imports: [ ConfigModule ],
|
||||||
|
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: NEO4J_CONFIG,
|
||||||
|
...configProvider
|
||||||
|
} as Provider<any>,
|
||||||
|
{
|
||||||
|
provide: NEO4J_DRIVER,
|
||||||
|
inject: [ NEO4J_CONFIG ],
|
||||||
|
useFactory: async (config: Neo4jConfig) => createDriver(config),
|
||||||
|
},
|
||||||
|
Neo4jService,
|
||||||
|
],
|
||||||
|
exports: [
|
||||||
|
Neo4jService,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
44
Nest/src/neo4j/neo4j.service.ts
Normal file
44
Nest/src/neo4j/neo4j.service.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import neo4j, { Driver, Result } from 'neo4j-driver';
|
||||||
|
import { Neo4jConfig } from './neo4j-cfg.interface';
|
||||||
|
import { NEO4J_CONFIG, NEO4J_DRIVER } from './neo4j.constans';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class Neo4jService {
|
||||||
|
constructor(
|
||||||
|
@Inject(NEO4J_CONFIG) private readonly config: Neo4jConfig,
|
||||||
|
@Inject(NEO4J_DRIVER) private readonly driver: Driver,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
getDriver(): Driver {
|
||||||
|
return this.driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
getConfig(): Neo4jConfig {
|
||||||
|
return this.config;
|
||||||
|
}
|
||||||
|
|
||||||
|
getReadSession(database?: string) {
|
||||||
|
return this.driver.session({
|
||||||
|
database: database || this.config.database,
|
||||||
|
defaultAccessMode: neo4j.session.READ,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getWriteSession(database?: string) {
|
||||||
|
return this.driver.session({
|
||||||
|
database: database || this.config.database,
|
||||||
|
defaultAccessMode: neo4j.session.WRITE,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
read(cypher: string, params: Record<string, any>, database?: string): Result {
|
||||||
|
const session = this.getReadSession(database);
|
||||||
|
return session.run(cypher, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
write(cypher: string, params: Record<string, any>, database?: string): Result {
|
||||||
|
const session = this.getWriteSession(database);
|
||||||
|
return session.run(cypher, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
13
Nest/src/neo4j/neo4j.utilities.ts
Normal file
13
Nest/src/neo4j/neo4j.utilities.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import neo4j, { Driver } from 'neo4j-driver';
|
||||||
|
import { Neo4jConfig } from './neo4j-cfg.interface';
|
||||||
|
|
||||||
|
export const createDriver = async (config: Neo4jConfig) => {
|
||||||
|
const driver: Driver = neo4j.driver(
|
||||||
|
`${config.scheme}://${config.host}:${config.port}`,
|
||||||
|
neo4j.auth.basic(config.username, config.password),
|
||||||
|
);
|
||||||
|
|
||||||
|
const serverInfo = await driver.getServerInfo();
|
||||||
|
console.log(serverInfo);
|
||||||
|
return driver;
|
||||||
|
};
|
||||||
34
Nest/src/std_zh/diagnoza/diagnoza.controller.ts
Normal file
34
Nest/src/std_zh/diagnoza/diagnoza.controller.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||||
|
import { DiagnozaService } from './diagnoza.service';
|
||||||
|
import { CreateDiagnozaDto } from './dto/create-diagnoza.dto';
|
||||||
|
import { UpdateDiagnozaDto } from './dto/update-diagnoza.dto';
|
||||||
|
|
||||||
|
@Controller('diagnoza')
|
||||||
|
export class DiagnozaController {
|
||||||
|
constructor(private readonly diagnozaService: DiagnozaService) {}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
create(@Body() createDiagnozaDto: CreateDiagnozaDto) {
|
||||||
|
return this.diagnozaService.create(createDiagnozaDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
findAll() {
|
||||||
|
return this.diagnozaService.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
findOne(@Param('id') id: string) {
|
||||||
|
return this.diagnozaService.findOne(+id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch(':id')
|
||||||
|
update(@Param('id') id: string, @Body() updateDiagnozaDto: UpdateDiagnozaDto) {
|
||||||
|
return this.diagnozaService.update(+id, updateDiagnozaDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete(':id')
|
||||||
|
remove(@Param('id') id: string) {
|
||||||
|
return this.diagnozaService.remove(+id);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Nest/src/std_zh/diagnoza/diagnoza.module.ts
Normal file
9
Nest/src/std_zh/diagnoza/diagnoza.module.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { DiagnozaService } from './diagnoza.service';
|
||||||
|
import { DiagnozaController } from './diagnoza.controller';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [DiagnozaController],
|
||||||
|
providers: [DiagnozaService]
|
||||||
|
})
|
||||||
|
export class DiagnozaModule {}
|
||||||
26
Nest/src/std_zh/diagnoza/diagnoza.service.ts
Normal file
26
Nest/src/std_zh/diagnoza/diagnoza.service.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { CreateDiagnozaDto } from './dto/create-diagnoza.dto';
|
||||||
|
import { UpdateDiagnozaDto } from './dto/update-diagnoza.dto';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DiagnozaService {
|
||||||
|
create(createDiagnozaDto: CreateDiagnozaDto) {
|
||||||
|
return 'This action adds a new diagnoza';
|
||||||
|
}
|
||||||
|
|
||||||
|
findAll() {
|
||||||
|
return `This action returns all diagnoza`;
|
||||||
|
}
|
||||||
|
|
||||||
|
findOne(id: number) {
|
||||||
|
return `This action returns a #${id} diagnoza`;
|
||||||
|
}
|
||||||
|
|
||||||
|
update(id: number, updateDiagnozaDto: UpdateDiagnozaDto) {
|
||||||
|
return `This action updates a #${id} diagnoza`;
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(id: number) {
|
||||||
|
return `This action removes a #${id} diagnoza`;
|
||||||
|
}
|
||||||
|
}
|
||||||
1
Nest/src/std_zh/diagnoza/dto/create-diagnoza.dto.ts
Normal file
1
Nest/src/std_zh/diagnoza/dto/create-diagnoza.dto.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export class CreateDiagnozaDto {}
|
||||||
4
Nest/src/std_zh/diagnoza/dto/update-diagnoza.dto.ts
Normal file
4
Nest/src/std_zh/diagnoza/dto/update-diagnoza.dto.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { PartialType } from '@nestjs/mapped-types';
|
||||||
|
import { CreateDiagnozaDto } from './create-diagnoza.dto';
|
||||||
|
|
||||||
|
export class UpdateDiagnozaDto extends PartialType(CreateDiagnozaDto) {}
|
||||||
1
Nest/src/std_zh/diagnoza/entities/diagnoza.entity.ts
Normal file
1
Nest/src/std_zh/diagnoza/entities/diagnoza.entity.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export class Diagnoza {}
|
||||||
1
Nest/src/std_zh/klinika/dto/create-klinika.dto.ts
Normal file
1
Nest/src/std_zh/klinika/dto/create-klinika.dto.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export class CreateKlinikaDto {}
|
||||||
4
Nest/src/std_zh/klinika/dto/update-klinika.dto.ts
Normal file
4
Nest/src/std_zh/klinika/dto/update-klinika.dto.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { PartialType } from '@nestjs/mapped-types';
|
||||||
|
import { CreateKlinikaDto } from './create-klinika.dto';
|
||||||
|
|
||||||
|
export class UpdateKlinikaDto extends PartialType(CreateKlinikaDto) {}
|
||||||
1
Nest/src/std_zh/klinika/entities/klinika.entity.ts
Normal file
1
Nest/src/std_zh/klinika/entities/klinika.entity.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export class Klinika {}
|
||||||
34
Nest/src/std_zh/klinika/klinika.controller.ts
Normal file
34
Nest/src/std_zh/klinika/klinika.controller.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||||
|
import { KlinikaService } from './klinika.service';
|
||||||
|
import { CreateKlinikaDto } from './dto/create-klinika.dto';
|
||||||
|
import { UpdateKlinikaDto } from './dto/update-klinika.dto';
|
||||||
|
|
||||||
|
@Controller('klinika')
|
||||||
|
export class KlinikaController {
|
||||||
|
constructor(private readonly klinikaService: KlinikaService) {}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
create(@Body() createKlinikaDto: CreateKlinikaDto) {
|
||||||
|
return this.klinikaService.create(createKlinikaDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
findAll() {
|
||||||
|
return this.klinikaService.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
findOne(@Param('id') id: string) {
|
||||||
|
return this.klinikaService.findOne(+id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch(':id')
|
||||||
|
update(@Param('id') id: string, @Body() updateKlinikaDto: UpdateKlinikaDto) {
|
||||||
|
return this.klinikaService.update(+id, updateKlinikaDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete(':id')
|
||||||
|
remove(@Param('id') id: string) {
|
||||||
|
return this.klinikaService.remove(+id);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Nest/src/std_zh/klinika/klinika.module.ts
Normal file
9
Nest/src/std_zh/klinika/klinika.module.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { KlinikaService } from './klinika.service';
|
||||||
|
import { KlinikaController } from './klinika.controller';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [KlinikaController],
|
||||||
|
providers: [KlinikaService]
|
||||||
|
})
|
||||||
|
export class KlinikaModule {}
|
||||||
26
Nest/src/std_zh/klinika/klinika.service.ts
Normal file
26
Nest/src/std_zh/klinika/klinika.service.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { CreateKlinikaDto } from './dto/create-klinika.dto';
|
||||||
|
import { UpdateKlinikaDto } from './dto/update-klinika.dto';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class KlinikaService {
|
||||||
|
create(createKlinikaDto: CreateKlinikaDto) {
|
||||||
|
return 'This action adds a new klinika';
|
||||||
|
}
|
||||||
|
|
||||||
|
findAll() {
|
||||||
|
return `This action returns all klinika`;
|
||||||
|
}
|
||||||
|
|
||||||
|
findOne(id: number) {
|
||||||
|
return `This action returns a #${id} klinika`;
|
||||||
|
}
|
||||||
|
|
||||||
|
update(id: number, updateKlinikaDto: UpdateKlinikaDto) {
|
||||||
|
return `This action updates a #${id} klinika`;
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(id: number) {
|
||||||
|
return `This action removes a #${id} klinika`;
|
||||||
|
}
|
||||||
|
}
|
||||||
1
Nest/src/std_zh/pacienti/dto/create-pacienti.dto.ts
Normal file
1
Nest/src/std_zh/pacienti/dto/create-pacienti.dto.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export class CreatePacientiDto {}
|
||||||
4
Nest/src/std_zh/pacienti/dto/update-pacienti.dto.ts
Normal file
4
Nest/src/std_zh/pacienti/dto/update-pacienti.dto.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { PartialType } from '@nestjs/mapped-types';
|
||||||
|
import { CreatePacientiDto } from './create-pacienti.dto';
|
||||||
|
|
||||||
|
export class UpdatePacientiDto extends PartialType(CreatePacientiDto) {}
|
||||||
1
Nest/src/std_zh/pacienti/entities/pacienti.entity.ts
Normal file
1
Nest/src/std_zh/pacienti/entities/pacienti.entity.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export class Pacienti {}
|
||||||
34
Nest/src/std_zh/pacienti/pacienti.controller.ts
Normal file
34
Nest/src/std_zh/pacienti/pacienti.controller.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||||
|
import { PacientiService } from './pacienti.service';
|
||||||
|
import { CreatePacientiDto } from './dto/create-pacienti.dto';
|
||||||
|
import { UpdatePacientiDto } from './dto/update-pacienti.dto';
|
||||||
|
|
||||||
|
@Controller('pacienti')
|
||||||
|
export class PacientiController {
|
||||||
|
constructor(private readonly pacientiService: PacientiService) {}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
create(@Body() createPacientiDto: CreatePacientiDto) {
|
||||||
|
return this.pacientiService.create(createPacientiDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
findAll() {
|
||||||
|
return this.pacientiService.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
findOne(@Param('id') id: string) {
|
||||||
|
return this.pacientiService.findOne(+id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch(':id')
|
||||||
|
update(@Param('id') id: string, @Body() updatePacientiDto: UpdatePacientiDto) {
|
||||||
|
return this.pacientiService.update(+id, updatePacientiDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete(':id')
|
||||||
|
remove(@Param('id') id: string) {
|
||||||
|
return this.pacientiService.remove(+id);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Nest/src/std_zh/pacienti/pacienti.module.ts
Normal file
9
Nest/src/std_zh/pacienti/pacienti.module.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { PacientiService } from './pacienti.service';
|
||||||
|
import { PacientiController } from './pacienti.controller';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [PacientiController],
|
||||||
|
providers: [PacientiService]
|
||||||
|
})
|
||||||
|
export class PacientiModule {}
|
||||||
26
Nest/src/std_zh/pacienti/pacienti.service.ts
Normal file
26
Nest/src/std_zh/pacienti/pacienti.service.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { CreatePacientiDto } from './dto/create-pacienti.dto';
|
||||||
|
import { UpdatePacientiDto } from './dto/update-pacienti.dto';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class PacientiService {
|
||||||
|
create(createPacientiDto: CreatePacientiDto) {
|
||||||
|
return 'This action adds a new pacienti';
|
||||||
|
}
|
||||||
|
|
||||||
|
findAll() {
|
||||||
|
return `This action returns all pacienti`;
|
||||||
|
}
|
||||||
|
|
||||||
|
findOne(id: number) {
|
||||||
|
return `This action returns a #${id} pacienti`;
|
||||||
|
}
|
||||||
|
|
||||||
|
update(id: number, updatePacientiDto: UpdatePacientiDto) {
|
||||||
|
return `This action updates a #${id} pacienti`;
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(id: number) {
|
||||||
|
return `This action removes a #${id} pacienti`;
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Nest/src/std_zh/std_zh.module.ts
Normal file
12
Nest/src/std_zh/std_zh.module.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { KlinikaModule } from './klinika/klinika.module';
|
||||||
|
import { PacientiModule } from './pacienti/pacienti.module';
|
||||||
|
import { DiagnozaModule } from './diagnoza/diagnoza.module';
|
||||||
|
import { TrajtimiModule } from './trajtimi/trajtimi.module';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [],
|
||||||
|
providers: [],
|
||||||
|
imports: [KlinikaModule, PacientiModule, DiagnozaModule, TrajtimiModule],
|
||||||
|
})
|
||||||
|
export class StdZhModule {}
|
||||||
1
Nest/src/std_zh/trajtimi/dto/create-trajtimi.dto.ts
Normal file
1
Nest/src/std_zh/trajtimi/dto/create-trajtimi.dto.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export class CreateTrajtimiDto {}
|
||||||
4
Nest/src/std_zh/trajtimi/dto/update-trajtimi.dto.ts
Normal file
4
Nest/src/std_zh/trajtimi/dto/update-trajtimi.dto.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { PartialType } from '@nestjs/mapped-types';
|
||||||
|
import { CreateTrajtimiDto } from './create-trajtimi.dto';
|
||||||
|
|
||||||
|
export class UpdateTrajtimiDto extends PartialType(CreateTrajtimiDto) {}
|
||||||
1
Nest/src/std_zh/trajtimi/entities/trajtimi.entity.ts
Normal file
1
Nest/src/std_zh/trajtimi/entities/trajtimi.entity.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export class Trajtimi {}
|
||||||
34
Nest/src/std_zh/trajtimi/trajtimi.controller.ts
Normal file
34
Nest/src/std_zh/trajtimi/trajtimi.controller.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||||
|
import { TrajtimiService } from './trajtimi.service';
|
||||||
|
import { CreateTrajtimiDto } from './dto/create-trajtimi.dto';
|
||||||
|
import { UpdateTrajtimiDto } from './dto/update-trajtimi.dto';
|
||||||
|
|
||||||
|
@Controller('trajtimi')
|
||||||
|
export class TrajtimiController {
|
||||||
|
constructor(private readonly trajtimiService: TrajtimiService) {}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
create(@Body() createTrajtimiDto: CreateTrajtimiDto) {
|
||||||
|
return this.trajtimiService.create(createTrajtimiDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
findAll() {
|
||||||
|
return this.trajtimiService.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
findOne(@Param('id') id: string) {
|
||||||
|
return this.trajtimiService.findOne(+id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch(':id')
|
||||||
|
update(@Param('id') id: string, @Body() updateTrajtimiDto: UpdateTrajtimiDto) {
|
||||||
|
return this.trajtimiService.update(+id, updateTrajtimiDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete(':id')
|
||||||
|
remove(@Param('id') id: string) {
|
||||||
|
return this.trajtimiService.remove(+id);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Nest/src/std_zh/trajtimi/trajtimi.module.ts
Normal file
9
Nest/src/std_zh/trajtimi/trajtimi.module.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { TrajtimiService } from './trajtimi.service';
|
||||||
|
import { TrajtimiController } from './trajtimi.controller';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [TrajtimiController],
|
||||||
|
providers: [TrajtimiService]
|
||||||
|
})
|
||||||
|
export class TrajtimiModule {}
|
||||||
26
Nest/src/std_zh/trajtimi/trajtimi.service.ts
Normal file
26
Nest/src/std_zh/trajtimi/trajtimi.service.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { CreateTrajtimiDto } from './dto/create-trajtimi.dto';
|
||||||
|
import { UpdateTrajtimiDto } from './dto/update-trajtimi.dto';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class TrajtimiService {
|
||||||
|
create(createTrajtimiDto: CreateTrajtimiDto) {
|
||||||
|
return 'This action adds a new trajtimi';
|
||||||
|
}
|
||||||
|
|
||||||
|
findAll() {
|
||||||
|
return `This action returns all trajtimi`;
|
||||||
|
}
|
||||||
|
|
||||||
|
findOne(id: number) {
|
||||||
|
return `This action returns a #${id} trajtimi`;
|
||||||
|
}
|
||||||
|
|
||||||
|
update(id: number, updateTrajtimiDto: UpdateTrajtimiDto) {
|
||||||
|
return `This action updates a #${id} trajtimi`;
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(id: number) {
|
||||||
|
return `This action removes a #${id} trajtimi`;
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Nest/src/user/user.controller.ts
Normal file
9
Nest/src/user/user.controller.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Controller } from '@nestjs/common';
|
||||||
|
import { UserService } from './user.service';
|
||||||
|
|
||||||
|
@Controller('user')
|
||||||
|
export class UserController {
|
||||||
|
constructor(private readonly userService: UserService) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Nest/src/user/user.module.ts
Normal file
11
Nest/src/user/user.module.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { UserService } from './user.service';
|
||||||
|
import { UserController } from './user.controller';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [],
|
||||||
|
providers: [UserService],
|
||||||
|
controllers: [UserController],
|
||||||
|
exports: [UserService],
|
||||||
|
})
|
||||||
|
export class UserModule {}
|
||||||
53
Nest/src/user/user.service.ts
Normal file
53
Nest/src/user/user.service.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import {
|
||||||
|
BadRequestException,
|
||||||
|
Injectable,
|
||||||
|
UnauthorizedException,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { RegisterDto } from 'src/auth/Dto/credentials.dto';
|
||||||
|
import { Neo4jService } from 'src/neo4j/neo4j.service';
|
||||||
|
import { Node } from 'neo4j-driver';
|
||||||
|
import { hash } from 'bcrypt';
|
||||||
|
|
||||||
|
export type User = Node;
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class UserService {
|
||||||
|
constructor(private readonly neo4jService: Neo4jService) {}
|
||||||
|
|
||||||
|
async findByUsername(username: string): Promise<User> {
|
||||||
|
try {
|
||||||
|
const res = await this.neo4jService.read(
|
||||||
|
`
|
||||||
|
MATCH (u:User {username: $username})
|
||||||
|
RETURN u
|
||||||
|
`,
|
||||||
|
{ username },
|
||||||
|
);
|
||||||
|
return res.records[0].get('u');
|
||||||
|
} catch (error) {
|
||||||
|
throw new UnauthorizedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(registerDto: RegisterDto): Promise<User> {
|
||||||
|
const hashedPass = await this.hashPass(registerDto.password);
|
||||||
|
const newUser = { ...registerDto, password: hashedPass };
|
||||||
|
try {
|
||||||
|
const res = await this.neo4jService.write(
|
||||||
|
`
|
||||||
|
CREATE (u:User)
|
||||||
|
SET u += $newUser, u.id = randomUUID()
|
||||||
|
RETURN u
|
||||||
|
`,
|
||||||
|
{ newUser },
|
||||||
|
);
|
||||||
|
return res.records[0].get('u');
|
||||||
|
} catch (error: any) {
|
||||||
|
throw new BadRequestException(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async hashPass(plain: string): Promise<string> {
|
||||||
|
return await hash(plain, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
4
Nest/tsconfig.build.json
Normal file
4
Nest/tsconfig.build.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
||||||
|
}
|
||||||
21
Nest/tsconfig.json
Normal file
21
Nest/tsconfig.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"declaration": true,
|
||||||
|
"removeComments": true,
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"target": "es2017",
|
||||||
|
"sourceMap": true,
|
||||||
|
"outDir": "./dist",
|
||||||
|
"baseUrl": "./",
|
||||||
|
"incremental": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"strictNullChecks": false,
|
||||||
|
"noImplicitAny": false,
|
||||||
|
"strictBindCallApply": false,
|
||||||
|
"forceConsistentCasingInFileNames": false,
|
||||||
|
"noFallthroughCasesInSwitch": false
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user