nsarrazin commited on
Commit
c3aee90
·
1 Parent(s): 55af7c5

fix: assistants flow

Browse files
src/routes/api/assistants/+server.ts CHANGED
@@ -14,6 +14,8 @@ export async function GET({ url, locals }) {
14
  const username = url.searchParams.get("user");
15
  const query = url.searchParams.get("q")?.trim() ?? null;
16
  const showUnfeatured = url.searchParams.get("showUnfeatured") === "true";
 
 
17
  let user: Pick<User, "_id"> | null = null;
18
  if (username) {
19
  user = await collections.users.findOne<Pick<User, "_id">>(
@@ -32,7 +34,7 @@ export async function GET({ url, locals }) {
32
  if (!user) {
33
  // only show featured assistants on the community page
34
  shouldBeFeatured = { review: ReviewStatus.APPROVED };
35
- } else {
36
  // on a user page show assistants that have been approved or are pending
37
  shouldBeFeatured = { review: { $in: [ReviewStatus.APPROVED, ReviewStatus.PENDING] } };
38
  }
 
14
  const username = url.searchParams.get("user");
15
  const query = url.searchParams.get("q")?.trim() ?? null;
16
  const showUnfeatured = url.searchParams.get("showUnfeatured") === "true";
17
+ const createdByCurrentUser = locals.user?.username && locals.user.username === username;
18
+
19
  let user: Pick<User, "_id"> | null = null;
20
  if (username) {
21
  user = await collections.users.findOne<Pick<User, "_id">>(
 
34
  if (!user) {
35
  // only show featured assistants on the community page
36
  shouldBeFeatured = { review: ReviewStatus.APPROVED };
37
+ } else if (!createdByCurrentUser) {
38
  // on a user page show assistants that have been approved or are pending
39
  shouldBeFeatured = { review: { $in: [ReviewStatus.APPROVED, ReviewStatus.PENDING] } };
40
  }
src/routes/assistants/+page.server.ts CHANGED
@@ -20,6 +20,7 @@ export const load = async ({ url, locals }) => {
20
  const query = url.searchParams.get("q")?.trim() ?? null;
21
  const sort = url.searchParams.get("sort")?.trim() ?? SortKey.TRENDING;
22
  const showUnfeatured = url.searchParams.get("showUnfeatured") === "true";
 
23
 
24
  let user: Pick<User, "_id"> | null = null;
25
  if (username) {
@@ -39,7 +40,7 @@ export const load = async ({ url, locals }) => {
39
  if (!user) {
40
  // only show featured assistants on the community page
41
  shouldBeFeatured = { review: ReviewStatus.APPROVED };
42
- } else {
43
  // on a user page show assistants that have been approved or are pending
44
  shouldBeFeatured = { review: { $in: [ReviewStatus.APPROVED, ReviewStatus.PENDING] } };
45
  }
 
20
  const query = url.searchParams.get("q")?.trim() ?? null;
21
  const sort = url.searchParams.get("sort")?.trim() ?? SortKey.TRENDING;
22
  const showUnfeatured = url.searchParams.get("showUnfeatured") === "true";
23
+ const createdByCurrentUser = locals.user?.username && locals.user.username === username;
24
 
25
  let user: Pick<User, "_id"> | null = null;
26
  if (username) {
 
40
  if (!user) {
41
  // only show featured assistants on the community page
42
  shouldBeFeatured = { review: ReviewStatus.APPROVED };
43
+ } else if (!createdByCurrentUser) {
44
  // on a user page show assistants that have been approved or are pending
45
  shouldBeFeatured = { review: { $in: [ReviewStatus.APPROVED, ReviewStatus.PENDING] } };
46
  }