Skip to content
Snippets Groups Projects
Select Git revision
  • 42b9e2c54875bed9e1ddf54c1455f64aae7baf1f
  • dev default protected
  • renovate/bitnami-mongodb-8.x
  • renovate/ghcr.io-browserless-chromium-2.x
  • renovate/major-nest-monorepo
  • renovate/luxon-3.x
  • renovate/gouvfr-anct-timetable-to-osm-opening-hours-2.x
  • renovate/major-typescript-eslint-monorepo
  • renovate/npm-11.x
  • renovate/mysql-9.x
  • renovate/mongo-express-1.x
  • renovate/major-jest-monorepo
  • renovate/tsconfig-paths-4.x
  • renovate/jest-junit-16.x
  • renovate/express-5.x
  • renovate/elastic-elasticsearch-8.x
  • renovate/ghost-5.x
  • renovate/elasticsearch-7.x
  • renovate/devdependencies-(non-major)
  • 714-label-cafe-ia
  • master protected
  • v4.0.3
  • v4.0.1
  • v4.0.0
  • v3.4.3
  • v3.4.2
  • v3.4.1
  • v3.4.0
  • v3.3.1
  • v3.3.0
  • v3.2.0
  • v3.1.0
  • v3.0.1
  • v3.0.0
  • v2.5.0
  • v2.4.2
  • v2.4.1
  • v2.4.0
  • v2.3.2
  • v2.3.1
  • v2.3.0
41 results

posts.controller.ts

Blame
  • admin.controller.ts 2.23 KiB
    import { Body } from '@nestjs/common';
    import { Controller, Get, Post, UseGuards } from '@nestjs/common';
    import { ApiOperation } from '@nestjs/swagger';
    import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
    import { StructuresService } from '../structures/services/structures.service';
    import { Roles } from '../users/decorators/roles.decorator';
    import { RolesGuard } from '../users/guards/roles.guard';
    import { UsersService } from '../users/users.service';
    import { PendingStructureDto } from './dto/pending-structure.dto';
    
    @Controller('admin')
    export class AdminController {
      constructor(private usersService: UsersService, private structuresService: StructuresService) {}
    
      @UseGuards(JwtAuthGuard, RolesGuard)
      @Roles('admin')
      @Get('pendingStructures')
      @ApiOperation({ description: 'Get pending structre for validation' })
      public async getPendingAttachments(): Promise<PendingStructureDto[]> {
        const pendingStructure = await this.usersService.getPendingStructures();
        return await Promise.all(
          pendingStructure.map(async (structure) => {
            structure.structureName = (await this.structuresService.findOne(structure.structureId)).structureName;
            return structure;
          })
        );
      }
    
      @UseGuards(JwtAuthGuard, RolesGuard)
      @Roles('admin')
      @Post('validatePendingStructure')
      @ApiOperation({ description: 'Validate structure ownership' })
      public async validatePendingStructure(@Body() pendingStructureDto: PendingStructureDto) {
        const structure = await this.structuresService.findOne(pendingStructureDto.structureId);
        return this.usersService.validatePendingStructure(
          pendingStructureDto.userEmail,
          pendingStructureDto.structureId,
          structure.structureName,
          true
        );
      }
    
      @UseGuards(JwtAuthGuard, RolesGuard)
      @Roles('admin')
      @Post('rejectPendingStructure')
      @ApiOperation({ description: 'Refuse structure ownership' })
      public async refusePendingStructure(@Body() pendingStructureDto: PendingStructureDto) {
        const structure = await this.structuresService.findOne(pendingStructureDto.structureId);
        return this.usersService.validatePendingStructure(
          pendingStructureDto.userEmail,
          pendingStructureDto.structureId,
          structure.structureName,
          false
        );
      }
    }