Skip to content

Commit

Permalink
feat(agora): migrating mongoose api and openapi yaml files (AG-1552) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sagely1 authored Oct 8, 2024
1 parent 01371bb commit f930ca4
Show file tree
Hide file tree
Showing 109 changed files with 5,619 additions and 233 deletions.
23 changes: 21 additions & 2 deletions apps/agora/api/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import express from 'express';
import mongoose from 'mongoose';
import { dataVersionRoute } from './components/dataversion';
import { teamMemberImageRoute, teamsRoute } from './components/teams';
import {
allBiodomainsRoute,
biodomainsRoute,
comparisonGenesRoute,
dataVersionRoute,
distributionRoute,
geneRoute,
genesRoute,
nominatedGenesRoute,
searchGeneRoute,
teamMemberImageRoute,
teamsRoute,
} from './components';

const mongoUri = process.env.MONGODB_URI;

Expand All @@ -19,7 +30,15 @@ mongoose.connection.on('error', console.error.bind(console, 'MongoDB connection

const router = express.Router();
mongoose.connection.once('open', async () => {
router.get('/biodomains', allBiodomainsRoute);
router.get('/biodomains/:id', biodomainsRoute);
router.get('/dataversion', dataVersionRoute);
router.get('/distribution', distributionRoute);
router.get('/genes/search', searchGeneRoute);
router.get('/genes/comparison', comparisonGenesRoute);
router.get('/genes/nominated', nominatedGenesRoute);
router.get('/genes/:id', geneRoute);
router.get('/genes', genesRoute);
router.get('/teams', teamsRoute);
router.get('/teamMembers/:name/image', teamMemberImageRoute);
});
Expand Down
84 changes: 84 additions & 0 deletions apps/agora/api/src/components/biodomains.ts
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);
}
}
Loading

0 comments on commit f930ca4

Please sign in to comment.