Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ElyasMehraein committed Apr 26, 2024
1 parent 0239129 commit 280e35b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/liara.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
- name: update-liara
env:
LIARA_TOKEN: ${{ secrets.LIARA_API_TOKEN }}
Expand Down
86 changes: 46 additions & 40 deletions app/[subDirectory]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,67 @@ import Business from '@/components/templates/business/business'
import UserModel from '@/models/User'
import Profile from '@/components/templates/Profile/Profile'
import { redirect } from 'next/navigation'
import { POST } from '../api/auth/logout/route';
export default async function subDirectory({ params }) {

try {
const token = cookies().get("token")?.value;
const tokenPayLoad = verifyToken(token);

export default async function subDirectory({ params }) {
connectToDB()
let logedUserCode = null;

const token = cookies().get("token")?.value;
const tokenPayLoad = verifyToken(token);
if (tokenPayLoad) {
logedUserCode = JSON.parse(JSON.stringify(await UserModel.findOne(
{ _id: tokenPayLoad.id },
"-_id code"
))).code;
}

connectToDB()
let logedUserCode = null;
if (isNaN(params.subDirectory)) {

if (tokenPayLoad) {
logedUserCode = JSON.parse(JSON.stringify(await UserModel.findOne(
{ _id: tokenPayLoad.id },
"-_id code"
))).code;
}
const business = JSON.parse(JSON.stringify(await BusinessModel.findOne({
businessName: params.subDirectory
}).populate("workers")));

if (isNaN(params.subDirectory)) {
if (!business) {
console.log("business not found in DB");
notFound()
}

const business = JSON.parse(JSON.stringify(await BusinessModel.findOne({
businessName: params.subDirectory
}).populate("workers")));
const bills = JSON.parse(JSON.stringify(await BillModel.find({
from: business._id,
isAccept: true
}).populate("to")));

return (
<Business business={business}
logedUserCode={logedUserCode}
bills={bills}
/>
)

if (!business) {
console.log("business not found in DB");
notFound()
}

const bills = JSON.parse(JSON.stringify(await BillModel.find({
from: business._id,
isAccept: true
}).populate("to")));


const user = JSON.parse(JSON.stringify(await UserModel.findOne(
{ code: params.subDirectory },
).populate("businesses")))

if (!user) {
console.log("user not found in DB");
notFound()
}
return (
<Business business={business}
<Profile user={user}
logedUserCode={logedUserCode}
bills={bills}
/>
)
} catch (err) {
console.error('server error in subDirectory:', err);
POST()
redirect("/w");
}



const user = JSON.parse(JSON.stringify(await UserModel.findOne(
{ code: params.subDirectory },
).populate("businesses")))

if (!user) {
console.log("user not found in DB");
notFound()
}
return (
<Profile user={user}
logedUserCode={logedUserCode}
/>
)
}

12 changes: 6 additions & 6 deletions app/all/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { notFound } from "next/navigation";

export default async function page() {
try {
// connectToDB();
// console.log("db connected for allBusinesses");
// const businesses = JSON.parse(JSON.stringify(await BusinessModel.find({}, "businessName bio businessBrand isAvatar")));
// console.log("allBusinesses data is", businesses);
await connectToDB();
console.log("db connected for allBusinesses");
const businesses = JSON.parse(JSON.stringify(await BusinessModel.find({}, "businessName bio businessBrand isAvatar")));
console.log("allBusinesses data is", businesses);


return (
// <AllBusinesses businesses={businesses} />
<h1>تست</h1>
<AllBusinesses businesses={businesses} />
);
} catch (err) {

console.error('Error fetching businesses:', err);
// return notFound();
}
Expand Down
11 changes: 6 additions & 5 deletions components/templates/allBusinesses/AllBusinesses.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import { Accordion, AccordionDetails, Chip } from "@mui/material";
import QuestionMarkOutlinedIcon from '@mui/icons-material/QuestionMarkOutlined';

import ItsAvatar from '@/components/modules/ItsAvatar'
import dynamic from 'next/dynamic'
const ShowMyLocation = dynamic(() => import('@/components/modules/ShowMyLocation'), { ssr: false })
// import dynamic from 'next/dynamic'
// const ShowMyLocation = dynamic(() => import('@/components/modules/ShowMyLocation'), { ssr: false })


export default function AllBusinesses({ businesses }) {
const router = useRouter()

const [expanded, setExpanded] = useState(false);

return (
Expand All @@ -41,7 +40,7 @@ export default function AllBusinesses({ businesses }) {
<AllBusinessesText />
</AccordionDetails>
</Accordion>
{businesses.map((business) => {
{businesses ? businesses.map((business) => {
return (
<List key={business._id} sx={{ width: '100%', maxWidth: 700, bgcolor: 'background.paper' }}>
<ListItem>
Expand All @@ -56,7 +55,9 @@ export default function AllBusinesses({ businesses }) {
</ListItem>
</List>
)
})}
}) :
<Typography>کسب و کاری برای نمایش وجود ندارد </Typography>
}
</Box>
</Container>
</>
Expand Down
3 changes: 2 additions & 1 deletion configs/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ const connectToDB = async () => {
if (mongoose.connections[0].readyState) {
return true;
}

try {
await mongoose.connect(process.env.MONGO_URI);
console.log("Connect To DB Successfully :))");
return true
} catch (err) {
console.error("DB Connection Error:", err);
throw err;
Expand Down

0 comments on commit 280e35b

Please sign in to comment.