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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Kysely, sql } from "kysely";

export async function up(db: Kysely<any>): Promise<void> {
const hasTotalLatency = await sql<{ exists: boolean }>`
SELECT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'endpoint_metrics' AND column_name = 'total_latency'
) as exists
`.execute(db);

if (hasTotalLatency.rows[0]?.exists) return;

const hasAvgLatency = await sql<{ exists: boolean }>`
SELECT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'endpoint_metrics' AND column_name = 'avg_latency'
) as exists
`.execute(db);

if (hasAvgLatency.rows[0]?.exists) {
await db.schema.alterTable("endpoint_metrics").renameColumn("avg_latency", "total_latency").execute();
} else {
await db.schema
.alterTable("endpoint_metrics")
.addColumn("total_latency", "double precision", (col) => col.defaultTo(0.0))
.execute();
}
}

export async function down(db: Kysely<any>): Promise<void> {
await db.schema.alterTable("endpoint_metrics").renameColumn("total_latency", "avg_latency").execute();
}
16 changes: 2 additions & 14 deletions server/src/shared/infra/messaging/eventProducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ import { IRetryStrategy } from "../../contracts/infra/resilience/IRetryStrategy.
import { CircuitBreakerStatsType } from "../../typings/circuitBreaker.typings";
import { ResourceNotInitializedError } from "../../typings/error.typings";
import { ProducerShuttingDownError } from "../../typings/eventError.typings";
import {
EventProducerMetricsType,
EventType,
PublishingEventDataType,
PublishingMessageType,
PublishOptions,
} from "../../typings/messaging.typings";
import { EventProducerMetricsType, PublishingEventDataType, PublishOptions } from "../../typings/messaging.typings";

export class EventProducer {
private channelManager: IConfirmChannelManager;
Expand Down Expand Up @@ -44,12 +38,6 @@ export class EventProducer {
}

private async publish(obj: PublishingEventDataType): Promise<boolean> {
const message: PublishingMessageType = {
type: EventType.API_HITS,
data: obj,
publishedAt: new Date().toISOString(),
};

const publishOptions: PublishOptions = {
persistent: true,
contentType: "application/json",
Expand All @@ -63,7 +51,7 @@ export class EventProducer {
}
try {
const currentChannel = await this.channelManager.getChannel();
const messageBuffer = Buffer.from(JSON.stringify(message));
const messageBuffer = Buffer.from(JSON.stringify(obj));

return new Promise((resolve, reject) => {
const written = currentChannel.publish("", this.queueName, messageBuffer, publishOptions, (err) => {
Expand Down
5 changes: 4 additions & 1 deletion server/src/shared/middleware/zodValidators.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export const validateBody = (schema: z.ZodType<any>) => async (req: Request, res

export const validateQuery = (schema: z.ZodType<any>) => async (req: Request, res: Response, next: NextFunction) => {
try {
req.query = await schema.parseAsync(req.query);
const parsed = await schema.parseAsync(req.query);
// Express 5 exposes req.query as a getter-only accessor, so it can't be
// reassigned outright — mutate the existing object in place instead.
Object.assign(req.query, parsed);
next();
} catch (error: any) {
const formattedErrors =
Expand Down
6 changes: 0 additions & 6 deletions server/src/shared/typings/messaging.typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ export interface EventDataType {
userAgent?: string;
}

export interface PublishingMessageType {
type: EventType;
data: PublishingEventDataType;
publishedAt: string;
}

export interface PublishOptions {
persistent: boolean; // Whether the message should be marked as persistent
contentType: string; // Content type of the message
Expand Down
Loading