-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(agora): migrating mongoose api and openapi yaml files (AG-1552) (#…
- Loading branch information
Showing
109 changed files
with
5,619 additions
and
233 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// -------------------------------------------------------------------------- // | ||
// Internal | ||
// -------------------------------------------------------------------------- // | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { cache, setHeaders } from '../helpers'; | ||
import { AllBioDomainsCollection, BioDomainsCollection } from '../models'; | ||
import { BioDomains, BioDomainInfo } from '@sagebionetworks/agora/api-client-angular'; | ||
|
||
// -------------------------------------------------------------------------- // | ||
// Functions | ||
// -------------------------------------------------------------------------- // | ||
export async function getAllBioDomains() { | ||
const cacheKey = 'all-biodomains'; | ||
let result: BioDomainInfo[] | null | undefined = cache.get(cacheKey); | ||
|
||
if (result) { | ||
return result; | ||
} | ||
|
||
result = await AllBioDomainsCollection.find().lean().sort().exec(); | ||
|
||
cache.set(cacheKey, result); | ||
return result || undefined; | ||
} | ||
|
||
export async function getAllGeneBioDomains() { | ||
const cacheKey = 'all-genebiodomains'; | ||
let result: BioDomains[] | null | undefined = cache.get(cacheKey); | ||
|
||
if (result) { | ||
return result; | ||
} | ||
|
||
result = await BioDomainsCollection.find().lean().sort().exec(); | ||
|
||
cache.set(cacheKey, result); | ||
return result || undefined; | ||
} | ||
|
||
export async function getBioDomains(ensg: string) { | ||
const cacheKey = ensg + '-biodomains'; | ||
let result: BioDomains | null | undefined = cache.get(cacheKey); | ||
|
||
if (result) { | ||
return result; | ||
} | ||
|
||
result = await BioDomainsCollection.findOne({ | ||
ensembl_gene_id: ensg, | ||
}) | ||
.lean() | ||
.exec(); | ||
|
||
cache.set(cacheKey, result); | ||
return result || undefined; | ||
} | ||
|
||
// -------------------------------------------------------------------------- // | ||
// Routes | ||
// -------------------------------------------------------------------------- // | ||
export async function allBiodomainsRoute(req: Request, res: Response, next: NextFunction) { | ||
try { | ||
const result = await getAllBioDomains(); | ||
setHeaders(res); | ||
res.json(result); | ||
} catch (err) { | ||
next(err); | ||
} | ||
} | ||
|
||
export async function biodomainsRoute(req: Request, res: Response, next: NextFunction) { | ||
if (!req.params || !req.params.id) { | ||
res.status(404).send('Not found'); | ||
return; | ||
} | ||
|
||
try { | ||
const result = await getBioDomains(<string>req.params.id); | ||
setHeaders(res); | ||
res.json(result?.gene_biodomains); | ||
} catch (err) { | ||
next(err); | ||
} | ||
} |
Oops, something went wrong.