diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts index 8ae5037c8c3c2107f59cf70ea34ae4ec4851804e..ad300fffffce1c8277578fbb624ff8fda7bc292e 100644 --- a/src/structures/services/structures.service.ts +++ b/src/structures/services/structures.service.ts @@ -13,6 +13,7 @@ import { Cron, CronExpression } from '@nestjs/schedule'; import { DateTime } from 'luxon'; import { IUser } from '../../users/interfaces/user.interface'; import * as _ from 'lodash'; +import { OwnerDto } from '../../users/dto/owner.dto'; @Injectable() export class StructuresService { @@ -350,7 +351,7 @@ export class StructuresService { public async findWithOwners( idStructure: string, emailUser: string - ): Promise<{ structure: Structure; owners: string[] }> { + ): Promise<{ structure: Structure; owners: OwnerDto[] }> { const structure = await this.findOne(idStructure); if (!structure) { throw new HttpException('Invalid structure id', HttpStatus.BAD_REQUEST); diff --git a/src/users/dto/owner.dto.ts b/src/users/dto/owner.dto.ts new file mode 100644 index 0000000000000000000000000000000000000000..d9f28ae9dd30becb286130968cc247996ffe8c09 --- /dev/null +++ b/src/users/dto/owner.dto.ts @@ -0,0 +1,11 @@ +import { IsEmail, IsNotEmpty, IsString } from 'class-validator'; + +export class OwnerDto { + @IsNotEmpty() + @IsEmail() + email: string; + + @IsNotEmpty() + @IsString() + id: string; +} diff --git a/src/users/users.service.ts b/src/users/users.service.ts index e9bf74b9b9ae7a5d53491e7f2394d0e4a79b8f52..5d741befb07175afe6f3244f37a4e42b89692c11 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -11,6 +11,7 @@ import { MailerService } from '../mailer/mailer.service'; import { IUser } from './interfaces/user.interface'; import { EmailChangeDto } from './dto/change-email.dto'; import { PendingStructureDto } from '../admin/dto/pending-structure.dto'; +import { OwnerDto } from './dto/owner.dto'; @Injectable() export class UsersService { @@ -479,14 +480,17 @@ export class UsersService { return user.deleteOne(); } - public async getStructureOwnersMails(structureId: string, emailUser: string): Promise<string[]> { + public async getStructureOwnersMails(structureId: string, emailUser: string): Promise<OwnerDto[]> { const users = await this.userModel .find({ structuresLink: Types.ObjectId(structureId), email: { $ne: emailUser } }) .exec(); - const usersMail: string[] = []; + const owners: OwnerDto[] = []; users.forEach((user) => { - usersMail.push(user.email); + const userProfile = new OwnerDto(); + userProfile.email = user.email; + userProfile.id = user._id; + owners.push(userProfile); }); - return usersMail; + return owners; } }