parse query
This commit is contained in:
1 parent
3fa370765e
commit
ef61a63da0
2 files changed
+24
-7
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
import { Request, Response, NextFunction } from "express";
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
import { requireTeamId } from "./controllerUtils.js";
|
||||||
|
|
||||||
const SERVICE_NAME = "incidentController";
|
const SERVICE_NAME = "incidentController";
|
||||||
|
|
||||||
@@ -17,10 +18,19 @@ class IncidentController {
|
|||||||
|
|
||||||
getIncidentsByTeam = async (req: Request, res: Response, next: NextFunction) => {
|
getIncidentsByTeam = async (req: Request, res: Response, next: NextFunction) => {
|
||||||
try {
|
try {
|
||||||
const result = await this.incidentService.getIncidentsByTeam({
|
const { sortOrder, dateRange, page, rowsPerPage, status, monitorId, resolutionType } = req.query || {};
|
||||||
teamId: req?.user?.teamId,
|
|
||||||
query: req?.query,
|
const teamId = requireTeamId(req.user?.teamId);
|
||||||
});
|
const result = await this.incidentService.getIncidentsByTeam(
|
||||||
|
teamId,
|
||||||
|
sortOrder,
|
||||||
|
dateRange,
|
||||||
|
page,
|
||||||
|
rowsPerPage,
|
||||||
|
status,
|
||||||
|
monitorId,
|
||||||
|
resolutionType
|
||||||
|
);
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
@@ -73,7 +83,6 @@ class IncidentController {
|
|||||||
|
|
||||||
resolveIncidentManually = async (req: Request, res: Response, next: NextFunction) => {
|
resolveIncidentManually = async (req: Request, res: Response, next: NextFunction) => {
|
||||||
try {
|
try {
|
||||||
console.log({ user: req.user });
|
|
||||||
const resolvedIncident = await this.incidentService.resolveIncident(
|
const resolvedIncident = await this.incidentService.resolveIncident(
|
||||||
req?.params?.incidentId,
|
req?.params?.incidentId,
|
||||||
req?.user?.id,
|
req?.user?.id,
|
||||||
|
|||||||
@@ -124,13 +124,21 @@ class IncidentService {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getIncidentsByTeam = async ({ teamId, query }: { teamId: string; query?: any }) => {
|
getIncidentsByTeam = async (
|
||||||
|
teamId: string,
|
||||||
|
sortOrder: string,
|
||||||
|
dateRange: string,
|
||||||
|
page: string,
|
||||||
|
rowsPerPage: string,
|
||||||
|
status: string,
|
||||||
|
monitorId: string,
|
||||||
|
resolutionType: string
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
if (!teamId) {
|
if (!teamId) {
|
||||||
throw this.errorService.createBadRequestError("No team ID in request");
|
throw this.errorService.createBadRequestError("No team ID in request");
|
||||||
}
|
}
|
||||||
|
|
||||||
const { sortOrder, dateRange, page, rowsPerPage, status, monitorId, resolutionType } = query || {};
|
|
||||||
const startDate = dateRangeLookup[dateRange];
|
const startDate = dateRangeLookup[dateRange];
|
||||||
|
|
||||||
const parsedPage = Number.isFinite(parseInt(page)) ? parseInt(page) : 0;
|
const parsedPage = Number.isFinite(parseInt(page)) ? parseInt(page) : 0;
|
||||||
|
|||||||
Reference in new issue
Block a user