-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
got build and queries working again! (#181)
- Loading branch information
Showing
8 changed files
with
94 additions
and
93 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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { initializeApp, applicationDefault, cert } from 'firebase-admin/app' | ||
import serviceAccountCredentials | ||
import { initializeApp, applicationDefault, cert, ServiceAccount } from 'firebase-admin/app' | ||
import serviceAccountCredentialsJson | ||
from '../findadoc-firebase-service-account-credentials.json' | ||
import { getFirestore, Timestamp, FieldValue } from 'firebase-admin/firestore' | ||
|
||
export async function initializeDb() { | ||
const credentials = serviceAccountCredentialsJson as ServiceAccount | ||
|
||
initializeApp({ | ||
credential: cert(serviceAccountCredentials) | ||
credential: cert(credentials) | ||
}) | ||
} |
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
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 |
---|---|---|
@@ -1,60 +1,52 @@ | ||
// import { HealthcareProfessional, LocaleName, Degree, | ||
// Specialty, SpecialtyName, SpokenLanguage, Insurance, Facility } from '../typeDefs/dbSchema' | ||
import { getFirestore } from 'firebase-admin/firestore' | ||
import { getHealthcareProfessionalsByIds } from './healthcareProfessionalService' | ||
import { HealthcareProfessional, LocaleName, Degree, | ||
Specialty, SpecialtyName, SpokenLanguage, Insurance, Facility } from '../typeDefs/dbSchema' | ||
import { DocumentData, WhereFilterOp, getFirestore } from 'firebase-admin/firestore' | ||
import { searchHealthcareProfessionals } from './healthcareProfessionalService' | ||
|
||
export const getFacilityById = async (id: string) => { | ||
export const getFacilityById = async (id: string) : Promise<Facility | null> => { | ||
const db = getFirestore() | ||
const facilityRef = db.collection('facilities') | ||
const snapshot = await facilityRef.where('id', '=', id).get() | ||
const facilities = [] | ||
const whereCondition = '=' as WhereFilterOp | ||
const snapshot = await facilityRef.where('id', whereCondition, id).get() | ||
|
||
snapshot.forEach(doc => { | ||
facilities.push(doc.data()) | ||
}) | ||
|
||
for await (const facility of facilities) { | ||
await hydrateFacility(facility) | ||
if (snapshot.docs.length < 1) { | ||
return null | ||
} | ||
|
||
return facilities | ||
} | ||
const convertedEntity = mapDbEntityTogqlEntity(snapshot.docs[0].data()) | ||
|
||
export async function addFacility(facilityRef, facility) { | ||
facilityRef.add(transformFacilityForFirestore(facility)) | ||
return convertedEntity | ||
} | ||
|
||
function transformFacilityForFirestore(facility) { | ||
const healthcareProfessionalIds = facility.healthcareProfessionals.map(hp => hp.id) | ||
|
||
facility.healthcareProfessionals = healthcareProfessionalIds | ||
|
||
return facility | ||
export const addFacility = async (facility : Facility) : Promise<void> => { | ||
//todo | ||
} | ||
|
||
export const getFacilities = async () => { | ||
export const searchFacilities = async (userSearchQuery : string[]) : Promise<Facility[]> => { | ||
const db = getFirestore() | ||
const facilitiesRef = db.collection('facilities') | ||
const hpRef = db.collection('healthcareProfessionals') | ||
// make this a real query | ||
const snapshot = await hpRef.where('id', 'in', userSearchQuery).get() | ||
|
||
const snapshot = await facilitiesRef.get() | ||
const facilities = [] | ||
const facilities = [] as Facility[] | ||
|
||
snapshot.forEach(doc => { | ||
facilities.push(doc.data()) | ||
}) | ||
const convertedEntity = mapDbEntityTogqlEntity(doc.data()) | ||
|
||
for await (const facility of facilities) { | ||
await hydrateFacility(facility) | ||
} | ||
facilities.push(convertedEntity) | ||
}) | ||
|
||
return facilities | ||
} | ||
|
||
async function hydrateFacility(facility) { | ||
const db = getFirestore() | ||
const healthcareProfessionals = await getHealthcareProfessionalsByIds(facility.healthcareProfessionals) | ||
|
||
facility.healthcareProfessionals = healthcareProfessionals | ||
|
||
return facility | ||
const mapDbEntityTogqlEntity = (dbEntity : DocumentData) : Facility => { | ||
const gqlEntity = { | ||
id: dbEntity.id, | ||
nameEn: dbEntity.nameEn, | ||
nameJa: dbEntity.nameJa, | ||
contact: dbEntity.contact, | ||
healthcareProfessionals: dbEntity.healthcareProfessionals | ||
} satisfies Facility | ||
|
||
return gqlEntity | ||
} |
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 |
---|---|---|
@@ -1,47 +1,53 @@ | ||
// import { HealthcareProfessional, LocaleName, Degree, | ||
// Specialty, SpecialtyName, SpokenLanguage, Insurance } from '../typeDefs/dbSchema' | ||
import { getFirestore } from 'firebase-admin/firestore' | ||
import { HealthcareProfessional, LocaleName, Degree, | ||
Specialty, SpecialtyName, SpokenLanguage, Insurance } from '../typeDefs/dbSchema' | ||
import { DocumentData, WhereFilterOp, getFirestore } from 'firebase-admin/firestore' | ||
|
||
export const getHealthcareProfessionalById = async (id: string) => { | ||
export const getHealthcareProfessionalById = async (id: string) : Promise<HealthcareProfessional | null> => { | ||
const db = getFirestore() | ||
const hpRef = db.collection('healthcareProfessionals') | ||
const snapshot = await hpRef.where('id', '=', id).get() | ||
const healthcareProfessionals = [] | ||
const whereCondition = '=' as WhereFilterOp | ||
const snapshot = await hpRef.where('id', whereCondition, id).get() | ||
|
||
snapshot.forEach(doc => { | ||
healthcareProfessionals.push(doc.data()) | ||
}) | ||
if (snapshot.docs.length < 1) { | ||
return null | ||
} | ||
|
||
return healthcareProfessionals | ||
const convertedEntity = mapDbEntityTogqlEntity(snapshot.docs[0].data()) | ||
|
||
return convertedEntity | ||
} | ||
|
||
export const addHealthcareProfessional = async (healthcareProfessionalsRef, healthcareProfessional) => { | ||
healthcareProfessionalsRef.add(healthcareProfessional) | ||
export const addHealthcareProfessional = async (healthcareProfessional : HealthcareProfessional) : Promise<void> => { | ||
|
||
//todo | ||
} | ||
|
||
export const getHealthcareProfessionals = async () => { | ||
export const searchHealthcareProfessionals = async (userSearchQuery : string[]) | ||
: Promise<HealthcareProfessional[]> => { | ||
const db = getFirestore() | ||
const hpRef = db.collection('healthcareProfessionals') | ||
const snapshot = await hpRef.where('id', 'in', userSearchQuery).get() | ||
|
||
const snapshot = await hpRef.get() | ||
const healthcareProfessionals = [] | ||
const healthcareProfessionals = [] as HealthcareProfessional[] | ||
|
||
snapshot.forEach(doc => { | ||
healthcareProfessionals.push(doc.data()) | ||
const convertedEntity = mapDbEntityTogqlEntity(doc.data()) | ||
|
||
healthcareProfessionals.push(convertedEntity) | ||
}) | ||
|
||
return healthcareProfessionals | ||
} | ||
|
||
export const getHealthcareProfessionalsByIds = async (ids : string[]) => { | ||
const db = getFirestore() | ||
const hpRef = db.collection('healthcareProfessionals') | ||
const snapshot = await hpRef.where('id', 'in', ids).get() | ||
const healthcareProfessionals = [] | ||
|
||
snapshot.forEach(doc => { | ||
healthcareProfessionals.push(doc.data()) | ||
}) | ||
|
||
return healthcareProfessionals | ||
const mapDbEntityTogqlEntity = (dbEntity : DocumentData) : HealthcareProfessional => { | ||
const gqlEntity = { | ||
id: dbEntity.id, | ||
names: dbEntity.names, | ||
degrees: dbEntity.degrees, | ||
spokenLanguages: dbEntity.spokenLanguages, | ||
specialties: dbEntity.specialties, | ||
acceptedInsurance: dbEntity.acceptedInsurance | ||
} satisfies HealthcareProfessional | ||
return gqlEntity | ||
} |
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