Add pagination to controller
This commit is contained in:
1 parent
ddd937d42f
commit
c3944f2fe7
1 file changed
+10
-7
@@ -1,4 +1,5 @@
|
|||||||
import { ISuperSimpleQueue } from "@/service/index.js";
|
import { IJobQueue } from "@/service/index.js";
|
||||||
|
import { getQueueJobsQueryValidation } from "@/validation/queueValidation.js";
|
||||||
import { Request, Response, NextFunction } from "express";
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
|
||||||
const SERVICE_NAME = "JobQueueController";
|
const SERVICE_NAME = "JobQueueController";
|
||||||
@@ -12,8 +13,8 @@ export interface IJobQueueController {
|
|||||||
|
|
||||||
class JobQueueController implements IJobQueueController {
|
class JobQueueController implements IJobQueueController {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
private jobQueue: ISuperSimpleQueue;
|
private jobQueue: IJobQueue;
|
||||||
constructor(jobQueue: ISuperSimpleQueue) {
|
constructor(jobQueue: IJobQueue) {
|
||||||
this.jobQueue = jobQueue;
|
this.jobQueue = jobQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,11 +37,12 @@ class JobQueueController implements IJobQueueController {
|
|||||||
|
|
||||||
getJobs = async (req: Request, res: Response, next: NextFunction) => {
|
getJobs = async (req: Request, res: Response, next: NextFunction) => {
|
||||||
try {
|
try {
|
||||||
const jobs = await this.jobQueue.getJobs();
|
const pagination = getQueueJobsQueryValidation.parse(req.query);
|
||||||
|
const { jobs, count } = await this.jobQueue.getJobs(pagination);
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: "Queue jobs fetched successfully",
|
msg: "Queue jobs fetched successfully",
|
||||||
data: jobs,
|
data: { jobs, count },
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
@@ -49,12 +51,13 @@ class JobQueueController implements IJobQueueController {
|
|||||||
|
|
||||||
getAllMetrics = async (req: Request, res: Response, next: NextFunction) => {
|
getAllMetrics = async (req: Request, res: Response, next: NextFunction) => {
|
||||||
try {
|
try {
|
||||||
const jobs = await this.jobQueue.getJobs();
|
const pagination = getQueueJobsQueryValidation.parse(req.query);
|
||||||
|
const { jobs, count } = await this.jobQueue.getJobs(pagination);
|
||||||
const metrics = await this.jobQueue.getMetrics();
|
const metrics = await this.jobQueue.getMetrics();
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: "Queue metrics fetched successfully",
|
msg: "Queue metrics fetched successfully",
|
||||||
data: { jobs, metrics },
|
data: { jobs, count, metrics },
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
|
|||||||
Reference in new issue
Block a user