Skip to content
Snippets Groups Projects
Commit 1fb80471 authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

fix: MR return + issue on delete owner endpoint

parent 0844ab40
No related branches found
No related tags found
3 merge requests!38Recette,!37Dev,!34Feat/add user to structure
......@@ -311,7 +311,7 @@ export class StructuresService {
* Send an email to structure owner's in order to accept or decline a join request
* @param user User
*/
public async sendStructureJoinRequest(user: IUser, structure: StructureDocument): Promise<any> {
public async sendStructureJoinRequest(user: IUser, structure: StructureDocument): Promise<void> {
const config = this.mailerService.config;
const ejsPath = this.mailerService.getTemplateLocation(config.templates.structureJoinRequest.ejs);
const jsonConfig = this.mailerService.loadJsonConfig(config.templates.structureJoinRequest.json);
......
......@@ -141,7 +141,7 @@ export class StructuresController {
@Post(':id/join')
@ApiParam({ name: 'id', type: String, required: true })
public async join(@Param('id') id: string, @Body() user: User): Promise<any> {
public async join(@Param('id') id: string, @Body() user: User): Promise<void> {
// Get structure name
const structure = await this.structureService.findOne(id);
if (!structure) {
......@@ -197,19 +197,20 @@ export class StructuresController {
}
}
@Delete(':id/removeOwner')
@Delete(':id/owner/:userId')
@UseGuards(JwtAuthGuard, IsStructureOwnerGuard)
@Roles('admin')
@ApiParam({ name: 'id', type: String, required: true })
public async removeOwner(@Param('id') id: string, @Body() user: User): Promise<any> {
@ApiParam({ name: 'userId', type: String, required: true })
public async removeOwner(@Param('id') id: string, @Param('userId') userId: string): Promise<void> {
// Get structure
const structure = await this.structureService.findOne(id);
if (!structure) {
throw new HttpException('Invalid Structure', HttpStatus.NOT_FOUND);
}
// Get user
const userFromDb = await this.userService.findOne(user.email);
if (!userFromDb) {
const userFromDb = await this.userService.findById(userId);
if (!userFromDb || !userFromDb.structuresLink.includes(Types.ObjectId(id))) {
throw new HttpException('Invalid User', HttpStatus.NOT_FOUND);
}
this.userService.removeFromStructureLinked(userFromDb.email, id);
......
import { Controller, Get, HttpException, HttpStatus, Param } from '@nestjs/common';
import { ApiParam } from '@nestjs/swagger';
import { TempUser } from './temp-user.schema';
import { TempUserService } from './temp-user.service';
@Controller('temp-user')
......@@ -8,7 +9,7 @@ export class TempUserController {
@Get(':id')
@ApiParam({ name: 'id', type: String, required: true })
public async getTempUser(@Param('id') id: string) {
public async getTempUser(@Param('id') id: string): Promise<TempUser> {
const user = await this.tempUserSercice.findById(id);
if (!user) {
throw new HttpException('User does not exists', HttpStatus.BAD_REQUEST);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment