Skip to content

Commit

Permalink
format: make the code prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Dec 15, 2024
1 parent 3b2b585 commit 3f72c94
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
14 changes: 9 additions & 5 deletions apps/api/app/v1/[[...route]]/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const app = new Hono()
message: "Oops! seems like your session is expired",
status: 400,
},
400
400,
);
}

Expand Down Expand Up @@ -68,10 +68,11 @@ const app = new Hono()
const cursor = c.req.query("cursor");
const take = parseInt(c.req.query("take") || "10");
const cacheKey = `users:all:${cursor || "start"}:${take}`;
let response: { nextCursor: string | null, users: User[] } | null = null;
let response: { nextCursor: string | null; users: User[] } | null = null;

try {
const cachedData: { nextCursor: string | null, users: User[] } | null = await cache.get(cacheKey);
const cachedData: { nextCursor: string | null; users: User[] } | null =
await cache.get(cacheKey);
if (cachedData) {
response = cachedData;
console.log("Returned user list from cache");
Expand Down Expand Up @@ -142,12 +143,15 @@ const app = new Hono()
try {
await cache.set(cacheKey, user, { ex: CACHE_EXPIRY });
} catch (cacheError) {
console.error("Error storing user data in cache (by ID):", cacheError);
console.error(
"Error storing user data in cache (by ID):",
cacheError,
);
}
}
}

return c.json({ user }, 200);
});

export default app;
export default app;
51 changes: 38 additions & 13 deletions apps/api/app/v1/[[...route]]/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ const app = new Hono()
const cursor = c.req.query("cursor");
const take = parseInt(c.req.query("take") || "10");
const cacheKey = `workspaces:all:${cursor || "start"}:${take}`;
let response: { nextCursor: string | null, workspaces: Workspace[] } | null = null;
let response: {
nextCursor: string | null;
workspaces: Workspace[];
} | null = null;

try {
const cachedData: { nextCursor: string | null, workspaces: Workspace[] } | null = await cache.get(cacheKey);
const cachedData: {
nextCursor: string | null;
workspaces: Workspace[];
} | null = await cache.get(cacheKey);
if (cachedData) {
response = cachedData;
console.log("Returned workspace list from cache");
Expand All @@ -51,14 +57,18 @@ const app = new Hono()
},
});

const nextCursor = workspaces.length > 0 ? workspaces[workspaces.length - 1].id : null;
const nextCursor =
workspaces.length > 0 ? workspaces[workspaces.length - 1].id : null;
response = { nextCursor, workspaces };

console.log("Fetched workspace list from database (all)");
try {
await cache.set(cacheKey, response, { ex: CACHE_EXPIRY });
} catch (cacheError) {
console.error("Error storing workspace list in cache (all):", cacheError);
console.error(
"Error storing workspace list in cache (all):",
cacheError,
);
}
}

Expand Down Expand Up @@ -98,7 +108,10 @@ const app = new Hono()
try {
await cache.set(cacheKey, workspace, { ex: CACHE_EXPIRY });
} catch (cacheError) {
console.error("Error storing workspace data in cache (by ID):", cacheError);
console.error(
"Error storing workspace data in cache (by ID):",
cacheError,
);
}
}

Expand Down Expand Up @@ -161,19 +174,24 @@ const app = new Hono()
const workspace = await prisma.workspace.create({
data: {
name: body.name,
userId: userId
userId: userId,
},
});

if (!workspace) {
return c.json({ message: "failed to create workspace", status: 404 }, 404);
return c.json(
{ message: "failed to create workspace", status: 404 },
404,
);
}

// Invalidate cache for user workspaces
const userWorkspacesCacheKey = `workspaces:user:${userId}`;
try {
await cache.del(userWorkspacesCacheKey);
console.log(`Invalidated cache for user workspaces: ${userWorkspacesCacheKey}`);
console.log(
`Invalidated cache for user workspaces: ${userWorkspacesCacheKey}`,
);
} catch (cacheError) {
console.error("Error invalidating user workspaces cache:", cacheError);
}
Expand Down Expand Up @@ -217,15 +235,22 @@ const app = new Hono()
try {
await Promise.all([
cache.del(specificWorkspaceCacheKey),
cache.del(userWorkspacesCacheKey)
cache.del(userWorkspacesCacheKey),
]);
console.log(`Invalidated cache for workspace: ${specificWorkspaceCacheKey}`);
console.log(`Invalidated cache for user workspaces: ${userWorkspacesCacheKey}`);
console.log(
`Invalidated cache for workspace: ${specificWorkspaceCacheKey}`,
);
console.log(
`Invalidated cache for user workspaces: ${userWorkspacesCacheKey}`,
);
} catch (cacheError) {
console.error("Error invalidating workspace and user workspaces cache:", cacheError);
console.error(
"Error invalidating workspace and user workspaces cache:",
cacheError,
);
}

return c.json({ deletedWorkspace: workspace }, 200);
});

export default app;
export default app;

0 comments on commit 3f72c94

Please sign in to comment.