Skip to content

Commit

Permalink
open special class
Browse files Browse the repository at this point in the history
  • Loading branch information
okeken committed Sep 30, 2023
1 parent db81bc8 commit 83871f2
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 92 deletions.
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ CLOUDINARY_NAME=*************
CLOUDINARY_API_KEY=***************
CLOUDINARY_API_SECRET=***************
FLW_PUBLIC_KEY=***************


2 changes: 1 addition & 1 deletion config/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const registrationPaused = false;
export const TRAINING_CLOSED = {
web2: !isOpened,
web3: true,
specialClass: true,
specialClass:false,
cairo: true,
};

Expand Down
20 changes: 10 additions & 10 deletions server/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ export const webPayment = {

export const specialClassPayment = {
["Html, CSS, intro to JavaScript"]: {
naira: isDev ? 50000 : 500,
USD: 70,
naira: isDev ? 500 : 142500,
USD: 150,
},

["JavaScript, react, typescript"]: {
naira: isDev ? 700 : 70000,
USD: 100,
naira: isDev ? 700 : 142500,
USD: 150,
},
["JavaScript, nodejs"]: {
naira: isDev ? 700 : 70000,
USD: 100,
naira: isDev ? 700 : 142500,
USD: 150,
},
["Go"]: {
naira: isDev ? 210 : 210000,
USD: 300,
naira: isDev ? 210 : 142500,
USD: 150,
},
["Solidity"]: {
naira: isDev ? 210 : 210000,
USD: 300,
naira: isDev ? 210 : 142500,
USD: 150,
},
};

Expand Down
1 change: 1 addition & 0 deletions server/mailer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const sendEmail = async (data) => {
}),
};


if (!final?.file) return;

let userDb = final?.userDb;
Expand Down
21 changes: 21 additions & 0 deletions src/pages/api/country.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'


export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {

let apiKey = process.env.IP_KEY;
try{
const result = await fetch(`https://api.ipdata.co?api-key=${apiKey}`)
.then(info=>info.json())
.catch(e=>"Error")
return res.status(200).json({ data:result })
}
catch(e){
return res.status(500).json({ data:{} })
}

}
21 changes: 15 additions & 6 deletions src/pages/api/pyt-webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { verifyPaymentSchema } from "schema";
import { ISmsData } from "types";
import { sendSms } from "@server/sms";
import validate from "@server/validate";
import { isDev, userEmail, webPayment } from "@server/config";
import { isDev, specialClassPayment, userEmail, webPayment } from "@server/config";
import reportError from "@server/services/report-error";

const router = createRouter<NextApiRequest, NextApiResponse>();
Expand Down Expand Up @@ -61,7 +61,7 @@ router.post(async (req: NextApiRequest, res: NextApiResponse) => {

const track = result?.data?.meta?.track;
const userDb = tracks[track];

if (!userDb)
return res.status(404).json({
status: false,
Expand Down Expand Up @@ -97,14 +97,23 @@ router.post(async (req: NextApiRequest, res: NextApiResponse) => {
}

let expectedAmount = 0;
const expectedCurrency = "NGN";
let expectedCurrency = Boolean(result?.data?.meta?.isNaira) ? "NGN" : "USD";

if (track === Tracks.web2 || track === Tracks.web3) {
expectedAmount = webPayment.naira;
expectedCurrency ="NGN"
expectedAmount = webPayment.naira;
}

if(track===Tracks.specialClass){
if(Boolean(result?.data?.meta?.isNaira)){
expectedAmount = specialClassPayment.Solidity.naira
} else {
expectedAmount = specialClassPayment.Solidity.USD
}
}

if (expectedAmount === 0) {
return res.status(429).json({
return res.status(422).json({
message: "amount can not be zero",
});
}
Expand All @@ -130,7 +139,7 @@ router.post(async (req: NextApiRequest, res: NextApiResponse) => {
name: userDetails.name,
type: userDetails.currentTrack,
currentTrack: userDetails.currentTrack,
file: userEmail?.[userDetails?.currentTrack],
file: userDetails?.currentTrack==Tracks.specialClass ? "webemail":userEmail?.[userDetails?.currentTrack],
userDb,
}),
]);
Expand Down
11 changes: 8 additions & 3 deletions src/pages/api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { createRouter } from "next-connect";
import connectDB, { closeDB } from "@server/config/database";
import web3userDb from "@server/models/cohortUsers";
import web2UserDb from "@server/models/web2";
import specialClassDb from "@server/models/specialClass";
import { PaymentStatus, Tracks } from "enums";
import reportError from "@server/services/report-error";
import { isDev } from "@server/config";

const router = createRouter<NextApiRequest, NextApiResponse>();


interface IQuery {
currentTrack?: Tracks | undefined;
page?: number | string;
Expand Down Expand Up @@ -36,21 +37,25 @@ router
let userDb;
const { currentTrack, paymentStatus }: IQuery = req.query;

if(currentTrack === "web2"){
if(currentTrack === Tracks.web2){
userDb = web2UserDb
}

if(currentTrack === "web3"){
if(currentTrack ===Tracks.web3){
userDb = web3userDb
}

if(currentTrack ===Tracks.specialClass){
userDb = specialClassDb
}


try {

const users = await userDb.find({
...(!!paymentStatus && {paymentStatus})
})

await closeDB()
return res.status(200).json({
status: true,
Expand Down
1 change: 1 addition & 0 deletions src/pages/trainings/special-class/specialClass.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getTotalLeft } from "@views/api";
const Form = () => {
const { query = {}, asPath } = useRouter();
const [track, typeOfTrack] = getTrack(asPath);

const [regStatus, setRegStatus] = useState({
left: null,
isCompleted: false,
Expand Down
44 changes: 44 additions & 0 deletions src/views/hooks/useCountry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useEffect, useState } from "react"


const initState = {
currency:{
code:""
}
}
const useCountry = ()=>{
const [country, setCountry] = useState(initState)

useEffect(()=>{

async function getCountry(){
try {

const {data={} } = await fetch("/api/country").then(info=>info.json())

const temp= {
...data,
currency:{
...data?.currency,
code:"USD"
}
}


setCountry(data)

} catch (error) {
setCountry(initState)
}
}

getCountry()

},[])


return country


}
export default useCountry
1 change: 1 addition & 0 deletions src/views/hooks/usePayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const config = {
};

const usePayment = (cardConfig) => {

const userCardConfig = { ...config, ...cardConfig, meta:{
...config.meta,
...cardConfig.meta
Expand Down
Loading

0 comments on commit 83871f2

Please sign in to comment.