- npm updates
- throw error exception if, there is no db connection
This commit is contained in:
parent
77d620bdbd
commit
df6f05a032
4 changed files with 93 additions and 67 deletions
|
@ -3,7 +3,7 @@ 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 { NextFunction, Request, Response } from "express";
|
||||
// import Logger from 'jet-logger';
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
|
||||
|
@ -22,7 +22,7 @@ export class DatasetController {
|
|||
order: ["server_date_published"],
|
||||
})
|
||||
.then((data) => {
|
||||
res.send(data);
|
||||
res.status(StatusCodes.OK).send(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({
|
||||
|
@ -32,44 +32,59 @@ export class DatasetController {
|
|||
}
|
||||
|
||||
@Get(":publish_id")
|
||||
public async findOne(req: Request, res: Response) {
|
||||
public async findOne(req: Request, res: Response, next: NextFunction) {
|
||||
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",
|
||||
// order: [['link_documents_persons.sort_order', 'ASC']],
|
||||
},
|
||||
{
|
||||
model: Person,
|
||||
through: { where: { role: "contributor" } },
|
||||
as: "contributors",
|
||||
},
|
||||
"subjects",
|
||||
"coverage",
|
||||
"licenses",
|
||||
"references",
|
||||
"project",
|
||||
"files",
|
||||
"identifier",
|
||||
],
|
||||
order: [
|
||||
["authors", dbContext.DocumentPersons, "sort_order", "ASC"],
|
||||
["contributors", dbContext.DocumentPersons, "sort_order", "ASC"],
|
||||
],
|
||||
// order: ['server_date_published'],
|
||||
// order: ['server_date_published'],
|
||||
});
|
||||
try {
|
||||
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",
|
||||
// order: [['link_documents_persons.sort_order', 'ASC']],
|
||||
},
|
||||
{
|
||||
model: Person,
|
||||
through: { where: { role: "contributor" } },
|
||||
as: "contributors",
|
||||
},
|
||||
"subjects",
|
||||
"coverage",
|
||||
"licenses",
|
||||
"references",
|
||||
"project",
|
||||
"files",
|
||||
"identifier",
|
||||
],
|
||||
order: [
|
||||
["authors", dbContext.DocumentPersons, "sort_order", "ASC"],
|
||||
["contributors", dbContext.DocumentPersons, "sort_order", "ASC"],
|
||||
],
|
||||
// order: ['server_date_published'],
|
||||
// order: ['server_date_published'],
|
||||
});
|
||||
if (dataset) {
|
||||
res.status(StatusCodes.OK).send(dataset);
|
||||
} else {
|
||||
res.status(StatusCodes.NOT_FOUND).send({
|
||||
message: `Cannot find Dataset with publish_id=${publish_id}.`,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
// res.status(500).send({
|
||||
// message: "Error retrieving Dataset with publish_id=" + publish_id,
|
||||
// });
|
||||
return next(error);
|
||||
}
|
||||
|
||||
// .then((data) => {
|
||||
// if (data) {
|
||||
// res.send(data);
|
||||
|
@ -84,13 +99,13 @@ export class DatasetController {
|
|||
// 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}.`,
|
||||
});
|
||||
}
|
||||
// if (dataset) {
|
||||
// res.status(StatusCodes.OK).send(dataset);
|
||||
// } else {
|
||||
// res.status(StatusCodes.NOT_FOUND).send({
|
||||
// message: `Cannot find Dataset with publish_id=${publish_id}.`,
|
||||
// });
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue