Skip to content
This repository has been archived by the owner on Jan 17, 2025. It is now read-only.

Commit

Permalink
added county to document
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgtho committed Dec 21, 2023
1 parent 2a133cb commit 272bf66
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Documents/build-document-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { encryptContent } = require('@vtfk/encryption')
const { ObjectId } = require('mongodb')
const { dataModificationsAdd } = require('../lib/crud')
const repackDocumentSchool = require('../lib/repack-document-school')
const repackDocumentCounty = require('../lib/repack-document-county')
const repackDocumentStudent = require('../lib/repack-document-student')
const repackDocumentTeacher = require('../lib/repack-document-teacher')
const config = require('../config')
Expand Down Expand Up @@ -42,6 +43,7 @@ module.exports.getNewDocumentQuery = ({ user, body, student, teacher }) => {
query.student = repackDocumentStudent(student)
query.teacher = repackDocumentTeacher(teacher)
query.school = repackDocumentSchool(student)
query.county = repackDocumentCounty(student)
query.isEncrypted = body.isEncrypted || false

// TODO: Append additional content data for YFF
Expand Down
33 changes: 33 additions & 0 deletions lib/repack-document-county.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const HTTPError = require('./http-error')
const repackStudent = require('./repack-student')
const getSchools = require('vtfk-schools-info')

module.exports = (student) => {
const repacked = student.username ? student : repackStudent(student, true, true)
const { schoolId: id } = repacked
{
// First try to find school with schoolId
const schools = getSchools({ schoolId: id })
if (schools.length === 1) {
const { county, countyNumber } = schools[0]
if (!(county && countyNumber)) throw new HTTPError(500, `Could not find county and countyNumber for school with schoolId equal to ${id} `)
return {
county,
countyNumber
}
}
}
{
// If not found we try with schoolNumber
const schools = getSchools({ schoolNumber: id })
if (schools.length === 1) {
const { county, countyNumber } = schools[0]
if (!(county && countyNumber)) throw new HTTPError(500, `Could not find county and countyNumber for school with schoolId equal to ${id} `)
return {
county,
countyNumber
}
}
}
throw new HTTPError(500, `Could not find any unique school in vtfk-schools-info with schoolId or schoolNumber equal to ${id} `)
}

0 comments on commit 272bf66

Please # to comment.