Skip to content

Commit

Permalink
Fix invalid buck retrieve from new bucket upload(scrapyd) notificatio…
Browse files Browse the repository at this point in the history
…n endpoint.
  • Loading branch information
Tadjaur committed Jan 13, 2025
1 parent 77450f9 commit 8dbdc85
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 47 deletions.
7 changes: 7 additions & 0 deletions packages/validations/src/validations/itemRoutesValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ export const getSimilarItems = z.object({
limit: z.number(),
});

export const importNotifiedETL = z.object({
bucket_name: z.string(),
file_key: z.string(),
spider_name: z.string(),
});
export type ImportNotifiedETL = z.infer<typeof importNotifiedETL>;

export const importItemHeaders = z.object({
Name: z.string(),
Weight: z.string(),
Expand Down
2 changes: 1 addition & 1 deletion server/src/controllers/item/importItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const importItems = async (c) => {
const parsedHeaders = results.meta.fields ?? [];
try {
const allHeadersPresent = expectedHeaders.every((header) =>
(parsedHeaders as string[]).includes(header),
parsedHeaders.includes(header),
);
if (!allHeadersPresent) {
return reject(
Expand Down
4 changes: 2 additions & 2 deletions server/src/controllers/item/importItemsGlobal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const importItemsGlobal = async (c: Context) => {
const parsedHeaders = results.meta.fields ?? [];
try {
const allHeadersPresent = expectedHeaders.every((header) =>
(parsedHeaders as string[]).includes(header),
parsedHeaders.includes(header),
);
if (!allHeadersPresent) {
return reject(
Expand Down Expand Up @@ -163,7 +163,7 @@ export function importItemsGlobalRoute() {
const parsedHeaders = results.meta.fields ?? [];
try {
const allHeadersPresent = expectedHeaders.every((header) =>
(parsedHeaders as string[]).includes(header),
parsedHeaders.includes(header),
);
if (!allHeadersPresent) {
return reject(
Expand Down
12 changes: 8 additions & 4 deletions server/src/controllers/item/importNotifiedETL.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import * as validator from '@packrat/validations';
import {
bulkAddItemsGlobalService,
parseCSVData,
fetchFromS3,
} from '../../services/item/item.service';
import { User } from '../../drizzle/methods/User';
import { Context } from 'hono';

export const importNotifiedETL = async (c) => {
const params = c.req.query();
const file_name = params.file_key;
export const importNotifiedETL = async (c: Context) => {
const body = await c.req.json<validator.ImportNotifiedETL>();
const file_name = body.file_key;
const bucket_name = body.bucket_name;
const spider_name = body.spider_name;

const endpoint = c.env.BUCKET_ENDPOINT;
const bucket = c.env.BUCKET_NAME;
Expand All @@ -34,7 +38,7 @@ export const importNotifiedETL = async (c) => {

try {
const fileData = await fetchFromS3(
`${endpoint}/${bucket}/${file_name}`,
`${endpoint}/${bucket_name}/${file_name}`,
method,
service,
region,
Expand Down
4 changes: 1 addition & 3 deletions server/src/controllers/packTemplates/getPackTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ export function getPackTemplateRoute() {
return protectedProcedure
.input(validator.getPackTemplate)
.query(async ({ input }) => {
const param = input.id
? { id: input.id }
: { name: input.name as string };
const param = input.id ? { id: input.id } : { name: input.name };
return await getPackTemplateService(param);
});
}
16 changes: 8 additions & 8 deletions server/src/controllers/passport/signInGoogle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ export const signInGoogle = async (c: Context) => {
username,
});

await userClass.generateAuthToken(c.env.JWT_SECRET, user!.id);
await userClass.generateAuthToken(c.env.JWT_SECRET, user.id);

sendWelcomeEmail(
user!.email,
user!.name,
user.email,
user.name,
c.env.STMP_EMAIL,
c.env.SEND_GRID_API_KEY,
);
Expand All @@ -68,7 +68,7 @@ export const signInGoogle = async (c: Context) => {

await userClass.generateAuthToken(
c.env.JWT_SECRET,
alreadyGoogleSignin!.id,
alreadyGoogleSignin.id,
);

if (!alreadyGoogleSignin.googleId) {
Expand Down Expand Up @@ -140,11 +140,11 @@ export function googleSigninRoute() {
username,
});

await userClass.generateAuthToken(env.JWT_SECRET, user!.id);
await userClass.generateAuthToken(env.JWT_SECRET, user.id);

sendWelcomeEmail(
user!.email,
user!.name,
user.email,
user.name,
env.STMP_EMAIL,
env.SEND_GRID_API_KEY,
);
Expand All @@ -157,7 +157,7 @@ export function googleSigninRoute() {

await userClass.generateAuthToken(
env.JWT_SECRET,
alreadyGoogleSignin!.id,
alreadyGoogleSignin.id,
);

if (!alreadyGoogleSignin.googleId) {
Expand Down
2 changes: 1 addition & 1 deletion server/src/drizzle/methods/ItemPacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ItemPacks {
.values(itemPack)
.returning()
.get();
await this.updateScoreIfNeeded(itemPack.packId as string);
await this.updateScoreIfNeeded(itemPack.packId);

return record;
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion server/src/drizzle/methods/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class User {
return DbClient.instance
.update(UserTable)
.set({ ...user, username })
.where(eq(UserTable.id, user.id!))
.where(eq(UserTable.id, user.id))
.returning()
.get();
}
Expand Down
10 changes: 5 additions & 5 deletions server/src/modules/feed/model/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ export class Feed {
// Cast or conditionally apply .having() only if we have valid conditions
const havingConditions = this.generateHavingConditions(modifiers, pack);
if (havingConditions) {
packsQuery = (packsQuery as any).having(havingConditions as any);
packsQuery = packsQuery.having(havingConditions as any);
}
}

if (modifiers) {
const whereConditions = this.generateWhereConditions(modifiers, pack);
if (whereConditions) {
packsQuery = (packsQuery as any).where(whereConditions as any);
packsQuery = packsQuery.where(whereConditions as any);
}
}

Expand Down Expand Up @@ -154,7 +154,7 @@ export class Feed {

let feedQuery: any = null;
if (packsQuery && tripsQuery) {
feedQuery = (packsQuery as any).union(tripsQuery as any);
feedQuery = packsQuery.union(tripsQuery);
} else if (packsQuery) {
feedQuery = packsQuery;
} else if (tripsQuery) {
Expand Down Expand Up @@ -256,7 +256,7 @@ export class Feed {
modifiers: Modifiers,
table: typeof trip | typeof pack,
) {
const conditions: SQL<unknown>[] = [];
const conditions: Array<SQL<unknown>> = [];

if (modifiers?.isPublic !== undefined) {
conditions.push(eq(table.is_public, modifiers.isPublic));
Expand All @@ -277,7 +277,7 @@ export class Feed {
modifiers: Modifiers,
table: typeof trip | typeof pack,
) {
const conditions: SQL<unknown>[] = [];
const conditions: Array<SQL<unknown>> = [];

if (modifiers?.ownerId && modifiers.includeUserFavoritesOnly) {
conditions.push(
Expand Down
2 changes: 1 addition & 1 deletion server/src/routes/geojsonRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ router.get(

const object = await GeojsonStorageService.retrieve(
params.resource as ResourceType,
params.resourceId as string,
params.resourceId,
);

if (!object) {
Expand Down
5 changes: 2 additions & 3 deletions server/src/routes/itemRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ router.get(
tryCatchWrapper(importFromBucket),
);

router.get(
router.post(
'/importNotifiedETL',
// authTokenMiddleware,
// zodParser(validator.importNotifiedETL, 'query'),
zodParser(validator.importNotifiedETL, 'body'),
tryCatchWrapper(importNotifiedETL),
);

Expand Down
6 changes: 3 additions & 3 deletions server/src/services/trip/getTripByIdService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ interface TripResult {
id: string;
name: string;
packs?: {
itemPacks?: { item: any }[];
itemPacks?: Array<{ item: any }>;
};
tripGeojsons?: {
tripGeojsons?: Array<{
geojson?: { geoJSON?: string };
}[];
}>;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions server/src/tests/routes/favorite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ describe('Favorite routes', () => {
passThroughOnException: () => {},
};
caller = await setupTest(env, executionCtx);
user = (await userClass.create({
user = await userClass.create({
email: '[email protected]',
name: 'test',
username: 'test',
password: 'test123',
})) as User;
});
});

beforeEach(async () => {
Expand Down
4 changes: 2 additions & 2 deletions server/src/tests/routes/item.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ describe('Item routes', () => {
name: 'test',
type: 'test',
});
owner = (await userClass.create({
owner = await userClass.create({
email: '[email protected]',
name: 'test',
username: 'test',
password: 'test123',
})) as User;
});

// clear modules cache to ensure that dependents use the latest mock modules
// this prevents unusual assertion failures during reruns in watch mode
Expand Down
4 changes: 2 additions & 2 deletions server/src/tests/routes/pack.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ describe('Pack routes', () => {
passThroughOnException: () => {},
};
caller = await setupTest(env, executionCtx);
owner = (await userClass.create({
owner = await userClass.create({
email: '[email protected]',
name: 'test',
username: 'test',
password: 'test123',
})) as User;
});

// clear modules cache to ensure that dependents use the latest mock modules
// this prevents unusual assertion failures during reruns in watch mode
Expand Down
4 changes: 2 additions & 2 deletions server/src/tests/routes/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ describe('Template Routes', () => {

describe('addTemplate', () => {
it('should create a template', async () => {
const user = (await userClass.create({
const user = await userClass.create({
email: '[email protected]',
name: 'test',
username: 'test',
password: 'test123',
})) as User;
});
const result = await caller.addTemplate({
type: 'pack',
createdBy: user.id,
Expand Down
4 changes: 2 additions & 2 deletions server/src/tests/routes/trip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ describe('Trip Routes', () => {
passThroughOnException: () => {},
};
caller = await setupTest(env, executionCtx);
owner = (await userClass.create({
owner = await userClass.create({
email: '[email protected]',
name: 'test',
username: 'test',
password: 'test123',
})) as User;
});
const pack = await packClass.create({
name: 'test',
owner_id: owner.id,
Expand Down
4 changes: 2 additions & 2 deletions server/src/trpc/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const findUser = async (
let user: User | null = null;
try {
const decoded = await jwt.verify(token, jwtSecret);
user = (await userRepository.findUser({
user = await userRepository.findUser({
userId: decoded.id as string,
})) as User;
});
} catch {
// pass
}
Expand Down
6 changes: 3 additions & 3 deletions server/src/vector/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8dbdc85

Please sign in to comment.