Skip to content

Commit

Permalink
Add optional email parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignas-rgb committed Dec 18, 2024
1 parent 6a2f0f3 commit 75ecf1b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/report/dto/create-report.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
IsLatitude,
IsLongitude,
IsNotEmpty,
IsBoolean
} from 'class-validator';
import { ReportCategory } from '../../common/dto/report-category';

Expand All @@ -24,6 +25,9 @@ export class CreateReportDto {
@IsEmail()
email: string;

@IsBoolean()
automaticEmailsEnabled: boolean;

@ApiProperty({ type: 'array', items: { type: 'string', format: 'binary' } })
images: any[];
}
5 changes: 3 additions & 2 deletions src/repositories/reports/report.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class ReportRepository {
imageUrls: imageUrls,
officerImageUrls: [],
emailFeedbackStage: 1,
automaticEmailsEnabled: createReport.automaticEmailsEnabled,
historyData: [
{
user: createReport.email,
Expand Down Expand Up @@ -197,7 +198,7 @@ export class ReportRepository {
}
}

if(updateReport.status == 'tiriamas' && report.emailFeedbackStage < 2){
if(updateReport.status == 'tiriamas' && report.emailFeedbackStage < 2 && report.automaticEmailsEnabled){
await this.postmarkService.sendInInvestigationReportEmail(report.email, this.postmarkService.generateReportUrl(updateReport.refId));
await this.reportModel.updateOne(
{
Expand All @@ -218,7 +219,7 @@ export class ReportRepository {
historyEntry.edits.push(
new HistoryEditsDto('emailFeedbackStage', '2'),
);
}else if((updateReport.status == 'išspręsta' || updateReport.status == 'nepasitvirtino') && report.emailFeedbackStage < 3){
}else if((updateReport.status == 'išspręsta' || updateReport.status == 'nepasitvirtino') && report.emailFeedbackStage < 3 && report.automaticEmailsEnabled){
await this.postmarkService.sendInvestigatedReportEmail(report.email, this.postmarkService.generateReportUrl(updateReport.refId));
await this.reportModel.updateOne(
{
Expand Down
3 changes: 3 additions & 0 deletions src/repositories/reports/schemas/report.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export class Report {
@Prop({ type: Number, required: true })
emailFeedbackStage: number;

@Prop({ type: Boolean, required: false, default: false })
automaticEmailsEnabled: boolean;

@Prop({
type: [
{
Expand Down

0 comments on commit 75ecf1b

Please sign in to comment.