Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions backend/src/api/routes/dataCorrections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
import { DataCorrectionService } from "../../services/dataCorrection.service.js";
import { authMiddleware } from "../middleware/auth.js";

export async function dataCorrectionsRoutes(server: FastifyInstance) {
const service = new DataCorrectionService();

server.addHook("preHandler", authMiddleware());

server.get(
"/pending",
{
schema: {
tags: ["Data Corrections"],
summary: "Get pending corrections",
security: [{ ApiKeyAuth: [] }],
},
},
async (request: FastifyRequest, reply: FastifyReply) => {
const corrections = await service.getPendingCorrections();
reply.send({ corrections });
}
);

server.get<{ Querystring: { requesterAddress: string } }>(
"/",
{
schema: {
tags: ["Data Corrections"],
summary: "Get corrections for requester",
security: [{ ApiKeyAuth: [] }],
querystring: {
type: "object",
required: ["requesterAddress"],
properties: { requesterAddress: { type: "string" } },
},
},
},
async (request: FastifyRequest, reply: FastifyReply) => {
const { requesterAddress } = request.query as { requesterAddress: string };
const corrections = await service.getCorrectionsForRequester(requesterAddress);
reply.send({ corrections });
}
);

server.post<{
Body: {
requesterAddress: string;
dataType: string;
entityId: string;
originalData: Record<string, unknown>;
correctedData: Record<string, unknown>;
reason: string;
};
}>(
"/",
{
schema: {
tags: ["Data Corrections"],
summary: "Create correction request",
security: [{ ApiKeyAuth: [] }],
body: {
type: "object",
required: ["requesterAddress", "dataType", "entityId", "originalData", "correctedData", "reason"],
properties: {
requesterAddress: { type: "string" },
dataType: { type: "string" },
entityId: { type: "string" },
originalData: { type: "object" },
correctedData: { type: "object" },
reason: { type: "string" },
},
},
},
},
async (request: FastifyRequest, reply: FastifyReply) => {
const { requesterAddress, dataType, entityId, originalData, correctedData, reason } = request.body;
const correction = await service.createCorrection(
requesterAddress,
dataType,
entityId,
originalData,
correctedData,
reason
);
reply.code(201).send({ correction });
}
);

server.post<{
Params: { id: string };
Body: { approverAddress: string };
}>(
"/:id/approve",
{
schema: {
tags: ["Data Corrections"],
summary: "Approve correction request",
security: [{ ApiKeyAuth: [] }],
params: {
type: "object",
required: ["id"],
properties: { id: { type: "string", format: "uuid" } },
},
body: {
type: "object",
required: ["approverAddress"],
properties: { approverAddress: { type: "string" } },
},
},
},
async (request: FastifyRequest, reply: FastifyReply) => {
const { id } = request.params as { id: string };
const { approverAddress } = request.body;
const correction = await service.approveCorrection(id, approverAddress);
reply.send({ correction });
}
);

server.post<{
Params: { id: string };
Body: { rejectionReason: string };
}>(
"/:id/reject",
{
schema: {
tags: ["Data Corrections"],
summary: "Reject correction request",
security: [{ ApiKeyAuth: [] }],
params: {
type: "object",
required: ["id"],
properties: { id: { type: "string", format: "uuid" } },
},
body: {
type: "object",
required: ["rejectionReason"],
properties: { rejectionReason: { type: "string" } },
},
},
},
async (request: FastifyRequest, reply: FastifyReply) => {
const { id } = request.params as { id: string };
const { rejectionReason } = request.body;
const correction = await service.rejectCorrection(id, rejectionReason);
reply.send({ correction });
}
);
}
99 changes: 99 additions & 0 deletions backend/src/api/routes/loginRiskSignals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
import { LoginRiskSignalService } from "../../services/loginRiskSignal.service.js";
import { authMiddleware } from "../middleware/auth.js";

export async function loginRiskSignalsRoutes(server: FastifyInstance) {
const service = new LoginRiskSignalService();

server.addHook("preHandler", authMiddleware());

server.get<{ Querystring: { userAddress: string } }>(
"/signals",
{
schema: {
tags: ["Login Risk Signals"],
summary: "Get login risk signals for user",
security: [{ ApiKeyAuth: [] }],
querystring: {
type: "object",
required: ["userAddress"],
properties: { userAddress: { type: "string" } },
},
},
},
async (request: FastifyRequest, reply: FastifyReply) => {
const { userAddress } = request.query as { userAddress: string };
const signals = await service.getSignalsForUser(userAddress);
reply.send({ signals });
}
);

server.get(
"/active-signals",
{
schema: {
tags: ["Login Risk Signals"],
summary: "Get active high-risk signals",
security: [{ ApiKeyAuth: [] }],
},
},
async (request: FastifyRequest, reply: FastifyReply) => {
const signals = await service.getActiveSignals("high");
reply.send({ signals });
}
);

server.post<{
Body: {
userAddress: string;
signalType: string;
riskLevel: string;
metadata?: Record<string, unknown>;
};
}>(
"/signals",
{
schema: {
tags: ["Login Risk Signals"],
summary: "Create login risk signal",
security: [{ ApiKeyAuth: [] }],
body: {
type: "object",
required: ["userAddress", "signalType", "riskLevel"],
properties: {
userAddress: { type: "string" },
signalType: { type: "string" },
riskLevel: { type: "string", enum: ["critical", "high", "medium", "low"] },
metadata: { type: "object" },
},
},
},
},
async (request: FastifyRequest, reply: FastifyReply) => {
const { userAddress, signalType, riskLevel, metadata } = request.body;
const signal = await service.createSignal(userAddress, signalType as any, riskLevel as any, metadata);
reply.code(201).send({ signal });
}
);

server.post<{ Params: { id: string } }>(
"/signals/:id/resolve",
{
schema: {
tags: ["Login Risk Signals"],
summary: "Resolve login risk signal",
security: [{ ApiKeyAuth: [] }],
params: {
type: "object",
required: ["id"],
properties: { id: { type: "string", format: "uuid" } },
},
},
},
async (request: FastifyRequest, reply: FastifyReply) => {
const { id } = request.params as { id: string };
const signal = await service.resolveSignal(id);
reply.send({ signal });
}
);
}
115 changes: 115 additions & 0 deletions backend/src/api/routes/notificationAnalytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
import { NotificationAnalyticsService } from "../../services/notificationAnalytics.service.js";
import { authMiddleware } from "../middleware/auth.js";

export async function notificationAnalyticsRoutes(server: FastifyInstance) {
const service = new NotificationAnalyticsService();

server.addHook("preHandler", authMiddleware());

server.get<{
Querystring: {
startDate: string;
endDate: string;
notificationType?: string;
};
}>(
"/analytics",
{
schema: {
tags: ["Notification Analytics"],
summary: "Get notification delivery analytics",
security: [{ ApiKeyAuth: [] }],
querystring: {
type: "object",
required: ["startDate", "endDate"],
properties: {
startDate: { type: "string", format: "date-time" },
endDate: { type: "string", format: "date-time" },
notificationType: { type: "string" },
},
},
},
},
async (request: FastifyRequest, reply: FastifyReply) => {
const { startDate, endDate, notificationType } = request.query as {
startDate: string;
endDate: string;
notificationType?: string;
};
const analytics = await service.getAnalytics(new Date(startDate), new Date(endDate), notificationType);
reply.send(analytics);
}
);

server.get<{ Querystring: { channel: string; limit?: string } }>(
"/history",
{
schema: {
tags: ["Notification Analytics"],
summary: "Get notification delivery history",
security: [{ ApiKeyAuth: [] }],
querystring: {
type: "object",
required: ["channel"],
properties: {
channel: { type: "string" },
limit: { type: "string" },
},
},
},
},
async (request: FastifyRequest, reply: FastifyReply) => {
const { channel, limit } = request.query as { channel: string; limit?: string };
const history = await service.getDeliveryHistory(channel, limit ? parseInt(limit) : 100);
reply.send({ history });
}
);

server.post<{
Body: {
notificationType: string;
channel: string;
recipient: string;
status: string;
deliveryTimeMs?: number;
errorMessage?: string;
metadata?: Record<string, unknown>;
};
}>(
"/log",
{
schema: {
tags: ["Notification Analytics"],
summary: "Log notification delivery",
security: [{ ApiKeyAuth: [] }],
body: {
type: "object",
required: ["notificationType", "channel", "recipient", "status"],
properties: {
notificationType: { type: "string" },
channel: { type: "string" },
recipient: { type: "string" },
status: { type: "string", enum: ["sent", "delivered", "failed", "bounced"] },
deliveryTimeMs: { type: "number" },
errorMessage: { type: "string" },
metadata: { type: "object" },
},
},
},
},
async (request: FastifyRequest, reply: FastifyReply) => {
const { notificationType, channel, recipient, status, deliveryTimeMs, errorMessage, metadata } = request.body;
const delivery = await service.logDelivery(
notificationType,
channel,
recipient,
status as any,
deliveryTimeMs,
errorMessage,
metadata
);
reply.code(201).send({ delivery });
}
);
}
Loading
Loading