get all tickets
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { EntityManager, EntityRepository, FilterQuery } from '@mikro-orm/postgresql';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
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()
|
||||
export class TicketRepository extends EntityRepository<Ticket> {
|
||||
@@ -10,4 +16,39 @@ export class TicketRepository extends EntityRepository<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,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user