diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts index ddd4e2bd4b5f085d273afbf269210874abd7017f..6fc689024f17f42a152a3697b92f1f8808b4567b 100644 --- a/src/structures/services/structures.service.ts +++ b/src/structures/services/structures.service.ts @@ -39,16 +39,21 @@ export class StructuresService { if (searchString && filters) { return this.structureModel .find({ - $and: [...this.parseFilter(filters), { $text: { $search: searchString }, deletedAt: { $exists: false } }], + $and: [ + ...this.parseFilter(filters), + { $text: { $search: searchString }, deletedAt: { $exists: false }, accountVerified: true }, + ], }) .exec(); } else if (filters) { return this.structureModel - .find({ $and: [{ $or: this.parseFilter(filters), deletedAt: { $exists: false } }] }) + .find({ $and: [{ $or: this.parseFilter(filters), deletedAt: { $exists: false }, accountVerified: true }] }) .exec(); } else { return this.structureModel - .find({ $and: [{ $or: [{ $text: { $search: searchString }, deletedAt: { $exists: false } }] }] }) + .find({ + $and: [{ $or: [{ $text: { $search: searchString }, deletedAt: { $exists: false }, accountVerified: true }] }], + }) .exec(); } } @@ -95,7 +100,7 @@ export class StructuresService { } }) ); - return this.structureModel.find({ deletedAt: { $exists: false } }).exec(); + return this.structureModel.find({ deletedAt: { $exists: false }, accountVerified: true }).exec(); } public async update(idStructure: string, structure: structureDto): Promise<Structure> { @@ -292,4 +297,16 @@ export class StructuresService { }); this.mailerService.send(userEmail, jsonConfig.subject, html); } + + public async updateAfterOwnerVerify(emailUser: string): Promise<Structure> { + const user = await this.userService.findOne(emailUser); + const structureLinked = await this.findOne(user.structuresLink[0]); + const structure = new this.structureModel(structureLinked); + if (!structure) { + throw new HttpException('Invalid structure', HttpStatus.NOT_FOUND); + } + structure.accountVerified = true; + structure.save(); + return structure; + } } diff --git a/src/structures/structures.controller.ts b/src/structures/structures.controller.ts index b301a463f40c505140410986d1d17e69e12e345b..748493ee0caea09ca488b3bab7448ef30dc97b90 100644 --- a/src/structures/structures.controller.ts +++ b/src/structures/structures.controller.ts @@ -26,6 +26,11 @@ export class StructuresController { return this.structureService.search(query.query, body ? body.filters : null); } + @Put('updateAfterOwnerVerify/:id') + public async updateAfterOwnerVerify(@Param('id') id: string, @Body() body: structureDto): Promise<Structure> { + return this.structureService.update(id, body); + } + @Put(':id') @UseGuards(JwtAuthGuard, IsStructureOwnerGuard) @Roles('admin') diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 920a233da69bc25e390303b463de08a8445b668c..28a7bac340fc9596a66066ec49bcf5107deeaba2 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -185,12 +185,13 @@ export class UsersService { * @param userId string * @param token string */ - public async validateUser(userId: string, token: string): Promise<any> { + public async validateUser(userId: string, token: string): Promise<User> { const user = await this.findById(userId); if (user && user.validationToken === token) { user.validationToken = null; user.emailVerified = true; user.save(); + return user; } else { throw new HttpException('Invalid token', HttpStatus.UNAUTHORIZED); }