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

Target

Select target project
  • web-et-numerique/factory/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server
1 result
Show changes
Commits on Source (8)
......@@ -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.
### [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.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",
"version": "2.1.0",
"version": "2.1.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......
{
"name": "ram_server",
"private": true,
"version": "2.1.0",
"version": "2.1.1",
"description": "Nest TypeScript starter repository",
"license": "MIT",
"scripts": {
......
......@@ -70,8 +70,7 @@ export class Structure {
contactPhone?: string;
@Prop()
@IsNotEmpty()
contactMail: string;
contactMail?: string;
@Prop()
website: string;
......
......@@ -69,9 +69,9 @@ export class StructuresService {
const results = await this.structuresSearchService.search(text, fields);
const ids = results.map((result) => result.structureId);
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) => {
return Object.keys(elem)[0].length != 0;
return Object.keys(elem)[0]?.length != 0;
});
//TODO: remove useless code ?
......@@ -243,23 +243,6 @@ export class StructuresService {
public async findAll(): Promise<StructureDocument[]> {
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
.find({ deletedAt: { $exists: false }, accountVerified: true })
.populate('structureType')
......@@ -307,29 +290,6 @@ export class StructuresService {
*/
public async findAllFormated(categories: Categories[]): Promise<StructureDocument[]> {
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 (
await this.structureModel
.find({ deletedAt: { $exists: false }, accountVerified: true, $where: 'this.dataShareConsentDate != null' })
......@@ -768,7 +728,7 @@ export class StructuresService {
@Cron(CronExpression.EVERY_DAY_AT_4AM)
public async structuresTasksProcess(): Promise<void> {
this.logger.debug('structuresTasksProcess');
this.logger.log('structuresTasksProcess');
await this.processToBeDeletedStructures().catch((error) => {
this.logger.error(error);
......@@ -1039,7 +999,7 @@ export class StructuresService {
})
),
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 {
const CNFSData = await this.getCNFSStructures();
if (!resinStructure) return 'Could not find structure';
const mathingStructure = this.findMatchingStructure(resinStructure, CNFSData);
if (mathingStructure) {
const matchingStructure = this.findMatchingStructure(resinStructure, CNFSData);
if (matchingStructure) {
// 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';
}
this.logger.debug(`No match found`);
......@@ -1089,7 +1049,7 @@ export class StructuresService {
*/
@Cron(CronExpression.EVERY_WEEK)
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 resinStructures = await this.findAll();
this.logger.debug(`${resinStructures.length} resin structures found`);
......@@ -1098,17 +1058,21 @@ export class StructuresService {
let dismatchCount = 0;
for (const resinStructure of resinStructures) {
const mathingStructure = this.findMatchingStructure(resinStructure, CNFSData);
if (mathingStructure) {
await this.setCNFSid(resinStructure.id, mathingStructure.id);
matchCount++;
const matchingStructure = this.findMatchingStructure(resinStructure, CNFSData);
if (matchingStructure) {
if (await this.setCNFSid(resinStructure.id, matchingStructure.id)) {
matchCount++;
}
// if a corresponing structure has been found but its email is different, we probably will need to update it here.
} else {
await this.setCNFSid(resinStructure.id, '');
dismatchCount++;
if (await this.setCNFSid(resinStructure.id, '')) {
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`;
}
......@@ -1116,8 +1080,11 @@ export class StructuresService {
* Update the idCNFS of a structure with its value of ""
*/
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);
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 });
return this.structureModel.findByIdAndUpdate(new Types.ObjectId(idStructure), deepClone).exec();
}
......
......@@ -869,7 +869,7 @@ export class UsersService {
}
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
if (structure.personalOffers.length === 0) return null;
// Return personal offer if the user has one in this structure
......