- also query dataset by :prefix/:value

This commit is contained in:
Arno Kaimbacher 2023-07-05 17:21:56 +02:00
parent 5f766110e6
commit 221dff8208

View File

@ -56,7 +56,7 @@ export class DatasetController {
through: { where: { role: "contributor" } },
as: "contributors",
},
"subjects",
"coverage",
"licenses",
@ -64,11 +64,9 @@ export class DatasetController {
"project",
// "files",
{
model: dbContext.File,
model: dbContext.File,
as: "files",
include: [
"hashvalues"
]
include: ["hashvalues"],
},
"identifier",
],
@ -115,6 +113,94 @@ export class DatasetController {
// });
// }
}
@Get(":prefix/:value") // 10.24341/tethys.99.2
public async findByIdentifier(req: Request, res: Response, next: NextFunction) {
const value = req.params.prefix + "/" + req.params.value;
try {
const dataset = await dbContext.Dataset.findOne({
where: {
// id: Sequelize.literal(`(SELECT dataset_id FROM gba.dataset_identifiers WHERE value = '${value}')`),
id: {
[Sequelize.Op.in]: Sequelize.literal(`(SELECT dataset_id FROM gba.dataset_identifiers WHERE value = '${value}')`),
},
},
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",
{
model: dbContext.File,
as: "files",
include: ["hashvalues"],
},
"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 doi_value=${value}.`,
});
}
} 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);
// } 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.