-
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
Showing
21 changed files
with
529 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
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ export enum ReportCategory { | |
trash = 'trash', | ||
forest = 'forest', | ||
beetle = 'beetle', | ||
permits = 'permits', | ||
} |
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 { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class GeometryCoordinatesDto { | ||
@ApiProperty({ format: 'double' }) | ||
latitude: number; | ||
|
||
@ApiProperty({ format: 'double' }) | ||
longitude: number; | ||
|
||
constructor(latitude: number, longitude: number) { | ||
this.latitude = latitude; | ||
this.longitude = longitude; | ||
} | ||
} |
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 * from './permit.dto'; |
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,15 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { GeometryCoordinatesDto } from './geometry-coordinates.dto'; | ||
|
||
export class PermitGeometryDto { | ||
@ApiProperty() | ||
type: string; | ||
|
||
@ApiProperty({ type: [GeometryCoordinatesDto] }) | ||
coordinates: GeometryCoordinatesDto[]; | ||
|
||
constructor(type: string, coordinates: GeometryCoordinatesDto[]) { | ||
this.type = type; | ||
this.coordinates = coordinates; | ||
} | ||
} |
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,67 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class PermitPropertiesDto { | ||
@ApiProperty() | ||
type: string; | ||
|
||
@ApiProperty() | ||
issuedFrom: string; | ||
|
||
@ApiProperty() | ||
issuedTo: string; | ||
|
||
@ApiProperty() | ||
cadastralNumber: string; | ||
|
||
@ApiProperty({ nullable: true }) | ||
subdivision?: string; | ||
|
||
@ApiProperty({ nullable: true }) | ||
forestryDistrict?: string; | ||
|
||
@ApiProperty({ format: 'double', nullable: true }) | ||
block?: number; | ||
|
||
@ApiProperty({ nullable: true }) | ||
plot?: string; | ||
|
||
@ApiProperty({ format: 'double', nullable: true }) | ||
cuttableArea?: number; | ||
|
||
@ApiProperty({ nullable: true }) | ||
dominantTree?: string; | ||
|
||
@ApiProperty({ nullable: true }) | ||
cuttingType?: string; | ||
|
||
@ApiProperty({ nullable: true }) | ||
reinstatementType?: string; | ||
|
||
constructor( | ||
type: string, | ||
issuedFrom: string, | ||
issuedTo: string, | ||
cadastralNumber: string, | ||
subdivision?: string, | ||
forestryDistrict?: string, | ||
block?: number, | ||
plot?: string, | ||
cuttableArea?: number, | ||
dominantTree?: string, | ||
cuttingType?: string, | ||
reinstatementType?: string, | ||
) { | ||
this.type = type; | ||
this.issuedFrom = issuedFrom; | ||
this.issuedTo = issuedTo; | ||
this.cadastralNumber = cadastralNumber; | ||
this.subdivision = subdivision; | ||
this.forestryDistrict = forestryDistrict; | ||
this.block = block; | ||
this.plot = plot; | ||
this.cuttableArea = cuttableArea; | ||
this.dominantTree = dominantTree; | ||
this.cuttingType = cuttingType; | ||
this.reinstatementType = reinstatementType; | ||
} | ||
} |
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 { ApiProperty } from '@nestjs/swagger'; | ||
import { PermitPropertiesDto } from './permit-properties.dto'; | ||
import { PermitGeometryDto } from './permit-geometry.dto'; | ||
|
||
export class PermitDto { | ||
@ApiProperty({ type: PermitPropertiesDto }) | ||
permitProperties: PermitPropertiesDto; | ||
|
||
@ApiProperty({ type: PermitGeometryDto }) | ||
permitGeometry: PermitGeometryDto; | ||
|
||
constructor( | ||
permitProperties: PermitPropertiesDto, | ||
permitGeometry: PermitGeometryDto, | ||
) { | ||
this.permitProperties = permitProperties; | ||
this.permitGeometry = permitGeometry; | ||
} | ||
} |
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,40 @@ | ||
import { Body, Controller, Get, ParseArrayPipe, Post } from '@nestjs/common'; | ||
import { PermitService } from './permit.service'; | ||
import { ApiCreatedResponse, ApiOkResponse, ApiTags } from '@nestjs/swagger'; | ||
import { PermitDto } from './dto'; | ||
|
||
@Controller('permits') | ||
@ApiTags('permits') | ||
export class PermitController { | ||
constructor(private readonly permitService: PermitService) {} | ||
|
||
@ApiCreatedResponse({ | ||
description: 'New Permits have been successfully created', | ||
type: [PermitDto], | ||
}) | ||
@Post('/multiple') | ||
createMultiplePermits( | ||
@Body(new ParseArrayPipe({ items: PermitDto })) | ||
createPermits: PermitDto[], | ||
): Promise<PermitDto[]> { | ||
return this.permitService.createMultiplePermits(createPermits); | ||
} | ||
|
||
@ApiCreatedResponse({ | ||
description: 'New Permit has been successfully created', | ||
type: PermitDto, | ||
}) | ||
@Post() | ||
createNewPermit(@Body() createPermit: PermitDto): Promise<PermitDto> { | ||
return this.permitService.createPermit(createPermit); | ||
} | ||
|
||
@ApiOkResponse({ | ||
description: 'All permits have been successfully found', | ||
type: [PermitDto], | ||
}) | ||
@Get() | ||
getAllPermits(): Promise<PermitDto[]> { | ||
return this.permitService.getAllPermits(); | ||
} | ||
} |
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,15 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { PermitController } from './permit.controller'; | ||
import { PermitService } from './permit.service'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { Permit, PermitSchema } from '../repositories/permit/schemas'; | ||
import { PermitRepository } from '../repositories/permit/permit.repository'; | ||
|
||
@Module({ | ||
imports: [ | ||
MongooseModule.forFeature([{ name: Permit.name, schema: PermitSchema }]), | ||
], | ||
controllers: [PermitController], | ||
providers: [PermitService, PermitRepository], | ||
}) | ||
export class PermitModule {} |
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,73 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { PermitDto } from './dto'; | ||
import { PermitRepository } from '../repositories/permit/permit.repository'; | ||
import { | ||
GeometryCoordinates, | ||
Permit, | ||
PermitGeometry, | ||
PermitProperties, | ||
} from '../repositories/permit/schemas'; | ||
import { PermitPropertiesDto } from './dto/permit-properties.dto'; | ||
import { PermitGeometryDto } from './dto/permit-geometry.dto'; | ||
import { GeometryCoordinatesDto } from './dto/geometry-coordinates.dto'; | ||
|
||
@Injectable() | ||
export class PermitService { | ||
constructor(private readonly permitRepository: PermitRepository) {} | ||
|
||
async getAllPermits(): Promise<PermitDto[]> { | ||
const permits = await this.permitRepository.getAllPermits(); | ||
return permits.map(PermitService.docToPermit); | ||
} | ||
|
||
async createPermit(permit: PermitDto): Promise<PermitDto> { | ||
const newPermit = await this.permitRepository.createPermit(permit); | ||
return PermitService.docToPermit(newPermit); | ||
} | ||
|
||
async createMultiplePermits(permits: PermitDto[]): Promise<PermitDto[]> { | ||
const convertedPermits = []; | ||
for (let i = 0; i < permits.length; i++) { | ||
const newPermit = await this.permitRepository.createPermit(permits[i]); | ||
convertedPermits[i] = PermitService.docToPermit(newPermit); | ||
} | ||
return convertedPermits; | ||
} | ||
|
||
private static docToPermit(e: Permit): PermitDto { | ||
return new PermitDto( | ||
PermitService.docToProperties(e.permitProperties), | ||
PermitService.docToGeometry(e.permitGeometry), | ||
); | ||
} | ||
|
||
private static docToProperties(e: PermitProperties): PermitPropertiesDto { | ||
return new PermitPropertiesDto( | ||
e.type, | ||
e.issuedFrom, | ||
e.issuedTo, | ||
e.cadastralNumber, | ||
e.subdivision, | ||
e.forestryDistrict, | ||
e.block, | ||
e.plot, | ||
e.cuttableArea, | ||
e.dominantTree, | ||
e.cuttingType, | ||
e.reinstatementType, | ||
); | ||
} | ||
|
||
private static docToGeometry(e: PermitGeometry): PermitGeometryDto { | ||
return new PermitGeometryDto( | ||
e.type, | ||
e.coordinates.map(PermitService.coordinatesToGeometry), | ||
); | ||
} | ||
|
||
private static coordinatesToGeometry( | ||
e: GeometryCoordinates, | ||
): GeometryCoordinatesDto { | ||
return new GeometryCoordinatesDto(e.latitude, e.longitude); | ||
} | ||
} |
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 { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class GeometryCoordinatesDto { | ||
@ApiProperty({ format: 'double' }) | ||
latitude: number; | ||
|
||
@ApiProperty({ format: 'double' }) | ||
longitude: number; | ||
|
||
constructor(latitude: number, longitude: number) { | ||
this.latitude = latitude; | ||
this.longitude = longitude; | ||
} | ||
} |
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,3 +1,4 @@ | ||
export * from './create-report.dto'; | ||
export * from './public-report.dto'; | ||
export * from './status-records.dto'; | ||
export * from './permit.dto'; |
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,15 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { GeometryCoordinatesDto } from './geometry-coordinates.dto'; | ||
|
||
export class PermitGeometryDto { | ||
@ApiProperty() | ||
type: string; | ||
|
||
@ApiProperty({ type: [GeometryCoordinatesDto] }) | ||
coordinates: GeometryCoordinatesDto[]; | ||
|
||
constructor(type: string, coordinates: GeometryCoordinatesDto[]) { | ||
this.type = type; | ||
this.coordinates = coordinates; | ||
} | ||
} |
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,67 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class PermitPropertiesDto { | ||
@ApiProperty() | ||
type: string; | ||
|
||
@ApiProperty() | ||
issuedFrom: string; | ||
|
||
@ApiProperty() | ||
issuedTo: string; | ||
|
||
@ApiProperty() | ||
cadastralNumber: string; | ||
|
||
@ApiProperty({ nullable: true }) | ||
subdivision?: string; | ||
|
||
@ApiProperty({ nullable: true }) | ||
forestryDistrict?: string; | ||
|
||
@ApiProperty({ format: 'double', nullable: true }) | ||
block?: number; | ||
|
||
@ApiProperty({ nullable: true }) | ||
plot?: string; | ||
|
||
@ApiProperty({ format: 'double', nullable: true }) | ||
cuttableArea?: number; | ||
|
||
@ApiProperty({ nullable: true }) | ||
dominantTree?: string; | ||
|
||
@ApiProperty({ nullable: true }) | ||
cuttingType?: string; | ||
|
||
@ApiProperty({ nullable: true }) | ||
reinstatementType?: string; | ||
|
||
constructor( | ||
type: string, | ||
issuedFrom: string, | ||
issuedTo: string, | ||
cadastralNumber: string, | ||
subdivision?: string, | ||
forestryDistrict?: string, | ||
block?: number, | ||
plot?: string, | ||
cuttableArea?: number, | ||
dominantTree?: string, | ||
cuttingType?: string, | ||
reinstatementType?: string, | ||
) { | ||
this.type = type; | ||
this.issuedFrom = issuedFrom; | ||
this.issuedTo = issuedTo; | ||
this.cadastralNumber = cadastralNumber; | ||
this.subdivision = subdivision; | ||
this.forestryDistrict = forestryDistrict; | ||
this.block = block; | ||
this.plot = plot; | ||
this.cuttableArea = cuttableArea; | ||
this.dominantTree = dominantTree; | ||
this.cuttingType = cuttingType; | ||
this.reinstatementType = reinstatementType; | ||
} | ||
} |
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 { ApiProperty } from '@nestjs/swagger'; | ||
import { PermitPropertiesDto } from './permit-properties.dto'; | ||
import { PermitGeometryDto } from './permit-geometry.dto'; | ||
|
||
export class PermitDto { | ||
@ApiProperty({ type: PermitPropertiesDto }) | ||
permitProperties: PermitPropertiesDto; | ||
|
||
@ApiProperty({ type: PermitGeometryDto }) | ||
permitGeometry: PermitGeometryDto; | ||
|
||
constructor( | ||
permitProperties: PermitPropertiesDto, | ||
permitGeometry: PermitGeometryDto, | ||
) { | ||
this.permitProperties = permitProperties; | ||
this.permitGeometry = permitGeometry; | ||
} | ||
} |
Oops, something went wrong.