-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transfer data integration #13
Changes from 2 commits
b784ef9
11ec774
5c9b121
986b934
f88d3bb
540f060
3dc115d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { FullReportDto } from './dto'; | ||
import { FullReportDto, TransferReportDto } from './dto'; | ||
import { DumpRepository } from '../repositories/dumps/dump.repository'; | ||
import { ReportRepository } from '../repositories/reports/report.repository'; | ||
import { CreateDumpDto, FullDumpDto, UpdateDumpDto } from './dto'; | ||
|
@@ -15,6 +15,7 @@ import { StatusRecordsDto } from '../report/dto'; | |
import { UpdateReportDto } from './dto'; | ||
import { Dump } from '../repositories/dumps/schemas'; | ||
import { ReportCategory } from '../common/dto/report-category'; | ||
import axios, { AxiosResponse } from 'axios'; | ||
|
||
@Injectable() | ||
export class AdminService { | ||
|
@@ -76,6 +77,29 @@ export class AdminService { | |
return AdminService.docToFullDump(dump); | ||
} | ||
|
||
async transferReport( | ||
transferReportDto: TransferReportDto, | ||
): Promise<FullReportDto | null> { | ||
const response: AxiosResponse | null = | ||
await this.sendTransferRequest(transferReportDto); | ||
if (response == null) { | ||
return null; | ||
} | ||
|
||
const controle = response.data[Object.keys(response.data)[0]]; | ||
const controleId = response.data[Object.keys(response.data)[1]]; | ||
|
||
const report: Report | null = | ||
await this.reportRepository.updateTransferReport( | ||
transferReportDto.refId, | ||
controle, | ||
controleId, | ||
transferReportDto.email, | ||
); | ||
if (!report) return null; | ||
return AdminService.docToFullReport(report); | ||
} | ||
|
||
private static docToFullDump(dump: Dump): FullDumpDto { | ||
return new FullDumpDto( | ||
dump._id.toString(), | ||
|
@@ -99,8 +123,11 @@ export class AdminService { | |
report.reportLong, | ||
report.reportLat, | ||
report.email, | ||
report.controle, | ||
report.controleId, | ||
report.isVisible, | ||
report.isDeleted, | ||
report.isTransferred, | ||
report.comment, | ||
report.status, | ||
report.reportDate, | ||
|
@@ -136,4 +163,44 @@ export class AdminService { | |
throw new Error(`Invalid report category: ${value}`); | ||
} | ||
} | ||
|
||
async sendTransferRequest( | ||
Ignas-rgb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
transferReportDto: TransferReportDto, | ||
): Promise<AxiosResponse | null> { | ||
let returnValue = null; | ||
const data = JSON.stringify({ | ||
'TL pranešimo ID': transferReportDto.refId, | ||
Turinys: transferReportDto.name, | ||
Platuma: transferReportDto.latitude.toString(), | ||
Ilguma: transferReportDto.longitude.toString(), | ||
Statusas: transferReportDto.status, | ||
'Data ir laikas': transferReportDto.reportDate.toString(), | ||
'Vykdytojo e-mail': transferReportDto.email, | ||
}); | ||
|
||
const config = { | ||
method: 'post', | ||
maxBodyLength: Infinity, | ||
url: process.env['AADIS_URL'], | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
data: data, | ||
}; | ||
|
||
await axios | ||
.request(config) | ||
.then((response) => { | ||
if (response.status == 200) { | ||
returnValue = response; | ||
} else { | ||
returnValue = null; | ||
} | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debugging errors will be challenging since Sentry won't capture these errors, and you'll only find them only in Docker logs. To mitigate this, consider configuring axios |
||
returnValue = null; | ||
}); | ||
return returnValue; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class TransferReportDto { | ||
@ApiProperty() | ||
refId: string; | ||
|
||
@ApiProperty() | ||
name: string; | ||
|
||
@ApiProperty({ format: 'double' }) | ||
longitude: number; | ||
|
||
@ApiProperty({ format: 'double' }) | ||
latitude: number; | ||
|
||
@ApiProperty() | ||
status: string; | ||
|
||
@ApiProperty() | ||
reportDate: Date; | ||
|
||
@ApiProperty() | ||
email: string; | ||
|
||
constructor( | ||
name: string, | ||
refId: string, | ||
longitude: number, | ||
latitude: number, | ||
status: string, | ||
reportDate: Date, | ||
email: string, | ||
) { | ||
this.name = name; | ||
this.refId = refId; | ||
this.longitude = longitude; | ||
this.latitude = latitude; | ||
this.status = status; | ||
this.reportDate = reportDate; | ||
this.email = email; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to pass the entire
TransferReportDto
, or would just theReportID
suffice for this method?