💥 Implementing the models for each collection

pull/33/head
capitanwesler 4 years ago
parent fc2dc9ae79
commit d35db8944e

@ -3,6 +3,9 @@ import Parser from 'rss-parser';
import urls from '../utils/urls'; import urls from '../utils/urls';
import { obtainPreviewNews } from '../utils/obtainPreviews'; import { obtainPreviewNews } from '../utils/obtainPreviews';
import { requestGot } from '../utils/requestCall'; import { requestGot } from '../utils/requestCall';
import RadioStationModel, {
RadioStation,
} from '../database/models/radiostation.model';
/* /*
UtilsController - controller to parse the UtilsController - controller to parse the
@ -277,4 +280,27 @@ export default class UtilsController {
res.status(500).json({ message: 'Aruppi lost in the shell' }); res.status(500).json({ message: 'Aruppi lost in the shell' });
} }
} }
async getRadioStations(req: Request, res: Response, next: NextFunction) {
let data: RadioStation[];
try {
data = await RadioStationModel.find();
} catch (err) {
return next(err);
}
const results: any[] = data.map((item: RadioStation) => {
return {
name: item.name,
url: item.url,
};
});
if (results.length > 0) {
res.status(200).json({ stations: results });
} else {
res.status(500).json({ message: 'Aruppi lost in the shell' });
}
}
} }

@ -0,0 +1,19 @@
import { Document, model, Types, Schema } from 'mongoose';
/*
This is the model for each genre
of the directory, the genre model.
*/
export interface Genre extends Document {
name: string;
value: string;
}
// Schema for the theme
const GenreSchema: Schema = new Schema({
name: { type: String },
value: { type: String },
});
export default model<Genre>('Genre', GenreSchema);

@ -0,0 +1,19 @@
import { Document, model, Schema } from 'mongoose';
/*
This is the model for each radiostation
of the directory, the radiostation model.
*/
export interface RadioStation extends Document {
name: string;
url: string;
}
// Schema for the theme
const RadioStationSchema: Schema = new Schema({
name: { type: String },
url: { type: String },
});
export default model<RadioStation>('RadioStation', RadioStationSchema);

@ -0,0 +1,29 @@
import { Document, model, Types, Schema } from 'mongoose';
/*
This is the model for each theme
of the directory, the theme model.
*/
interface TInterface {
title: string;
video: string;
type: string;
}
export interface Theme extends Document {
id: string;
title: string;
year: string;
themes: Types.Array<TInterface>;
}
// Schema for the theme
const ThemeSchema: Schema = new Schema({
id: { type: String },
title: { type: String },
year: { type: String },
themes: [{ type: Object }],
});
export default model<Theme>('Theme', ThemeSchema);

@ -97,5 +97,6 @@ routes.get('/api/v4/news', utilsController.getNews);
routes.get('/api/v4/images/:title', utilsController.getImages); routes.get('/api/v4/images/:title', utilsController.getImages);
routes.get('/api/v4/videos/:channelId', utilsController.getVideos); routes.get('/api/v4/videos/:channelId', utilsController.getVideos);
routes.get('/api/v4/sectionedVideos/:type', utilsController.getSectionVideos); routes.get('/api/v4/sectionedVideos/:type', utilsController.getSectionVideos);
routes.get('/api/v4/radio', utilsController.getRadioStations);
export default routes; export default routes;

Loading…
Cancel
Save