Skip to content

Commit

Permalink
hotfix: serialized boolean parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
arielweinberger committed Dec 31, 2023
1 parent f112663 commit 8111573
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
6 changes: 3 additions & 3 deletions apps/server/src/app/reporting/reporting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ export class ReportingService {
type: "ChatCompletion",
requestTimestamp: request.timestamp,
requestBody: JSON.stringify(request.body),
isError: (response as any).status !== 200 ? 1 : 0,
isError: (response as any).status !== 200,
responseStatusCode: (response as any).status,
responseTimestamp: response.timestamp,
responseBody: JSON.stringify(response.body),
cacheEnabled: cacheEnabled ? 1 : 0,
cacheHit: cacheHit ? 1 : 0,
cacheEnabled: cacheEnabled,
cacheHit: cacheHit,
promptId: report.metadata.promptId || null,
};

Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/app/reporting/requests.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export class RequestReportsResolver {
data.reportId,
data.projectId
);

console.log(result);

return result;
}

Expand Down
29 changes: 7 additions & 22 deletions libs/types/src/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,26 @@ export interface ReportSchema {
provider: string;
requestTimestamp: string;
requestBody: string;
isError: number;
isError: boolean;
responseStatusCode: number;
responseTimestamp: string;
responseBody: string;
cacheEnabled: number;
cacheHit: number;
cacheEnabled: boolean;
cacheHit: boolean;
promptId: string;
}

export interface SerializedReport
extends Omit<
ReportSchema,
"requestBody" | "isError" | "responseBody" | "cacheEnabled" | "cacheHit"
> {
extends Omit<ReportSchema, "requestBody" | "responseBody"> {
requestBody: Record<string, any>;
isError: boolean;
responseBody: Record<string, any>;
cacheEnabled: boolean;
cacheHit: boolean;
}

export const serializeReport = (doc: ReportSchema): SerializedReport => {
return {
...doc,
requestBody: JSON.parse(doc.requestBody),
isError: doc.isError === 1,
responseBody: JSON.parse(doc.responseBody),
cacheEnabled: doc.cacheEnabled === 1,
cacheHit: doc.cacheHit === 1,
};
};

Expand All @@ -62,23 +53,17 @@ export interface PaginatedReportsSchema {
modelAuthor: string;
provider: string;
responseStatusCode: number;
cacheEnabled: number;
cacheHit: number;
promptId: string;
}

export interface SerializedPaginatedReport
extends Omit<PaginatedReportsSchema, "cacheEnabled" | "cacheHit"> {
cacheEnabled: boolean;
cacheHit: boolean;
promptId: string;
}

export type SerializedPaginatedReport = PaginatedReportsSchema;

export const serializePaginatedReport = (
doc: PaginatedReportsSchema
): SerializedPaginatedReport => {
return {
...doc,
cacheEnabled: doc.cacheEnabled === 1,
cacheHit: doc.cacheHit === 1,
};
};

0 comments on commit 8111573

Please sign in to comment.