Archived
Merge branch 'main' of https://github.com/GRZ4NA/city-tracker
This commit is contained in:
commit
6caa1dc6cb
14 files changed
+4921
-122
No files matched your search
Generated
+5
@@ -0,0 +1,5 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
@@ -9,17 +9,23 @@
|
|||||||
"build": "nest build",
|
"build": "nest build",
|
||||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||||
"start": "nest start",
|
"start": "nest start",
|
||||||
"dev": "nest start --watch",
|
"dev": "nest start --watch --preserveWatchOutput",
|
||||||
"debug": "nest start --debug --watch",
|
"debug": "nest start --debug --watch --preserveWatchOutput",
|
||||||
"prod": "node dist/main",
|
"prod": "node dist/main",
|
||||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nestjs/common": "^9.0.0",
|
"@nestjs/common": "^9.0.0",
|
||||||
"@nestjs/core": "^9.0.0",
|
"@nestjs/core": "^9.0.0",
|
||||||
|
"@nestjs/mapped-types": "*",
|
||||||
"@nestjs/platform-express": "^9.0.0",
|
"@nestjs/platform-express": "^9.0.0",
|
||||||
|
"@nestjs/typeorm": "^9.0.1",
|
||||||
|
"class-transformer": "^0.5.1",
|
||||||
|
"class-validator": "^0.14.0",
|
||||||
|
"pg": "^8.11.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rxjs": "^7.2.0"
|
"rxjs": "^7.2.0",
|
||||||
|
"typeorm": "^0.3.16"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nestjs/cli": "^9.0.0",
|
"@nestjs/cli": "^9.0.0",
|
||||||
@@ -38,22 +44,5 @@
|
|||||||
"ts-node": "^10.0.0",
|
"ts-node": "^10.0.0",
|
||||||
"tsconfig-paths": "4.2.0",
|
"tsconfig-paths": "4.2.0",
|
||||||
"typescript": "^5.0.0"
|
"typescript": "^5.0.0"
|
||||||
},
|
|
||||||
"jest": {
|
|
||||||
"moduleFileExtensions": [
|
|
||||||
"js",
|
|
||||||
"json",
|
|
||||||
"ts"
|
|
||||||
],
|
|
||||||
"rootDir": "src",
|
|
||||||
"testRegex": ".*\\.spec\\.ts$",
|
|
||||||
"transform": {
|
|
||||||
"^.+\\.(t|j)s$": "ts-jest"
|
|
||||||
},
|
|
||||||
"collectCoverageFrom": [
|
|
||||||
"**/*.(t|j)s"
|
|
||||||
],
|
|
||||||
"coverageDirectory": "../coverage",
|
|
||||||
"testEnvironment": "node"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,20 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { AppController } from './app.controller';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { AppService } from './app.service';
|
import { IssuesModule } from './issues/issues.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [],
|
imports: [
|
||||||
controllers: [AppController],
|
TypeOrmModule.forRoot({
|
||||||
providers: [AppService],
|
type: 'postgres',
|
||||||
|
host: 'postgres',
|
||||||
|
port: 5432,
|
||||||
|
username: 'admin',
|
||||||
|
password: 'admin!',
|
||||||
|
database: 'city_tracker_db',
|
||||||
|
autoLoadEntities: true,
|
||||||
|
synchronize: process.env.NODE_ENV !== 'production',
|
||||||
|
}),
|
||||||
|
IssuesModule,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AppService {
|
|
||||||
getHello(): string {
|
|
||||||
return 'Hello World!';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { IsNumber, IsString, MaxLength, MinLength } from 'class-validator';
|
||||||
|
|
||||||
|
export class CreateIssueDto {
|
||||||
|
@IsString()
|
||||||
|
@MinLength(1)
|
||||||
|
@MaxLength(32)
|
||||||
|
title: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@MinLength(10)
|
||||||
|
@MaxLength(255)
|
||||||
|
description: string;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
latitude: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
longitude: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import { PartialType } from '@nestjs/mapped-types';
|
||||||
|
import { CreateIssueDto } from './create-issue.dto';
|
||||||
|
|
||||||
|
export class UpdateIssueDto extends PartialType(CreateIssueDto) {}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export enum IssueStatus {
|
||||||
|
new = 'NEW',
|
||||||
|
inProgress = 'IN_PROGRESS',
|
||||||
|
done = 'DONE',
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import {
|
||||||
|
Column,
|
||||||
|
CreateDateColumn,
|
||||||
|
Entity,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
} from 'typeorm';
|
||||||
|
import { IssueStatus } from './issue-status.enum';
|
||||||
|
|
||||||
|
@Entity('issues')
|
||||||
|
export class Issue {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
title: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
description: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
latitude: number;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
longitude: string;
|
||||||
|
|
||||||
|
@Column({ type: 'enum', enum: IssueStatus, default: IssueStatus.new })
|
||||||
|
status: IssueStatus;
|
||||||
|
|
||||||
|
@CreateDateColumn()
|
||||||
|
createdAt: Date;
|
||||||
|
|
||||||
|
toDto() {
|
||||||
|
return {
|
||||||
|
id: this.id,
|
||||||
|
title: this.title,
|
||||||
|
status: this.status,
|
||||||
|
description: this.description,
|
||||||
|
latitude: this.latitude,
|
||||||
|
longitude: this.longitude,
|
||||||
|
createdAt: this.createdAt,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
Post,
|
||||||
|
Body,
|
||||||
|
Patch,
|
||||||
|
Param,
|
||||||
|
Delete,
|
||||||
|
HttpCode,
|
||||||
|
HttpStatus,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { IssuesService } from './issues.service';
|
||||||
|
import { CreateIssueDto } from './dto/create-issue.dto';
|
||||||
|
import { UpdateIssueDto } from './dto/update-issue.dto';
|
||||||
|
|
||||||
|
@Controller('issues')
|
||||||
|
export class IssuesController {
|
||||||
|
constructor(private readonly issuesService: IssuesService) {}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
create(@Body() createIssueDto: CreateIssueDto) {
|
||||||
|
return this.issuesService.create(createIssueDto).then((i) => i.toDto());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
findAll(@Param('direction') direction: string) {
|
||||||
|
return this.issuesService
|
||||||
|
.findAll(
|
||||||
|
direction.toLowerCase() === 'desc' ||
|
||||||
|
direction.toLowerCase() === 'descending',
|
||||||
|
)
|
||||||
|
.then((r) => r.map((i) => i.toDto()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
findOne(@Param('id') id: string) {
|
||||||
|
return this.issuesService.findOne(id).then((i) => i.toDto());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch(':id')
|
||||||
|
update(@Param('id') id: string, @Body() updateIssueDto: UpdateIssueDto) {
|
||||||
|
return this.issuesService.update(id, updateIssueDto).then((i) => i.toDto());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete(':id')
|
||||||
|
@HttpCode(HttpStatus.NO_CONTENT)
|
||||||
|
remove(@Param('id') id: string) {
|
||||||
|
return this.issuesService.remove(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { IssuesService } from './issues.service';
|
||||||
|
import { IssuesController } from './issues.controller';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { Issue } from './entities/issue.entity';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [TypeOrmModule.forFeature([Issue])],
|
||||||
|
controllers: [IssuesController],
|
||||||
|
providers: [IssuesService],
|
||||||
|
exports: [IssuesService],
|
||||||
|
})
|
||||||
|
export class IssuesModule {}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||||
|
import { CreateIssueDto } from './dto/create-issue.dto';
|
||||||
|
import { UpdateIssueDto } from './dto/update-issue.dto';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { Issue } from './entities/issue.entity';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class IssuesService {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(Issue) private readonly repository: Repository<Issue>,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async create(createIssueDto: CreateIssueDto) {
|
||||||
|
const issue = this.repository.create({ ...createIssueDto });
|
||||||
|
return this.repository.save(issue);
|
||||||
|
}
|
||||||
|
|
||||||
|
async findAll(descending: boolean) {
|
||||||
|
return this.repository.find({
|
||||||
|
order: { createdAt: descending ? 'DESC' : 'ASC' },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async findOne(id: string) {
|
||||||
|
const ent = this.repository.findOneBy({ id });
|
||||||
|
if (ent === null) {
|
||||||
|
throw new NotFoundException('Issue not found');
|
||||||
|
}
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(id: string, updateIssueDto: UpdateIssueDto) {
|
||||||
|
const ent = await this.findOne(id);
|
||||||
|
this.repository.merge(ent, updateIssueDto);
|
||||||
|
return this.repository.save(ent);
|
||||||
|
}
|
||||||
|
|
||||||
|
async remove(id: string) {
|
||||||
|
const ent = await this.findOne(id);
|
||||||
|
return this.repository.remove(ent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,16 @@
|
|||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from '@nestjs/core';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
|
import { ValidationPipe } from '@nestjs/common';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
|
app.useGlobalPipes(
|
||||||
|
new ValidationPipe({
|
||||||
|
transform: true,
|
||||||
|
transformOptions: { enableImplicitConversion: false },
|
||||||
|
whitelist: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
await app.listen(3000);
|
await app.listen(3000);
|
||||||
}
|
}
|
||||||
bootstrap();
|
bootstrap();
|
||||||
Reference in new issue
Block a user