Commit 23180495 authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files
parents 8b3939d4 31f4997e
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
import { Controller, Get, Req, UseGuards } from '@nestjs/common';
import { Controller, Get, Param, Req, UseGuards } from '@nestjs/common';
import { AdminService } from './admin.service';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { ADMIN_ROLES } from 'src/shared/enum/admin-role.enum';
import { ApiBearerAuth, ApiParam, ApiTags } from '@nestjs/swagger';
import { ADMIN_ROLES, SUPERADMIN_ROLES } from 'src/shared/enum/admin-role.enum';
import { Roles } from 'src/auth/role.decorator';
import { CustomAdminRequest } from 'src/auth/admin/interface/customAdminReq';
import { AuthAdminGuard } from 'src/auth/admin/authAdmin.guard';
@@ -24,4 +24,18 @@ export class AdminController {
      idTown: req.admin?.idTown?.townId || null,
    };
  }

  @UseGuards(AuthAdminGuard)
  @Roles(SUPERADMIN_ROLES)
  @ApiParam({ name: 'idTown', type: Number })
  @Get('admin/:idTown')
  @ApiBearerAuth('jwt')
  async findAllByTown(@Param('idTown') idTown: number) {
    try {
      const admins = await this.adminService.findAllByTown(idTown);
      return admins;
    } catch (e) {
      return e;
    }
  }
}
+19 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Town } from 'src/town/entities/town.entity';
import { ADMIN_ROLE } from 'src/shared/enum/admin-role.enum';
import { GetAdminDto } from './dto/get-admin.dto';

@Injectable()
export class AdminService {
@@ -31,4 +32,22 @@ export class AdminService {
  async updatePassword(email: string, password: string) {
    await this.adminRepository.update({ email }, { password });
  }

  async findAllByTown(idTown : number) : Promise<GetAdminDto[]> {
    const res: any[] = await this.adminRepository
      .createQueryBuilder('admin')
      .leftJoinAndSelect('admin.idTown', 'town')
      .where('admin.idTown = :idTown', { idTown: idTown })
      .getMany();
    const admins: GetAdminDto[] = res.map((admin) :GetAdminDto => {
      return {
        email: admin.email,
        idTown: admin.idTown.townId,
        name: admin.name,
        lastName: admin.lastName,
        status: admin.status
      };
    });
    return admins;
  }
}
+18 −0
Original line number Diff line number Diff line
import { ApiProperty } from "@nestjs/swagger";

export class GetAdminDto {
  @ApiProperty()
  email: string;

  @ApiProperty()
  idTown: number;

  @ApiProperty()
  name: string;

  @ApiProperty()
  lastName: string;

  @ApiProperty()
  status: string;
}
 No newline at end of file
+4 −4
Original line number Diff line number Diff line
import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from 'typeorm';
import { Place } from './place.entity';

@Entity()
export class AvailableDate {
  @PrimaryGeneratedColumn()
  idAvailableDate: number;
  @PrimaryColumn()
  idPlace: number;

  @JoinColumn({ name: 'idPlace' })
  @ManyToOne(() => Place, (place) => place.availableDates, { nullable: false })
  idPlace: Place;
  place: Place;

  @Column()
  startDate: Date;
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ export class Place {
  @OneToMany(() => PointOfInterest, (point) => point.idPoint)
  points: PointOfInterest[];

  @OneToMany(() => AvailableDate, (available) => available.idPlace)
  @OneToMany(() => AvailableDate, (available) => available.place)
  availableDates: AvailableDate[];

  @ManyToMany(() => Category)
Loading