Skip to content

Commit

Permalink
Merge pull request #39 from w3bdesign/frontend
Browse files Browse the repository at this point in the history
Customer Frontend
  • Loading branch information
w3bdesign authored Nov 20, 2024
2 parents 6a2e8f4 + f4aa8c7 commit d3b9210
Show file tree
Hide file tree
Showing 18 changed files with 6,392 additions and 121 deletions.
13 changes: 12 additions & 1 deletion backend/src/bookings/bookings.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,56 @@ import { Roles } from "../auth/decorators/roles.decorator";
import { UserRole } from "../users/entities/user.entity";

@Controller("bookings")
@UseGuards(JwtAuthGuard, RolesGuard)
export class BookingsController {
constructor(private readonly bookingsService: BookingsService) {}

@Get("upcoming/count")
async getUpcomingCount() {
return { count: await this.bookingsService.getUpcomingCount() };
}

@Post()
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.CUSTOMER, UserRole.ADMIN)
async create(@Body() createBookingDto: CreateBookingDto) {
const booking = await this.bookingsService.create(createBookingDto);
return BookingResponseDto.fromEntity(booking);
}

@Get("upcoming")
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.EMPLOYEE, UserRole.ADMIN)
async findUpcoming() {
const bookings = await this.bookingsService.findUpcoming();
return BookingResponseDto.fromEntities(bookings);
}

@Get("customer/:customerId")
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.CUSTOMER, UserRole.ADMIN)
async findByCustomer(@Param("customerId") customerId: string) {
const bookings = await this.bookingsService.findByCustomer(customerId);
return BookingResponseDto.fromEntities(bookings);
}

@Get("employee/:employeeId")
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.EMPLOYEE, UserRole.ADMIN)
async findByEmployee(@Param("employeeId") employeeId: string) {
const bookings = await this.bookingsService.findByEmployee(employeeId);
return BookingResponseDto.fromEntities(bookings);
}

@Get(":id")
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.CUSTOMER, UserRole.EMPLOYEE, UserRole.ADMIN)
async findOne(@Param("id") id: string) {
const booking = await this.bookingsService.findOne(id);
return BookingResponseDto.fromEntity(booking);
}

@Put(":id")
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.CUSTOMER, UserRole.EMPLOYEE, UserRole.ADMIN)
async update(
@Param("id") id: string,
Expand All @@ -68,6 +78,7 @@ export class BookingsController {
}

@Put(":id/cancel")
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.CUSTOMER, UserRole.EMPLOYEE, UserRole.ADMIN)
async cancel(
@Param("id") id: string,
Expand Down
10 changes: 10 additions & 0 deletions backend/src/bookings/bookings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,14 @@ export class BookingsService {
order: { startTime: "ASC" },
});
}

async getUpcomingCount(): Promise<number> {
const now = new Date();
return this.bookingRepository.count({
where: {
startTime: MoreThan(now),
status: BookingStatus.CONFIRMED,
},
});
}
}
Loading

0 comments on commit d3b9210

Please sign in to comment.