Skip to content

Commit

Permalink
my request not getting more than one bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ElyasMehraein committed Apr 30, 2024
1 parent ffa2fee commit 79faac3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GET } from "@/app/api/auth/me/route"
export async function POST(req) {
const response = await GET(req)
const user = await response.json()
const { MyAnswer, requestID } = await req.json()
const { requestID } = await req.json()

const userPrimeJobBusiness = await BusinessModel.findOne({ _id: user.primeJob })

Expand All @@ -22,8 +22,10 @@ export async function POST(req) {
{ message: "you are not business Agent" },
{ status: 406 })
}
const update = MyAnswer === 'accept' ? { acceptedBy: user.primeJob } : { needMoreInfo: user.primeJob };
await RequestModel.findOneAndUpdate({ _id: requestID }, update)
const Request = await RequestModel.findOne({ _id: requestID })
Request.acceptedBy.addToSet(user.primeJob)
await Request.save();

return Response.json(
{ message: "your answer added to the Request" },
{ status: 201 }
Expand Down
13 changes: 6 additions & 7 deletions components/templates/index/Requests/MyRequestFrame.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,20 @@ const MyRequestFrame = ({ request }) => {
</AccordionSummary>
{
< AccordionDetails >
{request.acceptedBy?.map((acceptor) => {
return (
{request.acceptedBy?.map((acceptor) => (
<Box key={acceptor._id}>
<ListItemButton onClick={() => router.push(`/${acceptor.businessName}`)}>
<ListItemButton onClick={() => router.push(`/${acceptor.businessName}`)}>
<ListItemAvatar >
<Avatar sx={{ width: 40, height: 40 }}>
<ItsAvatar isAvatar={acceptor.isAvatar} userCodeOrBusinessBrand={acceptor.businessName} alt="workers avatar" />
</Avatar>
</ListItemAvatar>
<ListItemText align='right' primary={request.requesterBusiness.businessName} secondary={request.requesterBusiness.businessBrand} />
<ListItemText align='right' primary={acceptor.businessName} secondary={acceptor.businessBrand} />
<Typography sx={{ color: 'text.secondary' }}>{acceptor.bio}</Typography>
</ListItemButton>
<Typography sx={{ color: 'text.secondary' }}>{request.requesterBusiness.bio}</Typography>
</Box>
)
})}
))}

</AccordionDetails>
}
</Accordion>
Expand Down
16 changes: 8 additions & 8 deletions components/templates/index/Requests/OthersRequest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export default function OthersRequest({ user, distinctGuilds }) {
const userNonPrimeJobBusinesses = user.businesses.filter(
(business) => business._id !== user.primeJob
);

const userPrimeJobBusinessGuild = userPrimeJobBusinesses.map((business) => business.guildname)
const userNonPrimeJobBusinessesGuilds = userNonPrimeJobBusinesses.map((business) => business.guildname)
const userBusinessesGuilds = [...userPrimeJobBusinessGuild,...userNonPrimeJobBusinessesGuilds]
const userBusinessesGuilds = [...userPrimeJobBusinessGuild, ...userNonPrimeJobBusinessesGuilds]

useEffect(() => {
const getRequests = async () => {
Expand Down Expand Up @@ -77,11 +77,11 @@ export default function OthersRequest({ user, distinctGuilds }) {
return Number(business.agentCode) === user.code
})

async function acceptOrAskForMoreInfo(MyAnswer, requestID) {
const res = await fetch('api/requests/acceptOrAskForMoreInfo', {
async function acceptRequest(requestID) {
const res = await fetch('api/requests/acceptRequest', {
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ MyAnswer, requestID })
body: JSON.stringify({ requestID })
})
if (res.status === 500) {
console.log("server error", res);
Expand All @@ -98,15 +98,15 @@ export default function OthersRequest({ user, distinctGuilds }) {
const uniqueGuilds = [...new Set(requests.map((request) => request.guild))];
return uniqueGuilds.map((guild) => (
<Box key={guild}>
<Divider sx={{ mb: 1, fontSize: '12px' ,fontWeight: 'bold'}} className={"text-extrabold"} textAlign="left">
<Divider sx={{ mb: 1, fontSize: '12px', fontWeight: 'bold' }} className={"text-extrabold"} textAlign="left">
{guild}
</Divider>
{requests.filter((request) => request.guild === guild).map((request) => {
const isAlredyAccepted = request.acceptedBy.some((acceptor) => {
return acceptor === user.primeJob
})
return (
<Accordion key={request._id} sx={{bgcolor : blue[50]}} >
<Accordion key={request._id} sx={{ bgcolor: blue[50] }} >
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel3-content"
Expand Down Expand Up @@ -136,7 +136,7 @@ export default function OthersRequest({ user, distinctGuilds }) {
<AccordionActions>
{isUserAreBusinessAgent &&
<>
<Button disabled={isAlredyAccepted} onClick={() => acceptOrAskForMoreInfo("accept", request._id)} variant="outlined">تایید درخواست</Button>
<Button disabled={isAlredyAccepted} onClick={() => acceptRequest(request._id)} variant="outlined">تایید درخواست</Button>
</>

}
Expand Down

0 comments on commit 79faac3

Please sign in to comment.