Skip to content

Commit

Permalink
(WEB-98) update payload from server to client to hide ids
Browse files Browse the repository at this point in the history
  • Loading branch information
GetBlackBoxSolutions committed Sep 14, 2024
1 parent 44d44db commit fe3a6cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
22 changes: 21 additions & 1 deletion src/app/api/people/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,33 @@ import { Databases } from 'appwrite';

import { NextResponse } from 'next/server';

interface Speaker {
$id: string;
DocumentID: number;
isAdmin: boolean;
fullName: string;
xUrl?: string;
linkedInUrl?: string;
imageUrl?: string;
}

const databases = new Databases(client);

export async function GET() {
const response = await databases.listDocuments(
process.env.APPWRITE_DATABASE_ID as string,
'peoples'
);
const peopleData = response.documents.map((doc) => {
return {
documentId: doc.$id,
isAdmin: doc.isAdmin,
fullName: doc.fullName,
xUrl: doc.xUrl,
linkedInUrl: doc.linkedInUrl,
imageUrl: doc.imageUrl,
};
});

return NextResponse.json(response);
return NextResponse.json(peopleData);
}
9 changes: 4 additions & 5 deletions src/app/community/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import Section from '../components/Section/section';
import { useQuery } from '@tanstack/react-query';

interface Speaker {
$id: string;
DocumentID: number;
documentId: number;
isAdmin: boolean;
fullName: string;
xUrl?: string;
Expand All @@ -23,7 +22,7 @@ export default function CommunityPage() {
return response.json();
},
});
const peopleData = (peopleDataResponse?.documents ?? []) as Speaker[];
const peopleData = (peopleDataResponse ?? []) as Speaker[];
if (isLoading) {
return <h1>Loading...</h1>;
}
Expand Down Expand Up @@ -66,7 +65,7 @@ export default function CommunityPage() {
.filter((p) => p.isAdmin)
.map((person) => (
<Person
key={person.$id}
key={person.documentId}
fullName={person.fullName}
twitterUrl={person.xUrl}
linkedinUrl={person.linkedInUrl}
Expand All @@ -80,7 +79,7 @@ export default function CommunityPage() {
.filter((p) => !p.isAdmin)
.map((person) => (
<Person
key={person.$id}
key={person.documentId}
fullName={person.fullName}
twitterUrl={person.xUrl}
linkedinUrl={person.linkedInUrl}
Expand Down

0 comments on commit fe3a6cf

Please sign in to comment.