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 (2)
...@@ -670,13 +670,7 @@ export class UsersService { ...@@ -670,13 +670,7 @@ export class UsersService {
validate: boolean validate: boolean
): Promise<PendingStructureDto[]> { ): Promise<PendingStructureDto[]> {
const user = await this.findOne(userEmail); const user = await this.findOne(userEmail);
// Get other users who have made the demand on the same structure
const otherUsers = await this.userModel
.find({ 'pendingStructuresLink.id': { $eq: new Types.ObjectId(structureId) }, email: { $ne: userEmail } })
.exec();
let status = false;
if (!user) { if (!user) {
throw new HttpException('User not found', HttpStatus.NOT_FOUND); throw new HttpException('User not found', HttpStatus.NOT_FOUND);
} }
...@@ -691,22 +685,9 @@ export class UsersService { ...@@ -691,22 +685,9 @@ export class UsersService {
if (validate) { if (validate) {
user.structuresLink.push(new Types.ObjectId(structureId)); user.structuresLink.push(new Types.ObjectId(structureId));
user.unattachedSince = null; user.unattachedSince = null;
// Send validation email
status = true;
// For other users who have made the demand on the same structure
if (otherUsers) {
otherUsers.forEach((otherUser) => {
// Remove the structure id from their demand
otherUser.pendingStructuresLink = otherUser.pendingStructuresLink.filter((item) => {
return !new Types.ObjectId(structureId).equals(item.id);
});
// Send a rejection email
this.sendStructureClaimApproval(otherUser.email, structureName, false);
otherUser.save();
});
}
} }
this.sendStructureClaimApproval(userEmail, structureName, status); // Send validation or rejection email
this.sendStructureClaimApproval(userEmail, structureName, validate);
await user.save(); await user.save();
// Update CNFS label of the structure // Update CNFS label of the structure
await this.structuresService.updateDenormalizedFields(new Types.ObjectId(structureId)); await this.structuresService.updateDenormalizedFields(new Types.ObjectId(structureId));
......