Skip to content

Commit

Permalink
[Implement][EF-174-176][ConsultantBooking]Consultant staff view list …
Browse files Browse the repository at this point in the history
…and view detail booking API
  • Loading branch information
MinhhTien authored and nghiavohuynhdai committed Mar 3, 2024
1 parent f8d164d commit b2d0093
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/common/contracts/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ export const Errors: Record<string, ErrorResponse> = {
message: 'Không tìm thấy nhân viên.',
httpStatus: HttpStatus.BAD_REQUEST
},
CONSULTANT_BOOKING_NOT_FOUND: {
error: 'CONSULTANT_BOOKING_NOT_FOUND',
message: 'Không tìm thấy lịch đặt tư vấn. Vui lòng thử lại',
httpStatus: HttpStatus.BAD_REQUEST
},
CONSULTANT_STAFF_NOT_FOUND: {
error: 'CONSULTANT_STAFF_NOT_FOUND',
message: 'Không tìm thấy nhân viên tư vấn. Vui lòng thử lại',
Expand Down
3 changes: 2 additions & 1 deletion src/consultant-booking/booking.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import { ConsultantBooking, ConsultantBookingSchema } from '@consultant-booking/
import { ConsultantBookingCustomerController } from '@consultant-booking/controllers/customer.controller'
import { ConsultantBookingService } from '@consultant-booking/services/booking.service'
import { ConsultantBookingRepository } from '@consultant-booking/repositories/booking.repository'
import { ConsultantBookingProviderController } from '@consultant-booking/controllers/provider.controller'

@Module({
imports: [
MongooseModule.forFeature([{ name: ConsultantBooking.name, schema: ConsultantBookingSchema }]),
CategoryModule,
StaffModule
],
controllers: [ConsultantBookingCustomerController],
controllers: [ConsultantBookingCustomerController, ConsultantBookingProviderController],
providers: [ConsultantBookingService, ConsultantBookingRepository],
exports: [ConsultantBookingService]
})
Expand Down
51 changes: 51 additions & 0 deletions src/consultant-booking/controllers/provider.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Controller, Get, Param, Req, UseGuards } from '@nestjs/common'
import { ApiBadRequestResponse, ApiBearerAuth, ApiOkResponse, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger'
import * as _ from 'lodash'

import { ErrorResponse, PaginationQuery } from '@common/contracts/dto'
import { ConsultantBookingService } from '@consultant-booking/services/booking.service'
import { ConsultantBookingPaginateResponseDto, ConsultantBookingResponseDto } from '@consultant-booking/dto/booking.dto'
import { UserRole } from '@common/contracts/constant'
import { Roles } from '@auth/decorators/roles.decorator'
import { JwtAuthGuard } from '@auth/guards/jwt-auth.guard'
import { RolesGuard } from '@auth/guards/roles.guard'
import { Pagination, PaginationParams } from '@common/decorators/pagination.decorator'
import { Types } from 'mongoose'
import { ParseObjectIdPipe } from '@common/pipes/parse-object-id.pipe'

@ApiTags('ConsultantBooking - Provider')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard.ACCESS_TOKEN)
@Controller('provider')
export class ConsultantBookingProviderController {
constructor(private readonly consultantBookingService: ConsultantBookingService) {}

@Get()
@ApiOperation({
summary: "Get consultant's bookings list"
})
@Roles(UserRole.CONSULTANT_STAFF)
@UseGuards(RolesGuard)
@ApiQuery({ type: PaginationQuery })
@ApiOkResponse({ type: ConsultantBookingPaginateResponseDto })
async paginate(@Req() req, @Pagination() paginationParams: PaginationParams) {
const staffId = _.get(req, 'user._id')
return await this.consultantBookingService.paginate(
{ 'consultant._id': new Types.ObjectId(staffId) },
paginationParams
)
}

@Get(':bookingId')
@ApiOperation({
summary: 'Get consultant booking details'
})
@Roles(UserRole.CONSULTANT_STAFF)
@UseGuards(RolesGuard)
@ApiOkResponse({ type: ConsultantBookingResponseDto })
@ApiBadRequestResponse({ type: ErrorResponse })
async getOne(@Req() req, @Param('bookingId', ParseObjectIdPipe) bookingId: string) {
const staffId = _.get(req, 'user._id')
return await this.consultantBookingService.getOne({ 'consultant._id': new Types.ObjectId(staffId), _id: bookingId })
}
}
4 changes: 3 additions & 1 deletion src/consultant-booking/dto/booking.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ export class ConsultantBookingDto {

export class ConsultantBookingPaginateResponseDto extends DataResponse(
class ConsultantBookingPaginateResponse extends PaginateResponse(ConsultantBookingDto) {}
) {}
) {}

export class ConsultantBookingResponseDto extends DataResponse(ConsultantBookingDto) {}
14 changes: 14 additions & 0 deletions src/consultant-booking/services/booking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,18 @@ export class ConsultantBookingService {
)
return result
}

public async getOne(filter: FilterQuery<ConsultantBooking>) {
const booking = await this.consultantBookingRepository.findOne({
conditions: {
...filter,
status: {
$ne: BookingStatus.DELETED
}
},
})
if (!booking) throw new AppException(Errors.CONSULTANT_BOOKING_NOT_FOUND)

return booking
}
}

0 comments on commit b2d0093

Please sign in to comment.