- first commit
This commit is contained in:
commit
407717d4b5
57 changed files with 5510 additions and 0 deletions
160
src/controllers/dataset.controller.ts
Normal file
160
src/controllers/dataset.controller.ts
Normal file
|
@ -0,0 +1,160 @@
|
|||
import { Controller, Get } from "@overnightjs/core";
|
||||
import dbContext from "../models/init-models.js";
|
||||
import { Dataset, User, Person } from "../models/init-models.js";
|
||||
import Sequelize from "sequelize";
|
||||
const Op = Sequelize.Op;
|
||||
import { Request, Response } from "express";
|
||||
// import Logger from 'jet-logger';
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
|
||||
@Controller("api/dataset")
|
||||
export class DatasetController {
|
||||
@Get("")
|
||||
public async findAll(req: Request, res: Response) {
|
||||
// const type = req.query.type;
|
||||
// var condition = type ? { type: { [Op.iLike]: `%${type}%` } } : null;,
|
||||
const server_state = "published";
|
||||
const condition = { server_state: { [Op.eq]: `${server_state}` } };
|
||||
|
||||
Dataset.findAll({
|
||||
where: condition,
|
||||
include: ["abstracts"],
|
||||
order: ["server_date_published"],
|
||||
})
|
||||
.then((data) => {
|
||||
res.send(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({
|
||||
message: err.message || "Some error occurred while retrieving datasets.",
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Get(":publish_id")
|
||||
public async findOne(req: Request, res: Response) {
|
||||
const publish_id = req.params.publish_id;
|
||||
|
||||
const dataset = await dbContext.Dataset.findOne({
|
||||
where: { publish_id: publish_id },
|
||||
include: [
|
||||
"titles",
|
||||
"abstracts",
|
||||
{
|
||||
model: User,
|
||||
as: "user",
|
||||
},
|
||||
{
|
||||
model: Person,
|
||||
through: { where: { role: "author" } },
|
||||
as: "authors",
|
||||
},
|
||||
{
|
||||
model: Person,
|
||||
through: { where: { role: "contributor" } },
|
||||
as: "contributors",
|
||||
},
|
||||
"subjects",
|
||||
"coverage",
|
||||
"licenses",
|
||||
"project",
|
||||
"files",
|
||||
"identifier",
|
||||
],
|
||||
// order: ['server_date_published'],
|
||||
});
|
||||
// .then((data) => {
|
||||
// if (data) {
|
||||
// res.send(data);
|
||||
// } else {
|
||||
// res.status(404).send({
|
||||
// message: `Cannot find Dataset with publish_id=${publish_id}.`,
|
||||
// });
|
||||
// }
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// res.status(500).send({
|
||||
// message: "Error retrieving Dataset with publish_id=" + publish_id,
|
||||
// });
|
||||
// });
|
||||
if (dataset) {
|
||||
res.status(StatusCodes.OK).send(dataset);
|
||||
} else {
|
||||
res.status(StatusCodes.NOT_FOUND).send({
|
||||
message: `Cannot find Dataset with publish_id=${publish_id}.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve all Tutorials from the database.
|
||||
// export async function findAll(req: Request, res: Response) {
|
||||
// // const type = req.query.type;
|
||||
// // var condition = type ? { type: { [Op.iLike]: `%${type}%` } } : null;,
|
||||
// const server_state = "published";
|
||||
// var condition = { server_state: { [Op.eq]: `${server_state}` } };
|
||||
|
||||
// Dataset.findAll({
|
||||
// where: condition,
|
||||
// include: [
|
||||
// "abstracts"
|
||||
// ],
|
||||
// order: ['server_date_published'],
|
||||
// })
|
||||
// .then((data) => {
|
||||
// res.send(data);
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// res.status(500).send({
|
||||
// message:
|
||||
// err.message || "Some error occurred while retrieving datasets.",
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
// export async function findOne(req: Request, res: Response) {
|
||||
// const publish_id = req.params.publish_id;
|
||||
|
||||
// dbContext.Dataset.findOne({
|
||||
// where: { publish_id: publish_id },
|
||||
// include: [
|
||||
// "titles",
|
||||
// "abstracts",
|
||||
// {
|
||||
// model: User,
|
||||
// as: "user",
|
||||
// },
|
||||
// {
|
||||
// model: Person,
|
||||
// through: { where: { role: "author" } },
|
||||
// as: "authors",
|
||||
// },
|
||||
// {
|
||||
// model: Person,
|
||||
// through: { where: { role: "contributor" } },
|
||||
// as: "contributors",
|
||||
// },
|
||||
// "subjects",
|
||||
// "coverage",
|
||||
// "licenses",
|
||||
// "project",
|
||||
// "files",
|
||||
// "identifier"
|
||||
// ],
|
||||
// // order: ['server_date_published'],
|
||||
// })
|
||||
// .then((data) => {
|
||||
// if (data) {
|
||||
// res.send(data);
|
||||
// } else {
|
||||
// res.status(404).send({
|
||||
// message: `Cannot find Dataset with publish_id=${publish_id}.`,
|
||||
// });
|
||||
// }
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// res.status(500).send({
|
||||
// message: "Error retrieving Dataset with publish_id=" + publish_id,
|
||||
// });
|
||||
// });
|
||||
// }
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue