-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* hope this works * Run Prettier --------- Co-authored-by: Stanley Zheng <[email protected]> Co-authored-by: szheng31 <[email protected]> Co-authored-by: Isaac Liu <[email protected]>
- Loading branch information
1 parent
293f7f5
commit f299ac7
Showing
6 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Table } from 'antd'; | ||
|
||
import useSWR from 'swr'; | ||
import { DietaryData, ResponseError } from '../../../types/database'; | ||
import { RequestType, useCustomSWR } from '../../../utils/request-utils'; | ||
import React, { useState, useRef, useEffect } from 'react'; | ||
|
||
export default function Analytics() { | ||
const { data: dietaryData, error: dietaryError } = useCustomSWR<DietaryData[]>({ | ||
url: '/api/dietary-restrictions', | ||
method: RequestType.GET, | ||
errorMessage: 'Failed to get list of dietary data.', | ||
}); | ||
console.log('dietaryData:', dietaryData); // Add this to debug | ||
|
||
const columns = [ | ||
{ | ||
title: 'Dietary Restriction', | ||
dataIndex: '_id', // Corresponds to the _id field in the data | ||
key: '_id', | ||
}, | ||
{ | ||
title: 'Count', | ||
dataIndex: 'count', // Corresponds to the count field in the data | ||
key: 'count', | ||
}, | ||
]; | ||
|
||
// Format the dietary data to add a unique 'key' for each row | ||
const formattedDietaryData = dietaryData | ||
? dietaryData.map((restriction: DietaryData) => ({ | ||
...restriction, | ||
key: restriction._id, // Use _id as key or fallback to index | ||
})) | ||
: undefined; | ||
|
||
return ( | ||
<> | ||
<Table columns={columns} dataSource={formattedDietaryData}></Table> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
import dbConnect from '../../middleware/database'; | ||
import { getSession } from 'next-auth/react'; | ||
import Application from '../../models/application'; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) { | ||
const session = await getSession({ req }); | ||
|
||
await dbConnect(); | ||
|
||
switch (req.method) { | ||
case 'GET': | ||
const count = await Application.aggregate([ | ||
{ | ||
$unwind: '$dietaryRestrictions', | ||
}, | ||
{ | ||
$group: { | ||
_id: '$dietaryRestrictions', | ||
count: { $sum: 1 }, | ||
}, | ||
}, | ||
{ | ||
$sort: { count: -1 }, | ||
}, | ||
]); | ||
return res.status(200).send(JSON.stringify(count)); | ||
default: | ||
return res.status(405).send('Method not supported brother'); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters