Skip to content

Commit

Permalink
Server type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pinocchio-life-like committed Dec 24, 2024
1 parent 37c784a commit 7a2209a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion server/src/trpc/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DbClient } from '../db/client';
import { VectorClient } from '../vector/client';
import { AiClient } from '../integrations/ai/client';
import { type R2Bucket } from '@cloudflare/workers-types';
import { GeojsonStorageService } from 'src/services/geojsonStorage';
import { GeojsonStorageService } from '../services/geojsonStorage';

let DB: D1Database;

Expand Down
14 changes: 9 additions & 5 deletions server/src/trpc/utils/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TRPCError } from '@trpc/server';
import { User as UserRepository } from '../../drizzle/methods/User';
import { type User } from 'src/db/schema';
import { type User } from '../../db/schema';
import * as jwt from 'hono/jwt';

// import * as jwt from 'hono/jwt';
Expand Down Expand Up @@ -35,13 +35,17 @@ const extractToken = (req: Request): string | null => {
* @param {string} jwtSecret - The JWT secret.
* @returns {Promise<User>} - The user associated with the token. Resolves to null if token couldn't be verified or user is not found.
*/
const findUser = async (token: string, jwtSecret: string): Promise<User> => {
const findUser = async (
token: string,
jwtSecret: string,
): Promise<User | null> => {
const userRepository = new UserRepository();
let user: User = null;
// const user: any = await userClass.validateResetToken(token, jwtSecret);
let user: User | null = null;
try {
const decoded = await jwt.verify(token, jwtSecret);
user = await userRepository.findUser({ userId: decoded.id as string });
user = (await userRepository.findUser({
userId: decoded.id as string,
})) as User;
} catch {
// pass
}
Expand Down
12 changes: 7 additions & 5 deletions server/src/utils/item.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import { prisma } from '../prisma';

import { Item } from 'src/db/schema';
import { Item } from '../db/schema';

// /**
// * Validates the item data and creates a new item.
Expand Down Expand Up @@ -49,10 +49,12 @@ export const summarizeItem = (item: Item & { category?: { name: string } }) => {
const details = item.productDetails;
const description = item.description;

const parsedProductDetails = Object.entries(details).reduce(
(acc, [key, value]) => `${acc},${key}:${value}`,
'',
);
const parsedProductDetails = details
? Object.entries(details).reduce(
(acc, [key, value]) => `${acc},${key}:${value}`,
'',
)
: '';

return `Title: ${productName}\nCategory: ${category}\nDetails: ${parsedProductDetails}\nDescription: ${description}`;
};
8 changes: 4 additions & 4 deletions server/src/vector/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class VectorClient {
metadata: Metadata;
}>,
) {
const contentList = [];
const contentList: string[] = [];
for (const record of records) {
contentList.push(record.content);
}
Expand All @@ -219,10 +219,10 @@ class VectorClient {
namespace: string;
metadata: Metadata;
}>(contentList, (embedding, index) => ({
id: records[index].id,
id: records[index]!.id,
values: embedding,
namespace: records[index].namespace,
metadata: records[index].metadata,
namespace: records[index]!.namespace,
metadata: records[index]!.metadata,
}));

await this.upsert(values);
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"compilerOptions": {
"strictNullChecks": true,
"noUncheckedIndexedAccess": true,
"module": "commonJS",
"module": "node16",
"moduleResolution": "node16",
"paths": {
"app/*": ["./packages/app/*"],
"@packrat/api/*": ["./packages/api/*"],
Expand Down

0 comments on commit 7a2209a

Please sign in to comment.