This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
forked from themaxsandelin/skolverket-api
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added final data set, subject-area, to 'gymsar' level, completing it'…
…s implementation! 🎉
- Loading branch information
1 parent
80742c9
commit faf9cab
Showing
6 changed files
with
102 additions
and
18 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Route manager for: /gymsar/subject-areas | ||
// Data folder: gys | ||
|
||
// Dependencies | ||
const router = require('express').Router() | ||
const path = require('path') | ||
const fs = require('fs') | ||
const { parseString } = require('xml2js') | ||
const async = require('async') | ||
|
||
// Helpers | ||
const formatter = require('../../helpers/gymsar/formatter') | ||
const latinize = require('../../helpers/latinize') | ||
|
||
const rootPath = path.resolve(__dirname + '/../../../files/gys') | ||
|
||
router.get('/', (req, res) => { | ||
const folder = rootPath + '/subjectArea' | ||
const files = fs.readdirSync(folder) | ||
|
||
let areas = [] | ||
async.each(files, (file, callback) => { | ||
parseString(fs.readFileSync(folder + '/' + file), (err, result) => { | ||
areas.push({ | ||
name: result.subject.name[0], | ||
code: result.subject.code[0] | ||
}) | ||
|
||
callback() | ||
}) | ||
}, (error) => { | ||
res.json(areas) | ||
}) | ||
}) | ||
|
||
router.get('/:code', (req, res) => { | ||
const code = req.params.code.toLowerCase() | ||
const folder = rootPath + '/subjectArea' | ||
const files = fs.readdirSync(folder) | ||
|
||
let area | ||
async.each(files, (file, callback) => { | ||
parseString(fs.readFileSync(folder + '/' + file), (err, result) => { | ||
if (result.subject.code[0].toLowerCase() === code) { | ||
const data = result.subject | ||
area = formatter.formatSubjectData(result.subject) | ||
} | ||
|
||
callback() | ||
}) | ||
}, (error) => { | ||
if (area) { | ||
res.json(area) | ||
} else { | ||
res.status(404).send('Not found') | ||
} | ||
}) | ||
}) | ||
|
||
module.exports = router |
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
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