Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 3x 3x 3x 12x 1x 12x 1x 12x 1x 12x 3x | import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Req, UseGuards, Patch, HttpCode } from '@nestjs/common';
import { OpenHouseService } from '@app/modules/open-houses/open-house.service';
import { CreateOpenHouseDto } from '@app/modules/open-houses/dto/create-open-house.dto';
import { UpdateOpenHouseDto } from '@app/modules/open-houses/dto/update-open-house.dto';
import { JwtAuthGuard } from '@app/common/guards/jwt-auth.guard';
import { RolesGuard } from '@app/common/guards/roles.guard';
import { Roles } from '@app/common/decorators/roles.decorator';
import { User, Role } from '@prisma/client';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
@ApiTags('OpenHouse')
@ApiBearerAuth()
@Controller()
export class OpenHouseController {
constructor(private readonly service: OpenHouseService) {}
@Post('/listings/:id/open-houses')
@HttpCode(201)
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.AGENT, Role.ADMIN)
@ApiOperation({ summary: 'Create open house for a listing', description: 'Roles: AGENT or ADMIN.' })
create(
@Param('id', ParseIntPipe) listingId: number,
@Body() dto: CreateOpenHouseDto,
@Req() req: { user: User },
) {
if (process.env.NODE_ENV === 'test' || process.env.TEST_MODE === '1') {
// Avoid noisy timing logs in production/tests
return this.service.create(listingId, dto, req.user).then((result) => {
// end timing
return result;
});
}
return this.service.create(listingId, dto, req.user);
}
@Get('/listings/:id/open-houses')
@ApiOperation({ summary: 'List open houses for a listing' })
list(@Param('id', ParseIntPipe) listingId: number) {
return this.service.list(listingId);
}
@Delete('/open-houses/:id')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.AGENT, Role.ADMIN)
@ApiOperation({ summary: 'Delete an open house', description: 'Roles: AGENT or ADMIN.' })
remove(@Param('id', ParseIntPipe) id: number, @Req() req: { user: User }) {
return this.service.remove(id, req.user);
}
@Patch('/open-houses/:id')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.AGENT, Role.ADMIN)
@ApiOperation({ summary: 'Update an open house', description: 'Roles: AGENT or ADMIN.' })
update(
@Param('id', ParseIntPipe) id: number,
@Body() dto: UpdateOpenHouseDto,
@Req() req: { user: User },
) {
return this.service.update(id, dto, req.user);
}
@Post('/open-houses/:id/register')
@HttpCode(201)
@UseGuards(JwtAuthGuard)
@ApiOperation({ summary: 'Register for an open house', description: 'Requires authentication.' })
register(
@Param('id', ParseIntPipe) id: number,
@Req() req: { user: User },
) {
return this.service.register(id, req.user);
}
} |