get all tickets
This commit is contained in:
@@ -1,18 +1,5 @@
|
|||||||
import { ApiPropertyOptional } from "@nestjs/swagger";
|
|
||||||
import { IsEnum, IsOptional, IsUUID } from "class-validator";
|
|
||||||
|
|
||||||
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||||
import { UserMessage } from "../../../common/enums/message.enum";
|
|
||||||
import { TicketStatus } from "../enums/ticket-status.enum";
|
|
||||||
|
|
||||||
export class SearchTicketQueryDto extends PaginationDto {
|
export class FindTicketQueryDto extends PaginationDto {
|
||||||
@IsOptional()
|
|
||||||
@IsEnum(TicketStatus)
|
|
||||||
@ApiPropertyOptional({ enum: TicketStatus, description: "ticket status", example: TicketStatus.PENDING })
|
|
||||||
status?: TicketStatus;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsUUID("4", { message:" UserMessage.USER_ID_SHOULD_BE_A_UUID" })
|
|
||||||
@ApiPropertyOptional({ description: "user id", example: "123e4567-e89b-12d3-a456-426614174000" })
|
|
||||||
userId?: string;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { User } from "src/modules/user/entities/user.entity";
|
|||||||
import { UserRepository } from "src/modules/user/repositories/user.repository";
|
import { UserRepository } from "src/modules/user/repositories/user.repository";
|
||||||
import { AdminRepository } from "src/modules/admin/repositories/admin.repository";
|
import { AdminRepository } from "src/modules/admin/repositories/admin.repository";
|
||||||
import { Admin } from "src/modules/admin/entities/admin.entity";
|
import { Admin } from "src/modules/admin/entities/admin.entity";
|
||||||
|
import { FindTicketQueryDto } from "../DTO/search-ticket-query.dto";
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -334,19 +335,23 @@ export class TicketService {
|
|||||||
|
|
||||||
// //******************************** */
|
// //******************************** */
|
||||||
|
|
||||||
// async getTickets(queryDto: SearchTicketQueryDto, userId: string) {
|
async getTickets(orderId: string, queryDto: FindTicketQueryDto, userId?: string) {
|
||||||
// const [tickets, count] = await this.ticketsRepository.findTicketsList(queryDto, userId);
|
|
||||||
|
|
||||||
// return { tickets, count, paginate: true };
|
const order = await this.orderRepository.findOne({ id: orderId })
|
||||||
// }
|
if (!order) {
|
||||||
// //******************************** */
|
throw new BadRequestException("order not found!")
|
||||||
// async getTicketForAdmin(queryDto: SearchTicketQueryDto, adminId: string) {
|
}
|
||||||
// const isSuperAdmin = await this.usersService.isSuperAdmin(adminId);
|
if(userId){
|
||||||
|
if (order.user.id !== userId) {
|
||||||
|
throw new BadRequestException("This ticket doenst belongs to You !")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const data = await this.ticketsRepository.findAllPaginated({ ...queryDto, orderId });
|
||||||
|
|
||||||
// const [tickets, count] = await this.ticketsRepository.findTicketsListForAdmin(queryDto, adminId, isSuperAdmin);
|
return data
|
||||||
|
}
|
||||||
|
//******************************** */
|
||||||
|
|
||||||
// return { tickets, count, paginate: true };
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //******************************** */
|
// //******************************** */
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
|
import { EntityManager, EntityRepository, FilterQuery } from '@mikro-orm/postgresql';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { Ticket } from '../entities/ticket.entity';
|
import { Ticket } from '../entities/ticket.entity';
|
||||||
|
import { FindTicketQueryDto } from '../DTO/search-ticket-query.dto';
|
||||||
|
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
||||||
|
|
||||||
|
class FindOrdersOpts extends FindTicketQueryDto {
|
||||||
|
orderId: string;
|
||||||
|
};
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TicketRepository extends EntityRepository<Ticket> {
|
export class TicketRepository extends EntityRepository<Ticket> {
|
||||||
@@ -10,4 +16,39 @@ export class TicketRepository extends EntityRepository<Ticket> {
|
|||||||
super(em, Ticket);
|
super(em, Ticket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findAllPaginated(opts: FindOrdersOpts): Promise<PaginatedResult<Ticket>> {
|
||||||
|
const {
|
||||||
|
page = 1,
|
||||||
|
limit = 10,
|
||||||
|
orderId
|
||||||
|
} = opts;
|
||||||
|
|
||||||
|
const offset = (page - 1) * limit;
|
||||||
|
|
||||||
|
const where: FilterQuery<Ticket> = {
|
||||||
|
order: { id: orderId }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const [data, total] = await this.findAndCount(where, {
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
orderBy: { createdAt: 'desc' },
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const totalPages = Math.ceil(total / limit);
|
||||||
|
|
||||||
|
return {
|
||||||
|
data,
|
||||||
|
meta: {
|
||||||
|
total,
|
||||||
|
page,
|
||||||
|
limit,
|
||||||
|
totalPages,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
import { Body, Controller, Get, HttpCode, HttpStatus, Param, Patch, Post, Query } from "@nestjs/common";
|
import { Body, Controller, Get, HttpCode, HttpStatus, Param, Patch, Post, Query } from "@nestjs/common";
|
||||||
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
||||||
|
import { CreateTicketDto } from "./DTO/create-ticket.dto";
|
||||||
import { CreateTicketCategoryDto } from "./DTO/create-ticket-category.dto";
|
import { FindTicketQueryDto } from "./DTO/search-ticket-query.dto";
|
||||||
import { CreateTicketMessageDto } from "./DTO/create-ticket-message.dto";
|
|
||||||
import { CreateTicketByAdminDto, CreateTicketDto } from "./DTO/create-ticket.dto";
|
|
||||||
import { SearchTicketCategoryDto } from "./DTO/search-ticket-category.dto";
|
|
||||||
import { SearchTicketQueryDto } from "./DTO/search-ticket-query.dto";
|
|
||||||
import { TicketService } from "./providers/tickets.service";
|
import { TicketService } from "./providers/tickets.service";
|
||||||
|
|
||||||
|
|
||||||
@@ -70,25 +66,27 @@ export class TicketsController {
|
|||||||
return this.ticketsService.createTicket(orderId, createDto, userId);
|
return this.ticketsService.createTicket(orderId, createDto, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation({ summary: "Get all order tickets ==> user route" })
|
||||||
|
@Get('public/ticket/order/:orderId')
|
||||||
|
getTickets(@Query() queryDto: FindTicketQueryDto, @Param('orderId') orderId: string, @UserId() userId: string) {
|
||||||
|
return this.ticketsService.getTickets(orderId, queryDto, userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*=========================== Admin ============================== */
|
||||||
|
|
||||||
@Post('admin/ticket/order/:orderId')
|
@Post('admin/ticket/order/:orderId')
|
||||||
@ApiOperation({ summary: "create ticket ==> admin route" })
|
@ApiOperation({ summary: "create ticket ==> admin route" })
|
||||||
createTicketAsAdmin(@Param('orderId') orderId: string, @Body() createDto: CreateTicketDto, @AdminId() adminId: string) {
|
createTicketAsAdmin(@Param('orderId') orderId: string, @Body() createDto: CreateTicketDto, @AdminId() adminId: string) {
|
||||||
return this.ticketsService.createTicket(orderId, createDto, undefined, adminId);
|
return this.ticketsService.createTicket(orderId, createDto, undefined, adminId);
|
||||||
}
|
}
|
||||||
// @ApiOperation({ summary: "create ticket by admin" })
|
|
||||||
// @AdminRoute()
|
|
||||||
// @PermissionsDec(PermissionEnum.TICKETS)
|
|
||||||
// @Post("admin")
|
|
||||||
// createTicketByAdmin(@Body() createDto: CreateTicketByAdminDto, @UserIpAndHeaders() userIpAndHeaders: IUserIpAndHeaders) {
|
|
||||||
// return this.ticketsService.createTicketByAdmin(createDto, userIpAndHeaders);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @ApiOperation({ summary: "Get all tickets of user ==> user route" })
|
|
||||||
// @Get()
|
|
||||||
// getTickets(@Query() queryDto: SearchTicketQueryDto, @UserDec("id") userId: string) {
|
|
||||||
// return this.ticketsService.getTickets(queryDto, userId);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
@ApiOperation({ summary: "Get all order tickets ==> admin route" })
|
||||||
|
@Get('admin/ticket/order/:orderId')
|
||||||
|
getTicketsAsAdmin(@Query() queryDto: FindTicketQueryDto, @Param('orderId') orderId: string) {
|
||||||
|
return this.ticketsService.getTickets(orderId, queryDto);
|
||||||
|
}
|
||||||
// @ApiOperation({ summary: "Get all tickets ==> admin route" })
|
// @ApiOperation({ summary: "Get all tickets ==> admin route" })
|
||||||
// @AdminRoute()
|
// @AdminRoute()
|
||||||
// @PermissionsDec(PermissionEnum.TICKETS)
|
// @PermissionsDec(PermissionEnum.TICKETS)
|
||||||
|
|||||||
Reference in New Issue
Block a user