- request also hash values of the files via pai

This commit is contained in:
Arno Kaimbacher 2023-05-10 16:44:25 +02:00
parent df6f05a032
commit 466fdfbd14
4 changed files with 70 additions and 1 deletions

View File

@ -56,12 +56,20 @@ export class DatasetController {
through: { where: { role: "contributor" } },
as: "contributors",
},
"subjects",
"coverage",
"licenses",
"references",
"project",
"files",
// "files",
{
model: dbContext.File,
as: "files",
include: [
"hashvalues"
]
},
"identifier",
],
order: [

View File

@ -54,6 +54,7 @@ import sequelizeConnection from "../config/db.config";
import DocumentXmlCache from "./DocumentXmlCache";
import Collection from "./Collection";
import Reference from "./Reference";
import File from "./File";
class Dataset extends Model<InferAttributes<Dataset>, InferCreationAttributes<Dataset>> {
// id can be undefined during creation when using `autoIncrement`
@ -80,6 +81,7 @@ class Dataset extends Model<InferAttributes<Dataset>, InferCreationAttributes<Da
declare collections?: NonAttribute<Collection[]>;
declare references?: NonAttribute<Reference[]>;
declare files?: NonAttribute<File[]>;
// declare static associations: {
// };
@ -94,6 +96,7 @@ class Dataset extends Model<InferAttributes<Dataset>, InferCreationAttributes<Da
xmlCache: Association<Dataset, DocumentXmlCache>;
collections: Association<Dataset, Collection>;
references: Association<Dataset, Reference>;
files: Association<Dataset, File>;
};
public static async earliestPublicationDate(): Promise<Dataset | null> {

46
src/models/HashValue.ts Normal file
View File

@ -0,0 +1,46 @@
import { Model, DataTypes, InferAttributes, InferCreationAttributes, CreationOptional } from "sequelize";
import sequelizeConnection from "../config/db.config";
class HashValue extends Model<InferAttributes<HashValue>, InferCreationAttributes<HashValue>> {
// id can be undefined during creation when using `autoIncrement`
declare file_id: number;
declare type: string;
declare value: string;
// // createdAt can be undefined during creation
// declare created_at: CreationOptional<Date>;
// // updatedAt can be undefined during creation
// declare updated_at: CreationOptional<Date>;
}
HashValue.init(
{
file_id: {
type: DataTypes.INTEGER,
primaryKey: true,
},
type: {
type: DataTypes.STRING(50),
allowNull: false,
primaryKey: true,
},
value: {
type: DataTypes.STRING(255),
allowNull: false,
},
// created_at: DataTypes.DATE,
// updated_at: DataTypes.DATE,
},
{
// createdAt: "created_at",
// updatedAt: "updated_at",
timestamps: false,
tableName: "file_hashvalues",
sequelize: sequelizeConnection,
},
);
export default HashValue;

View File

@ -14,6 +14,7 @@ import Reference from "./Reference";
import Project from "./Project";
// import File from "./file.model.js";
import File from "./File";
import HashValue from "./HashValue";
import Identifier from "./Identifier";
import DocumentXmlCache from "./DocumentXmlCache";
import CollectionRole from "./CollectionRole";
@ -35,6 +36,7 @@ export {
Identifier,
DocumentXmlCache,
File,
HashValue,
Collection,
CollectionRole,
};
@ -230,6 +232,15 @@ export function initModels() {
as: "dataset",
});
File.hasMany(HashValue, {
as: "hashvalues",
foreignKey: "file_id",
});
HashValue.belongsTo(File, {
foreignKey: "file_id",
as: "file",
});
// collection an collectionRole relations
CollectionRole.hasMany(Collection, {
as: "collections",
@ -268,5 +279,6 @@ export function initModels() {
Subject: Subject,
License: License,
DocumentPersons: DocumentPersons,
File: File
};
}