Skip to content
Snippets Groups Projects
Commit dbc5e7de authored by henry anand's avatar henry anand
Browse files

feat : add student controller to fetch into SOAP

parent 93ce1166
No related merge requests found
import { Request, Response } from "express"
import axios from 'axios'
import { getStudentOfScholarship } from "../templates/student";
const xml2js = require("xml2js")
const soapRequest = require("easy-soap-request")
const util = require("util")
export const getUserPhpInfo = async (req : Request, res : Response) => {
try {
......@@ -24,4 +29,42 @@ export const getUserPhpInfo = async (req : Request, res : Response) => {
message: "Internal server error",
});
}
};
\ No newline at end of file
};
export const getStudentFromScholarship = async (req: Request, res: Response) => {
try {
const sid = req.params.sid
console.log("SID", sid)
const { response } = await soapRequest({
url: getStudentOfScholarship.url,
headers: getStudentOfScholarship.headers,
xml: util.format(
getStudentOfScholarship.body,
sid
)
})
const { body } = response
console.log("body",body)
const parser = new xml2js.Parser()
const parsedBody = await parser.parseStringPromise(body)
const scholarships =
parsedBody["S:Envelope"]["S:Body"][0]["ns2:getStudentOfScholarshipResponse"][0][
"return"
]
res.status(200).json({
status: "success",
message: "User retrieved successfully",
data: {
scholarships
},
});
} catch(error : any) {
console.error(error);
res.status(500).json({
status: "error",
message: "Internal server error",
});
}
}
\ No newline at end of file
import express from "express"
import {
getUserPhpInfo,
getStudentFromScholarship
} from "../controllers/student.controller"
const router = express.Router()
router.get("/user/:uid", getUserPhpInfo)
router.get("/scholarship/user/:sid", getStudentFromScholarship)
module.exports = router
\ No newline at end of file
const headers = {
"Content-Type": "text/xml;charset=UTF-8",
"X-API-KEY": process.env.SOAP_API_KEY
}
const getStudentOfScholarshipURL = process.env.SOAP_URL + "/ws/ScholarshipAcceptance?wsdl"
const getStudentOfScholarshipTemplate = `
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<getStudentOfScholarship xmlns="http://services.soap.orden.com/">
<scholarship_id_rest xmlns="">%d</scholarship_id_rest>
</getStudentOfScholarship>
</Body>
</Envelope>
`
export const getStudentOfScholarship = {
url : getStudentOfScholarshipURL,
headers : headers,
body: getStudentOfScholarshipTemplate
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment