-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: system to identify already subscribed plan
- Loading branch information
1 parent
317b8c4
commit 3de57bc
Showing
3 changed files
with
92 additions
and
4 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,59 @@ | ||
import axios from "axios"; | ||
|
||
const API_URL= `${process.env.NEXT_PUBLIC_API_URL}/api/v1/graphql` | ||
|
||
async function getAlreadySubscribed(id, token) { | ||
try { | ||
const res = await axios({ | ||
url: API_URL, | ||
method: "POST", | ||
headers: { | ||
Authorization: `Bearer ${token}` | ||
}, | ||
data: { | ||
query: ` | ||
query { | ||
allAccount (id: "${id}"){ | ||
edges { | ||
node { | ||
id | ||
internalSubscription { | ||
edges { | ||
node { | ||
canceledAt | ||
createdAt | ||
isActive | ||
stripeSubscription | ||
planInterval | ||
nextBillingCycle | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` | ||
} | ||
}) | ||
const data = res.data | ||
return data | ||
} catch (error) { | ||
console.error(error) | ||
return "err" | ||
} | ||
} | ||
|
||
export default async function handler(req, res) { | ||
const token = () => { | ||
if(req.query.q) return atob(req.query.q) | ||
return req.cookies.token | ||
} | ||
|
||
const result = await getAlreadySubscribed(atob(req.query.p), token()) | ||
|
||
if(result.errors) return res.status(500).json({error: result.errors}) | ||
if(result === "err") return res.status(500).json({error: "err"}) | ||
|
||
res.status(200).json(result?.data?.allAccount?.edges[0]?.node?.internalSubscription) | ||
} |
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