Skip to content

Commit

Permalink
Ajout d'un message département + bug ip 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentlaine committed Oct 17, 2024
1 parent 1baf5e5 commit f3d72c3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/core/interceptor/logger.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class LoggerInterceptor implements NestInterceptor {
*/
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
const id = crypto.randomBytes(8).toString('hex');
const req = context.getArgByIndex(0);
const req = context.switchToHttp().getRequest();
const body = { ...req.body };
this._logger.log(
`REQUEST - ${id} - ${req.ip} - ${req.session?.user?.email} - ${
Expand Down
5 changes: 3 additions & 2 deletions src/subscriptions/subscriptions.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Delete, Get, HttpCode, Param, Post, Req, UseGuards } from '@nestjs/common';
import { Body, Controller, Delete, Get, HttpCode, Ip, Param, Post, Req, UseGuards } from '@nestjs/common';
import { SubscriptionsService } from './subscriptions.service';
import { ApiExcludeController, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { CreateSubscriptionDto } from './dto/create_subscription.dto';
Expand All @@ -19,10 +19,11 @@ export class SubscriptionsController {
async create(
@Req() req,
@Body() createSubscriptionsDto: CreateSubscriptionDto,
@Ip() ip: string
): Promise<SubscriptionDto> {
return this.subscriptionsService.create(
createSubscriptionsDto,
req,
ip,
);
}

Expand Down
22 changes: 19 additions & 3 deletions src/subscriptions/subscriptions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export class SubscriptionsService {
});
}

async create(createSubscriptionDto: CreateSubscriptionDto, req: any): Promise<any> {
async create(createSubscriptionDto: CreateSubscriptionDto, ip: string): Promise<any> {
const subscription = <any>createSubscriptionDto;
subscription.ip = req.ip;
subscription.ip = ip;

if (subscription.commune) {
const commune = this.communesService.getCommune(subscription.commune);
Expand Down Expand Up @@ -83,7 +83,7 @@ export class SubscriptionsService {
} : {
lon: subscription.lon,
lat: subscription.lat,
}
};
const subscriptionExists = await this.abonnementMailRepository.exists({
where: whereClause,
});
Expand Down Expand Up @@ -234,6 +234,7 @@ export class SubscriptionsService {
erreur: 0,
nouveau: 0,
mail_envoye: 0,
departements: [],
};

const subscriptions = await this.abonnementMailRepository.find({
Expand All @@ -254,16 +255,19 @@ export class SubscriptionsService {
if (subscription.typesEau.includes('AEP') && AEP && subscription.situation?.AEP !== AEP) {
stats[AEP]++;
situationUpdated = true;
this.addStatDepartement(stats.departements, subscription.commune);
}

if (subscription.typesEau.includes('SOU') && SOU && subscription.situation?.SOU !== SOU) {
stats[SOU]++;
situationUpdated = true;
this.addStatDepartement(stats.departements, subscription.commune);
}

if (subscription.typesEau.includes('SUP') && SUP && subscription.situation?.SUP !== SUP) {
stats[SUP]++;
situationUpdated = true;
this.addStatDepartement(stats.departements, subscription.commune);
}

if (situationUpdated) {
Expand Down Expand Up @@ -300,6 +304,14 @@ export class SubscriptionsService {
await this.sendMattermostNotification(stats);
}

addStatDepartement(departements: string[], commune: string) {
const depCode = commune >= '97' ? commune.slice(0, 3) : commune.slice(0, 2);
if (departements.findIndex(d => d === depCode) >= 0) {
return;
}
departements.push(depCode);
}

async sendMattermostNotification(stats) {
const sentences = [];
if (stats.mail_envoye) {
Expand Down Expand Up @@ -338,6 +350,10 @@ export class SubscriptionsService {
sentences.push(`- **${stats.erreur}** usagers sont en erreur 🧨`);
}

if (stats.departements?.length > 0) {
sentences.push(`- **${stats.departements.join(', ')}** départements concernés 🗺️`);
}

const message = sentences.join('\n');
await this.mattermostService.sendMessage(message);
}
Expand Down
17 changes: 0 additions & 17 deletions src/zones/entities/arrete_cadre.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,6 @@ export class ArreteCadre extends BaseEntity {
// })
// statut: StatutArreteCadre;

// @Column('enum', {
// name: 'communeNiveauGraviteMax',
// enum: ['all', 'aep', 'none'],
// nullable: true,
// })
// communeNiveauGraviteMax: CommuneNiveauGraviteMax;

@Column({ nullable: true })
niveauGraviteSpecifiqueEap: boolean;

// @Column('enum', {
// name: 'ressourceEapCommunique',
// enum: ['esu', 'eso', 'max'],
// nullable: true,
// })
// ressourceEapCommunique: RessourceEapCommunique;

@ManyToMany(
() => ArreteRestriction,
(ArreteRestriction) => ArreteRestriction.arretesCadre,
Expand Down

0 comments on commit f3d72c3

Please sign in to comment.