2023-03-03 15:54:28 +00:00
|
|
|
import {
|
2023-06-22 15:20:04 +00:00
|
|
|
column,
|
|
|
|
BaseModel,
|
|
|
|
SnakeCaseNamingStrategy,
|
|
|
|
manyToMany,
|
|
|
|
ManyToMany,
|
|
|
|
belongsTo,
|
|
|
|
BelongsTo,
|
|
|
|
hasMany,
|
|
|
|
HasMany,
|
2023-06-27 16:23:18 +00:00
|
|
|
computed,
|
2023-07-28 15:08:20 +00:00
|
|
|
hasOne,
|
|
|
|
HasOne,
|
2023-03-03 15:54:28 +00:00
|
|
|
} from '@ioc:Adonis/Lucid/Orm';
|
|
|
|
import { DateTime } from 'luxon';
|
2023-06-27 16:23:18 +00:00
|
|
|
import dayjs from 'dayjs';
|
2023-03-03 15:54:28 +00:00
|
|
|
import Person from './Person';
|
2023-06-22 15:20:04 +00:00
|
|
|
import User from './User';
|
|
|
|
import Title from './Title';
|
|
|
|
import Description from './Description';
|
|
|
|
import License from './License';
|
|
|
|
import Subject from './Subject';
|
2023-06-27 16:23:18 +00:00
|
|
|
import File from './File';
|
2023-07-28 15:08:20 +00:00
|
|
|
import Coverage from './Coverage';
|
2023-09-04 11:24:58 +00:00
|
|
|
import DatasetReference from './DatasetReference';
|
2023-08-23 15:07:26 +00:00
|
|
|
import Collection from './Collection';
|
|
|
|
import DatasetIdentifier from './DatasetIdentifier';
|
2023-09-04 11:24:58 +00:00
|
|
|
import Project from './Project';
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
export default class Dataset extends BaseModel {
|
2023-06-22 15:20:04 +00:00
|
|
|
public static namingStrategy = new SnakeCaseNamingStrategy();
|
|
|
|
public static primaryKey = 'id';
|
|
|
|
public static table = 'documents';
|
|
|
|
public static selfAssignPrimaryKey = false;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column({ isPrimary: true })
|
|
|
|
public id: number;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
@column({})
|
2023-07-17 17:13:30 +00:00
|
|
|
public server_state: string;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
@column({})
|
2023-06-22 15:20:04 +00:00
|
|
|
public publisherName: string;
|
|
|
|
|
|
|
|
@column({ columnName: 'creating_corporation' })
|
|
|
|
public creatingCorporation: string;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
@column.dateTime({ columnName: 'embargo_date' })
|
2023-06-22 15:20:04 +00:00
|
|
|
public embargoDate: DateTime;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
@column({})
|
2023-06-22 15:20:04 +00:00
|
|
|
public type: string;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column({})
|
|
|
|
public language: string;
|
|
|
|
|
2023-09-04 11:24:58 +00:00
|
|
|
@column({})
|
|
|
|
public publish_id: number | null = null;
|
|
|
|
|
|
|
|
@column({})
|
|
|
|
public project_id: number | null = null;
|
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column({})
|
|
|
|
public account_id: number | null = null;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-27 16:23:18 +00:00
|
|
|
@column({})
|
|
|
|
public editor_id: number | null = null;
|
|
|
|
|
|
|
|
@column({})
|
|
|
|
public reviewer_id: number | null = null;
|
|
|
|
|
|
|
|
@column({})
|
2023-07-17 17:13:30 +00:00
|
|
|
public reject_editor_note: string | null;
|
2023-06-27 16:23:18 +00:00
|
|
|
|
2023-07-28 15:08:20 +00:00
|
|
|
@column({})
|
|
|
|
public preferred_reviewer: string | null;
|
|
|
|
|
|
|
|
@column({})
|
|
|
|
public preferred_reviewer_email: string | null;
|
|
|
|
|
2023-06-27 16:23:18 +00:00
|
|
|
@column({})
|
2023-07-17 17:13:30 +00:00
|
|
|
public reject_reviewer_note: string | null;
|
2023-06-27 16:23:18 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column.dateTime({ columnName: 'server_date_published' })
|
|
|
|
public serverDatePublished: DateTime;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-27 16:23:18 +00:00
|
|
|
// @column.dateTime({ autoCreate: true, columnName: 'created_at' })
|
|
|
|
@column.dateTime({
|
|
|
|
serialize: (value: Date | null) => {
|
|
|
|
return value ? dayjs(value).format('MMMM D YYYY HH:mm a') : value;
|
|
|
|
},
|
|
|
|
autoCreate: true,
|
|
|
|
columnName: 'created_at',
|
|
|
|
})
|
2023-06-22 15:20:04 +00:00
|
|
|
public createdAt: DateTime;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true, columnName: 'server_date_modified' })
|
|
|
|
public updatedAt: DateTime;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
@manyToMany(() => Person, {
|
2023-06-22 15:20:04 +00:00
|
|
|
pivotForeignKey: 'document_id',
|
|
|
|
pivotRelatedForeignKey: 'person_id',
|
|
|
|
pivotTable: 'link_documents_persons',
|
|
|
|
pivotColumns: ['role', 'sort_order', 'allow_email_contact'],
|
|
|
|
})
|
|
|
|
public persons: ManyToMany<typeof Person>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the account that the dataset belongs to
|
|
|
|
*/
|
|
|
|
@belongsTo(() => User, {
|
|
|
|
foreignKey: 'account_id',
|
|
|
|
})
|
|
|
|
public user: BelongsTo<typeof User>;
|
|
|
|
|
2023-09-04 11:24:58 +00:00
|
|
|
@belongsTo(() => Project, {
|
|
|
|
foreignKey: 'project_id',
|
|
|
|
})
|
|
|
|
public project: BelongsTo<typeof Project>;
|
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@hasMany(() => Title, {
|
|
|
|
foreignKey: 'document_id',
|
|
|
|
})
|
|
|
|
public titles: HasMany<typeof Title>;
|
|
|
|
|
|
|
|
@hasMany(() => Description, {
|
|
|
|
foreignKey: 'document_id',
|
|
|
|
})
|
|
|
|
public descriptions: HasMany<typeof Description>;
|
|
|
|
|
|
|
|
@manyToMany(() => License, {
|
|
|
|
pivotForeignKey: 'document_id',
|
|
|
|
pivotRelatedForeignKey: 'licence_id',
|
|
|
|
pivotTable: 'link_documents_licences',
|
|
|
|
})
|
|
|
|
public licenses: ManyToMany<typeof License>;
|
|
|
|
|
|
|
|
@manyToMany(() => Subject, {
|
|
|
|
pivotForeignKey: 'document_id',
|
|
|
|
pivotRelatedForeignKey: 'subject_id',
|
|
|
|
pivotTable: 'link_dataset_subjects',
|
|
|
|
})
|
|
|
|
public subjects: ManyToMany<typeof Subject>;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-27 16:23:18 +00:00
|
|
|
@hasMany(() => File, {
|
|
|
|
foreignKey: 'document_id',
|
|
|
|
})
|
|
|
|
public files: HasMany<typeof File>;
|
|
|
|
|
2023-07-28 15:08:20 +00:00
|
|
|
@hasOne(() => Coverage, {
|
|
|
|
foreignKey: 'dataset_id',
|
|
|
|
})
|
|
|
|
public coverage: HasOne<typeof Coverage>;
|
|
|
|
|
2023-08-01 15:06:51 +00:00
|
|
|
@hasMany(() => DatasetReference, {
|
|
|
|
foreignKey: 'document_id',
|
|
|
|
})
|
|
|
|
public references: HasMany<typeof DatasetReference>;
|
|
|
|
|
2023-09-04 11:24:58 +00:00
|
|
|
// Dataset.hasMany(Reference, {
|
|
|
|
// foreignKey: "related_document_id",
|
|
|
|
// as: "referenced_by",
|
|
|
|
// });
|
|
|
|
@hasMany(() => DatasetReference, {
|
|
|
|
foreignKey: 'related_document_id',
|
|
|
|
})
|
|
|
|
public referenced_by: HasMany<typeof DatasetReference>;
|
|
|
|
|
2023-08-23 15:07:26 +00:00
|
|
|
@manyToMany(() => Collection, {
|
|
|
|
pivotForeignKey: 'document_id',
|
|
|
|
pivotRelatedForeignKey: 'collection_id',
|
|
|
|
pivotTable: 'link_documents_collections',
|
|
|
|
})
|
|
|
|
public collections: ManyToMany<typeof Collection>;
|
|
|
|
|
|
|
|
@hasOne(() => DatasetIdentifier, {
|
2023-09-04 11:24:58 +00:00
|
|
|
foreignKey: 'dataset_id',
|
2023-08-23 15:07:26 +00:00
|
|
|
})
|
|
|
|
public identifier: HasOne<typeof DatasetIdentifier>;
|
|
|
|
|
2023-06-27 16:23:18 +00:00
|
|
|
@computed({
|
|
|
|
serializeAs: 'main_title',
|
|
|
|
})
|
|
|
|
public get mainTitle() {
|
|
|
|
// return `${this.firstName} ${this.lastName}`;
|
|
|
|
const mainTitle = this.titles?.find((title) => title.type === 'Main');
|
|
|
|
return mainTitle ? mainTitle.value : null;
|
|
|
|
}
|
2023-09-04 11:24:58 +00:00
|
|
|
|
|
|
|
@manyToMany(() => Person, {
|
|
|
|
pivotForeignKey: 'document_id',
|
|
|
|
pivotRelatedForeignKey: 'person_id',
|
|
|
|
pivotTable: 'link_documents_persons',
|
|
|
|
pivotColumns: ['role', 'sort_order', 'allow_email_contact'],
|
|
|
|
onQuery(query) {
|
|
|
|
query.wherePivot('role', 'author');
|
|
|
|
},
|
|
|
|
})
|
|
|
|
public authors: ManyToMany<typeof Person>;
|
|
|
|
|
|
|
|
@manyToMany(() => Person, {
|
|
|
|
pivotForeignKey: 'document_id',
|
|
|
|
pivotRelatedForeignKey: 'person_id',
|
|
|
|
pivotTable: 'link_documents_persons',
|
|
|
|
pivotColumns: ['role', 'sort_order', 'allow_email_contact'],
|
|
|
|
onQuery(query) {
|
|
|
|
query.wherePivot('role', 'contributor');
|
|
|
|
},
|
|
|
|
})
|
|
|
|
public contributors: ManyToMany<typeof Person>;
|
2023-03-03 15:54:28 +00:00
|
|
|
}
|