221 lines
8.4 KiB
TypeScript
Executable File
221 lines
8.4 KiB
TypeScript
Executable File
import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Patch, Post, Query } from "@nestjs/common";
|
|
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
|
|
|
import { AddReviewDto } from "./DTO/add-review.dto";
|
|
import { CategoryListSearchQueryDto, CategorySearchQueryDto } from "./DTO/category-search-query.dto";
|
|
import { CreateDanakServiceCategoryDto } from "./DTO/create-category.dto";
|
|
import { CreateServiceDto } from "./DTO/create-service.dto";
|
|
import { DanakServiceReviewQueryDto } from "./DTO/danak-service-review-query.dto";
|
|
import { DanakServicesGlobalSearchDto, DanakServicesQueryDto, DanakServicesSearchQueryDto } from "./DTO/danak-services-search-query.dto";
|
|
import { UpdateDanakServiceCategoryDto } from "./DTO/update-category.dto";
|
|
import { UpdateReviewStatusDto } from "./DTO/update-review-status.dto";
|
|
import { UpdateServiceDto } from "./DTO/update-service.dto";
|
|
import { DanakServicesService } from "./providers/danak-services.service";
|
|
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
|
import { Pagination } from "../../common/decorators/pagination.decorator";
|
|
import { PermissionsDec } from "../../common/decorators/permission.decorator";
|
|
import { UserDec } from "../../common/decorators/user.decorator";
|
|
import { ParamDto } from "../../common/DTO/param.dto";
|
|
import { PermissionEnum } from "../users/enums/permission.enum";
|
|
|
|
@Controller("danak-services")
|
|
@ApiTags("Danak-Services")
|
|
export class DanakServicesController {
|
|
constructor(private readonly danakServicesService: DanakServicesService) {}
|
|
|
|
//------------------------ service categories ------------------------
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@ApiOperation({ summary: "Create a new service category => admin route" })
|
|
@Post("categories")
|
|
createCategory(@Body() createDto: CreateDanakServiceCategoryDto) {
|
|
return this.danakServicesService.createCategory(createDto);
|
|
}
|
|
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@ApiOperation({ summary: "Get all service categories => admin route" })
|
|
@Get("categories")
|
|
getCategories(@Query() queryDto: CategorySearchQueryDto) {
|
|
return this.danakServicesService.getCategories(queryDto);
|
|
}
|
|
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@ApiOperation({ summary: "Get all service categories => admin route" })
|
|
@Pagination()
|
|
@Get("categories/list")
|
|
getCategoryList(@Query() queryDto: CategoryListSearchQueryDto) {
|
|
return this.danakServicesService.getCategoryList(queryDto);
|
|
}
|
|
|
|
// @AuthGuards()
|
|
@ApiOperation({ summary: "Get all service categories user side" })
|
|
@Get("categories/public")
|
|
getCategoriesUserSide() {
|
|
return this.danakServicesService.getCategoriesUserSide();
|
|
}
|
|
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@ApiOperation({ summary: "Get category by id => admin route" })
|
|
@Get("categories/:id")
|
|
getCategoryById(@Param() paramDto: ParamDto) {
|
|
return this.danakServicesService.getCategoryById(paramDto.id);
|
|
}
|
|
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@ApiOperation({ summary: "update category by id => admin route" })
|
|
@Patch("categories/:id")
|
|
updateCategory(@Param() paramDto: ParamDto, @Body() updateDto: UpdateDanakServiceCategoryDto) {
|
|
return this.danakServicesService.updateCategory(paramDto.id, updateDto);
|
|
}
|
|
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@ApiOperation({ summary: "delete category by id => admin route" })
|
|
@Delete("categories/:id")
|
|
deleteCategoryById(@Param() paramDto: ParamDto) {
|
|
return this.danakServicesService.deleteCategoryById(paramDto.id);
|
|
}
|
|
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@ApiOperation({ summary: "toggle status of categories => admin route" })
|
|
@HttpCode(HttpStatus.OK)
|
|
@Post("categories/toggle-status/:id")
|
|
toggleCategoryStatus(@Param() paramDto: ParamDto) {
|
|
return this.danakServicesService.toggleCategoryStatus(paramDto);
|
|
}
|
|
//-------------------- service management --------------------------
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@ApiOperation({ summary: "create new danak services => admin route" })
|
|
@Post()
|
|
createService(@Body() createDto: CreateServiceDto) {
|
|
return this.danakServicesService.createService(createDto);
|
|
}
|
|
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@ApiOperation({ summary: "get all danak services ==> admin route" })
|
|
@Get()
|
|
getServices(@Query() queryDto: DanakServicesSearchQueryDto) {
|
|
return this.danakServicesService.getServicesList(queryDto);
|
|
}
|
|
|
|
@ApiOperation({ summary: "get all danak services for user side" })
|
|
// @AuthGuards()
|
|
@Get("public")
|
|
getServicesForUser(@Query() queryDto: DanakServicesQueryDto) {
|
|
return this.danakServicesService.getServicesListForUser(queryDto);
|
|
}
|
|
|
|
@ApiOperation({ summary: "search danak services" })
|
|
@AuthGuards()
|
|
@Get("search")
|
|
searchServices(@Query() queryDto: DanakServicesGlobalSearchDto) {
|
|
return this.danakServicesService.searchServices(queryDto);
|
|
}
|
|
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@ApiOperation({ summary: "toggle status of danak service => admin route" })
|
|
@HttpCode(HttpStatus.OK)
|
|
@Post("toggle-status/:id")
|
|
toggleServiceStatus(@Param() paramDto: ParamDto) {
|
|
return this.danakServicesService.toggleServiceStatus(paramDto);
|
|
}
|
|
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@ApiOperation({ summary: "toggle status of danak service slider => admin route" })
|
|
@HttpCode(HttpStatus.OK)
|
|
@Post("toggle-slider/:id")
|
|
toggleServiceSlider(@Param() paramDto: ParamDto) {
|
|
return this.danakServicesService.toggleServiceSlider(paramDto);
|
|
}
|
|
|
|
@ApiOperation({ summary: "get services for user side" })
|
|
@Get("suggested")
|
|
getDanakSuggestServices() {
|
|
return this.danakServicesService.getDanakSuggestServices();
|
|
}
|
|
|
|
@ApiOperation({ summary: "get danak service slider" })
|
|
@Get("slider")
|
|
getDanakServicesSlider() {
|
|
return this.danakServicesService.getDanakServicesSlider();
|
|
}
|
|
|
|
@ApiOperation({ summary: "get danak service by id" })
|
|
@AuthGuards()
|
|
@Get(":id")
|
|
getDanakServiceById(@Param() paramDto: ParamDto, @UserDec("isAdmin") isAdmin: boolean, @UserDec("id") userId: string) {
|
|
return this.danakServicesService.getDanakServiceByIdWithSubs(paramDto.id, isAdmin, userId);
|
|
}
|
|
|
|
@ApiOperation({ summary: "get danakService by id public" })
|
|
@Get(":id/public")
|
|
getDanakServiceByIdPublic(@Param() paramDto: ParamDto) {
|
|
return this.danakServicesService.getDanakServiceByIdPublic(paramDto.id);
|
|
}
|
|
|
|
@ApiOperation({ summary: "update danak service" })
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@Patch(":id")
|
|
updateDanakService(@Param() paramDto: ParamDto, @Body() updateDto: UpdateServiceDto) {
|
|
return this.danakServicesService.updateDanakService(paramDto.id, updateDto);
|
|
}
|
|
|
|
@ApiOperation({ summary: "delete danak service" })
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@Delete(":id")
|
|
deleteServiceById(@Param() paramDto: ParamDto) {
|
|
return this.danakServicesService.deleteServiceById(paramDto.id);
|
|
}
|
|
|
|
@ApiOperation({ summary: "get service users" })
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@Get(":id/users")
|
|
getServiceUsers(@Param() paramDto: ParamDto) {
|
|
return this.danakServicesService.getServiceUsers(paramDto.id);
|
|
}
|
|
|
|
@ApiOperation({ summary: "add review to danak service ==> user route" })
|
|
@AuthGuards()
|
|
@Post(":id/reviews")
|
|
addReview(@Param() paramDto: ParamDto, @Body() addReviewDto: AddReviewDto, @UserDec("id") userId: string) {
|
|
return this.danakServicesService.addReview(userId, paramDto.id, addReviewDto);
|
|
}
|
|
|
|
@ApiOperation({ summary: "get danak service reviews ==> admin route" })
|
|
@AuthGuards()
|
|
@Pagination()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@Get("reviews")
|
|
getDanakServiceReviews(@Query() queryDto: DanakServiceReviewQueryDto) {
|
|
return this.danakServicesService.getDanakServiceReviews(queryDto);
|
|
}
|
|
|
|
@ApiOperation({ summary: "update danak service review status ==> admin route" })
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.SERVICES)
|
|
@Patch("reviews/:id/:status")
|
|
updateDanakServiceReviewStatus(@Param() updateParamDto: UpdateReviewStatusDto) {
|
|
return this.danakServicesService.updateDanakServiceReviewStatus(updateParamDto);
|
|
}
|
|
|
|
// @AuthGuards()
|
|
//
|
|
// @ApiOperation({ summary: "get all user purchased danak services" })
|
|
// @Get("user-services")
|
|
// getUserServices(@UserDec() user: User) {
|
|
// return this.danakServicesService.getUserServices(user.id);
|
|
// }
|
|
}
|