Skip to content
Snippets Groups Projects
Commit 638ed62b authored by Hugo NOUTS's avatar Hugo NOUTS
Browse files

Merge branch 'fix/rdvs-meeting-opened' into 'dev'

:fire: Removed call to rdvs api since api.consiller-num has meeting infos

See merge request !270
parents 824f3a18 65d6ad0e
No related branches found
No related tags found
2 merge requests!272V2.1.3,!270🔥 Removed call to rdvs api since api.consiller-num has meeting infos
......@@ -13,6 +13,7 @@ export interface CNFSStructure {
services: string;
conditions_access: string;
labels_nationaux: string;
prise_rdv?: string;
pivot?: string;
horaires?: string;
site_web?: string;
......
......@@ -1058,7 +1058,7 @@ export class StructuresService {
if (!resinStructure) return 'Could not find structure';
const matchingStructure = this.findMatchingStructure(resinStructure, CNFSData);
if (matchingStructure) {
if (matchingStructure && matchingStructure.prise_rdv) {
try {
const result = await this.setCNFSid(resinStructure.id, matchingStructure.structureId);
if (result) {
......@@ -1089,7 +1089,7 @@ export class StructuresService {
for (const resinStructure of resinStructures) {
const matchingStructure = this.findMatchingStructure(resinStructure, CNFSData);
if (matchingStructure) {
if (matchingStructure && matchingStructure.prise_rdv) {
try {
const result = await this.setCNFSid(resinStructure.id, matchingStructure.structureId);
if (result) {
......@@ -1120,26 +1120,7 @@ export class StructuresService {
*/
public async setCNFSid(idStructure: string, idCNFS: string): Promise<Structure> {
const oldStructure = await this.findOne(idStructure);
// Call the rdvs API to check if the idCNFS is open for meetings
try {
const apiResponse = await lastValueFrom(
this.httpService.get(`https://www.rdv-aide-numerique.fr/public_api/public_links?territory=CN`)
);
const matchingExternalIds = apiResponse.data.public_links.filter((item) => item.external_id === idCNFS);
if (matchingExternalIds.length === 0) {
this.logger.warn(`CNFS id '${idCNFS}' is not open for meetings`);
if (oldStructure.idCNFS) {
this.logger.warn(`Cleaning old CNFS id '${oldStructure.idCNFS}'`);
const setCnfsToNull = Object.assign(oldStructure, { idCNFS: '' });
return this.structureModel.findByIdAndUpdate(new Types.ObjectId(idStructure), setCnfsToNull).exec();
}
return null;
}
} catch (error) {
this.logger.warn(`Error while checking CNFS id '${idCNFS}' for meetings: ${error.message}`);
return null;
}
// no need for an update if the cnfs id match and is already known (in order to not mess with the structure activity recording when it was lastly updated for mail inquiries)
if (oldStructure.idCNFS === idCNFS) {
return null;
......
......@@ -1268,6 +1268,7 @@ export const mockCNFSStructures: Array<CNFSStructure> = [
id: '62866838cdc04606eb14ee90',
structureId: '62866838cdc04606eb14ee90',
nom: 'Centre social de Brignais',
prise_rdv: 'https://www.rdv-aide-numerique.fr/org/100000',
commune: 'BRIGNAIS',
code_postal: '69530',
adresse: '28 BD DE SCHWEIGHOUSE',
......@@ -1290,6 +1291,7 @@ export const mockCNFSStructures: Array<CNFSStructure> = [
id: '62866909cdc04606eb14ee95',
structureId: '62866909cdc04606eb14ee95',
nom: 'Plateforme Emploi et Cohésion Sociale',
prise_rdv: 'https://www.rdv-aide-numerique.fr/org/100000',
commune: 'BRIGNAIS',
code_postal: '69530',
adresse: '24 Rue des Jardins',
......@@ -1310,6 +1312,7 @@ export const mockCNFSStructures: Array<CNFSStructure> = [
structureId: '62872e94cdc04606eb14ef09',
nom: 'Communauté de Communes du Chemin des Dames',
commune: 'CRAONNE',
prise_rdv: 'https://www.rdv-aide-numerique.fr/org/100000',
// Wrong CP
code_postal: '02160',
adresse: "1 RUE DE L'EGLISE",
......@@ -1330,6 +1333,7 @@ export const mockCNFSStructures: Array<CNFSStructure> = [
structureId: '62866838cdc04606eb22ff11',
nom: 'Pwet',
commune: 'BRIGNAIS',
prise_rdv: 'https://www.rdv-aide-numerique.fr/org/100000',
// Corect CP
code_postal: '69530',
adresse: '28 BD DE SCHWEIGHOUSE',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment