Skip to content

Commit

Permalink
fix: mise à jour du Suivi
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Jul 12, 2021
1 parent d130394 commit e9ff616
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { MessageSmsStatus } from ".";

export const MESSAGE_SMS_STATUS: { [key: number]: MessageSmsStatus } = {
0: "ON_HOLD",
1: "SENT_AND_RECEIVED",
2: "SENT_AND_NOT_RECEIVED",
3: "IN_PROGRESS",
4: "FAILURE",
5: "EXPIRED",
6: "DISABLED",
};
8 changes: 5 additions & 3 deletions packages/backend/src/config/domifaConfig.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ export function loadEnvWithPreset({
defaultEnv ?? domifaConfigFileLoader.loadEnvFile(envFileName);

const presetEnvFileName =
domifaEnv["DOMIFA_ENV_PRESET"] ?? process.env["DOMIFA_ENV_PRESET"];
domifaEnv.DOMIFA_ENV_PRESET ?? process.env.DOMIFA_ENV_PRESET;

let domifaPresetEnv = domifaConfigFileLoader.loadEnvFile(
path.join(".env.preset", presetEnvFileName)
);

const presetParentEnvFileName = domifaPresetEnv["DOMIFA_ENV_PRESET_PARENT"];
console.log(domifaPresetEnv);

const presetParentEnvFileName = domifaPresetEnv.DOMIFA_ENV_PRESET_PARENT;

if (presetParentEnvFileName) {
const domifaPresetParentEnv = domifaConfigFileLoader.loadEnvFile(
Expand All @@ -55,7 +57,7 @@ export function loadEnvWithPreset({
...domifaPresetEnv, // default values
...domifaEnv, // empty in dist env (but used in local environments)
};
if (merged["DOMIFA_ENV_PRIORITY"] === "process.env") {
if (merged.DOMIFA_ENV_PRIORITY === "process.env") {
// DIST: global environment variables overrides files config
appLogger.warn('[loadEnvWithPreset] "process.env" overrides files config');
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as dotenv from "dotenv";
import * as fs from "fs";
import * as path from "path";
import { DomifaEnv } from "./model";
import SMTPTransport = require("nodemailer/lib/smtp-transport");

export const domifaConfigFileLoader = {
loadEnvFile,
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/config/model/DomifaEnv.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ export type DomifaEnv = {
DOMIFA_CRON_MONITORING_CLEANER_AUTO_RUN_STARTUP: string;
DOMIFA_SMS_ENABLE: string;
DOMIFA_SMS_API_KEY: string;
DOMIFA_ENV_PRESET_PARENT: string;
DOMIFA_PHONE_NUMBER_REDIRECT_ALL_TO: string;
};
4 changes: 2 additions & 2 deletions packages/backend/src/interactions/interactions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CurrentUsager } from "../auth/current-usager.decorator";
import { CurrentUser } from "../auth/current-user.decorator";
import { UsagerAccessGuard } from "../auth/guards/usager-access.guard";
import { interactionRepository } from "../database";
import { SmsService } from "../sms/services/sms.service";
import { MessageSmsService } from "../sms/services/message-sms.service";
import { UsagersService } from "../usagers/services/usagers.service";
import { AppAuthUser, UsagerLight } from "../_common/model";
import { InteractionType } from "../_common/model/interaction";
Expand All @@ -31,7 +31,7 @@ export class InteractionsController {
constructor(
private readonly interactionsService: InteractionsService,
private readonly usagersService: UsagersService,
private readonly smsService: SmsService
private readonly smsService: MessageSmsService
) {}

@Post(":usagerRef")
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/interactions/interactions.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { forwardRef, Module } from "@nestjs/common";
import { SmsService } from "../sms/services/sms.service";
import { MessageSmsService } from "../sms/services/message-sms.service";
import { SmsModule } from "../sms/sms.module";
import { StructuresModule } from "../structures/structure.module";
import { UsagersModule } from "../usagers/usagers.module";
Expand All @@ -16,6 +16,6 @@ import { InteractionsService } from "./interactions.service";
forwardRef(() => StructuresModule),
forwardRef(() => SmsModule),
],
providers: [InteractionsService, SmsService],
providers: [InteractionsService, MessageSmsService],
})
export class InteractionsModule {}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SuiviSmsDto } from "./../suivi-sms.dto";
import { HttpService, Injectable } from "@nestjs/common";
import { AxiosError } from "axios";
import { Repository } from "typeorm";
Expand All @@ -10,6 +11,7 @@ import {
MessageSmsSendResponse,
MESSAGE_SMS_RESPONSE_ERRORS,
} from "../../_common/model/message-sms";
import { MESSAGE_SMS_STATUS } from "../../_common/model/message-sms/MESSAGE_SMS_STATUS.const";

@Injectable()
export class MessageSmsSenderService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,52 @@
import moment = require("moment");
import { Injectable } from "@nestjs/common";
import { Repository } from "typeorm";
import { Repository, ReturningStatementNotSupportedError } from "typeorm";
import { appTypeormManager, structureRepository } from "../../database";
import { MessageSmsTable } from "../../database/entities/message-sms/MessageSmsTable.typeorm";
import { messageSmsRepository } from "../../database/services/message-sms";
import { InteractionDto } from "../../interactions/interactions.dto";
import { appLogger } from "../../util";
import { AppAuthUser, UsagerLight } from "../../_common/model";
import { MessageSms } from "../../_common/model/message-sms";
import { StructureSmsParams } from "./../../_common/model/structure/StructureSmsParams.type";
import { StructureSmsParams } from "../../_common/model/structure/StructureSmsParams.type";
import { generateSmsInteraction } from "./generators";
import { MESSAGE_SMS_STATUS } from "../../_common/model/message-sms/MESSAGE_SMS_STATUS.const";
import { SuiviSmsDto } from "../suivi-sms.dto";

@Injectable()
export class SmsService {
export class MessageSmsService {
// Délai entre chaque message envoyé
private messageSmsRepository: Repository<MessageSmsTable>;

constructor() {
public constructor() {
this.messageSmsRepository =
appTypeormManager.getRepository(MessageSmsTable);
}

public async updateMessageSmsStatut(suiviSms: SuiviSmsDto) {
const sms = await messageSmsRepository.findOne({
responseId: suiviSms.id_accuse,
});

if (!sms) {
appLogger.warn(
`[UPDATE-SMS-STATUS] Sms not found : ${suiviSms.id_message}`,
{
sentryBreadcrumb: true,
}
);
return;
}

return messageSmsRepository.updateOne(
{ responseId: suiviSms.id_accuse },
{
status: MESSAGE_SMS_STATUS[suiviSms.statut],
lastUpdate: new Date(),
}
);
}

// Suppression d'un SMS si le courrier a été distribué
public async deleteSmsInteractionOut(
usager: UsagerLight,
Expand Down
5 changes: 3 additions & 2 deletions packages/backend/src/sms/sms.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import { DomifaGuard } from "../auth/guards/domifa.guard";
import { UsagerAccessGuard } from "../auth/guards/usager-access.guard";
import { StructuresService } from "../structures/services/structures.service";
import { AppAuthUser } from "../_common/model";
import { SmsService } from "./services/sms.service";
import { MessageSmsService } from "./services/message-sms.service";
import { SpotHitPushDecorator } from "./SpotHitPushDecorator";
import { SuiviSmsDto } from "./suivi-sms.dto";

@Controller("sms")
@ApiTags("sms")
export class SmsController {
constructor(
private readonly smsService: SmsService,
private readonly smsService: MessageSmsService,
private readonly structureService: StructuresService
) {}

Expand All @@ -47,6 +47,7 @@ export class SmsController {
public async getHello(@SpotHitPushDecorator() suiviSmsDto: SuiviSmsDto) {
// URL de retour de l'API Spot-Hit pour mettre à jour le statut d'un SMS

this.smsService.updateMessageSmsStatut(suiviSmsDto);
console.log(suiviSmsDto);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/sms/sms.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { UsagersModule } from "../usagers/usagers.module";
import { CronSmsInteractionSenderService } from "./services/cron-sms-interaction-sender.service";

import { MessageSmsSenderService } from "./services/message-sms-sender.service";
import { SmsService } from "./services/sms.service";
import { MessageSmsService } from "./services/message-sms.service";
import { SmsController } from "./sms.controller";

@Module({
controllers: [SmsController],
exports: [
SmsService,
MessageSmsService,
CronSmsInteractionSenderService,
MessageSmsSenderService,
],
Expand All @@ -21,7 +21,7 @@ import { SmsController } from "./sms.controller";
forwardRef(() => UsagersModule),
],
providers: [
SmsService,
MessageSmsService,
CronSmsInteractionSenderService,
MessageSmsSenderService,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export const generateMotifLabel = (decision: UsagerDecision): string => {
return "";
}

console.log(decision);

let motif = "";
if (decision.statut === "REFUS" || decision.statut === "RADIE") {
if (decision.motif === "AUTRE") {
Expand Down

0 comments on commit e9ff616

Please sign in to comment.