Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • web-et-numerique/factory/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server
1 result
Select Git revision
Show changes
Commits on Source (8)
...@@ -2,6 +2,14 @@ ...@@ -2,6 +2,14 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [2.1.1](https://forge.grandlyon.com/web-et-numerique/factory/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server/compare/v2.1.0...v2.1.1) (2023-01-26)
### Bug Fixes
* **CNFS:** idCNFS import updates structure only if needed ([05aa070](https://forge.grandlyon.com/web-et-numerique/factory/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server/commit/05aa070a4abf91b1074483e2cf04cf48fb5d2bc5))
* missing data in structure admin (optional email) ([eac378d](https://forge.grandlyon.com/web-et-numerique/factory/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server/commit/eac378d3597c8065908af40f11204e111ecfc4a4))
## [2.1.0](https://forge.grandlyon.com/web-et-numerique/factory/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server/compare/v2.0.3...v2.1.0) (2023-01-05) ## [2.1.0](https://forge.grandlyon.com/web-et-numerique/factory/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server/compare/v2.0.3...v2.1.0) (2023-01-05)
### [2.0.3](https://forge.grandlyon.com/web-et-numerique/factory/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server/compare/v2.0.2...v2.0.3) (2023-01-05) ### [2.0.3](https://forge.grandlyon.com/web-et-numerique/factory/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server/compare/v2.0.2...v2.0.3) (2023-01-05)
......
{ {
"name": "ram_server", "name": "ram_server",
"version": "2.1.0", "version": "2.1.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
......
{ {
"name": "ram_server", "name": "ram_server",
"private": true, "private": true,
"version": "2.1.0", "version": "2.1.1",
"description": "Nest TypeScript starter repository", "description": "Nest TypeScript starter repository",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
......
...@@ -70,8 +70,7 @@ export class Structure { ...@@ -70,8 +70,7 @@ export class Structure {
contactPhone?: string; contactPhone?: string;
@Prop() @Prop()
@IsNotEmpty() contactMail?: string;
contactMail: string;
@Prop() @Prop()
website: string; website: string;
......
...@@ -69,9 +69,9 @@ export class StructuresService { ...@@ -69,9 +69,9 @@ export class StructuresService {
const results = await this.structuresSearchService.search(text, fields); const results = await this.structuresSearchService.search(text, fields);
const ids = results.map((result) => result.structureId); const ids = results.map((result) => result.structureId);
let structures; let structures;
let multipleFilters = filters ? filters.filter((elem) => Object.keys(elem)[0].length == 0) : null; let multipleFilters = filters ? filters.filter((elem) => Object.keys(elem)[0]?.length == 0) : null;
filters = filters?.filter((elem) => { filters = filters?.filter((elem) => {
return Object.keys(elem)[0].length != 0; return Object.keys(elem)[0]?.length != 0;
}); });
//TODO: remove useless code ? //TODO: remove useless code ?
...@@ -243,23 +243,6 @@ export class StructuresService { ...@@ -243,23 +243,6 @@ export class StructuresService {
public async findAll(): Promise<StructureDocument[]> { public async findAll(): Promise<StructureDocument[]> {
this.logger.debug('findAll'); this.logger.debug('findAll');
const structures = await this.structureModel.find({ deletedAt: { $exists: false } }).exec();
// Update structures coord and address before sending them
await Promise.all(
structures.map((structure: StructureDocument) => {
// If structre has no address, add it
if (!structure.address || structure.coord.length <= 0) {
return this.getStructurePosition(structure).then((position: StructureDocument) => {
this.structureModel
.findByIdAndUpdate(new Types.ObjectId(structure._id), {
address: position.address,
coord: position.coord,
})
.exec();
});
}
})
);
return this.structureModel return this.structureModel
.find({ deletedAt: { $exists: false }, accountVerified: true }) .find({ deletedAt: { $exists: false }, accountVerified: true })
.populate('structureType') .populate('structureType')
...@@ -307,29 +290,6 @@ export class StructuresService { ...@@ -307,29 +290,6 @@ export class StructuresService {
*/ */
public async findAllFormated(categories: Categories[]): Promise<StructureDocument[]> { public async findAllFormated(categories: Categories[]): Promise<StructureDocument[]> {
this.logger.debug('Find all formated structures, only returning structures who consented to data sharing'); this.logger.debug('Find all formated structures, only returning structures who consented to data sharing');
const structures = await this.structureModel
.find({ deletedAt: { $exists: false } })
.populate('personalOffers')
.populate('structureType')
.exec();
// Update structures coord and address before sending them
await Promise.all(
structures.map((structure: StructureDocument) => {
// If structure has no address, add it
if (!structure.address || structure.coord.length <= 0) {
return this.getStructurePosition(structure).then((position: StructureDocument) => {
this.structureModel
.findByIdAndUpdate(new Types.ObjectId(structure._id), {
address: position.address,
coord: position.coord,
})
.populate('personalOffers')
.populate('structureType')
.exec();
});
}
})
);
return ( return (
await this.structureModel await this.structureModel
.find({ deletedAt: { $exists: false }, accountVerified: true, $where: 'this.dataShareConsentDate != null' }) .find({ deletedAt: { $exists: false }, accountVerified: true, $where: 'this.dataShareConsentDate != null' })
...@@ -768,7 +728,7 @@ export class StructuresService { ...@@ -768,7 +728,7 @@ export class StructuresService {
@Cron(CronExpression.EVERY_DAY_AT_4AM) @Cron(CronExpression.EVERY_DAY_AT_4AM)
public async structuresTasksProcess(): Promise<void> { public async structuresTasksProcess(): Promise<void> {
this.logger.debug('structuresTasksProcess'); this.logger.log('structuresTasksProcess');
await this.processToBeDeletedStructures().catch((error) => { await this.processToBeDeletedStructures().catch((error) => {
this.logger.error(error); this.logger.error(error);
...@@ -1039,7 +999,7 @@ export class StructuresService { ...@@ -1039,7 +999,7 @@ export class StructuresService {
}) })
), ),
tap((response) => { tap((response) => {
this.logger.debug(`${response.length} CNFS rhone structures containing found`); this.logger.debug(`${response.length} CNFS rhone structures found`);
}) })
); );
...@@ -1073,10 +1033,10 @@ export class StructuresService { ...@@ -1073,10 +1033,10 @@ export class StructuresService {
const CNFSData = await this.getCNFSStructures(); const CNFSData = await this.getCNFSStructures();
if (!resinStructure) return 'Could not find structure'; if (!resinStructure) return 'Could not find structure';
const mathingStructure = this.findMatchingStructure(resinStructure, CNFSData); const matchingStructure = this.findMatchingStructure(resinStructure, CNFSData);
if (mathingStructure) { if (matchingStructure) {
// if a corresponing structure has been found but its email is different, we probably will need to update it here. // if a corresponing structure has been found but its email is different, we probably will need to update it here.
await this.setCNFSid(resinStructure.id, mathingStructure.id); await this.setCNFSid(resinStructure.id, matchingStructure.id);
return 'A match has been found, updating CNFSid'; return 'A match has been found, updating CNFSid';
} }
this.logger.debug(`No match found`); this.logger.debug(`No match found`);
...@@ -1089,7 +1049,7 @@ export class StructuresService { ...@@ -1089,7 +1049,7 @@ export class StructuresService {
*/ */
@Cron(CronExpression.EVERY_WEEK) @Cron(CronExpression.EVERY_WEEK)
public async bindCNFSids(): Promise<string> { public async bindCNFSids(): Promise<string> {
this.logger.debug(`bind CNFS ids to resin structures`); this.logger.log('bind CNFS ids to resin structures process');
const CNFSData = await this.getCNFSStructures(); const CNFSData = await this.getCNFSStructures();
const resinStructures = await this.findAll(); const resinStructures = await this.findAll();
this.logger.debug(`${resinStructures.length} resin structures found`); this.logger.debug(`${resinStructures.length} resin structures found`);
...@@ -1098,17 +1058,21 @@ export class StructuresService { ...@@ -1098,17 +1058,21 @@ export class StructuresService {
let dismatchCount = 0; let dismatchCount = 0;
for (const resinStructure of resinStructures) { for (const resinStructure of resinStructures) {
const mathingStructure = this.findMatchingStructure(resinStructure, CNFSData); const matchingStructure = this.findMatchingStructure(resinStructure, CNFSData);
if (mathingStructure) { if (matchingStructure) {
await this.setCNFSid(resinStructure.id, mathingStructure.id); if (await this.setCNFSid(resinStructure.id, matchingStructure.id)) {
matchCount++; matchCount++;
}
// if a corresponing structure has been found but its email is different, we probably will need to update it here. // if a corresponing structure has been found but its email is different, we probably will need to update it here.
} else { } else {
await this.setCNFSid(resinStructure.id, ''); if (await this.setCNFSid(resinStructure.id, '')) {
dismatchCount++; dismatchCount++;
}
} }
} }
this.logger.debug(`${matchCount} out of ${dismatchCount} structures affected with a idCNFS`); this.logger.log(
`${matchCount} structures affected with a idCNFS (${dismatchCount} structures with idCNFS emptied)`
);
return `${matchCount} structures affected`; return `${matchCount} structures affected`;
} }
...@@ -1116,8 +1080,11 @@ export class StructuresService { ...@@ -1116,8 +1080,11 @@ export class StructuresService {
* Update the idCNFS of a structure with its value of "" * Update the idCNFS of a structure with its value of ""
*/ */
public async setCNFSid(idStructure: string, idCNFS: string): Promise<Structure> { public async setCNFSid(idStructure: string, idCNFS: string): Promise<Structure> {
this.logger.debug(`A resin structure '${idStructure}' matched with a CNFS one, updating its idCNFS '${idCNFS}'`);
const oldStructure = await this.findOne(idStructure); const oldStructure = await this.findOne(idStructure);
if (oldStructure.idCNFS || '' == idCNFS) {
return null;
}
this.logger.log(`A resin structure '${idStructure}' matched with a CNFS one, updating its idCNFS '${idCNFS}'`);
const deepClone = Object.assign(oldStructure, { idCNFS }); const deepClone = Object.assign(oldStructure, { idCNFS });
return this.structureModel.findByIdAndUpdate(new Types.ObjectId(idStructure), deepClone).exec(); return this.structureModel.findByIdAndUpdate(new Types.ObjectId(idStructure), deepClone).exec();
} }
......
...@@ -869,7 +869,7 @@ export class UsersService { ...@@ -869,7 +869,7 @@ export class UsersService {
} }
public getPersonalOfferInStructure(user: User, structure: Structure): PersonalOfferDocument { public getPersonalOfferInStructure(user: User, structure: Structure): PersonalOfferDocument {
if (!user.job.hasPersonalOffer || user.personalOffers.length === 0) return null; if (!user.job?.hasPersonalOffer || user.personalOffers.length === 0) return null;
// Check if structure has personal offers // Check if structure has personal offers
if (structure.personalOffers.length === 0) return null; if (structure.personalOffers.length === 0) return null;
// Return personal offer if the user has one in this structure // Return personal offer if the user has one in this structure
......