tethys.backend/app/Models/Dataset.ts
Arno Kaimbacher 4714dfdd94
All checks were successful
CI Pipeline / japa-tests (push) Successful in 46s
- use latest prettier 3.0 with eslint-plugin-prettier: 5.0.0-alpha.2
- npm normal updates
- add all xslt and style asstes in extra folder public/assets2
- linting corrections
- delete local .env.test from git tracking: git rm --cached .env.test
- add .env.test into .gitignore file
- add edit functionality for editing by submitter
- npm updates
-added xslt3 packeage for builfing sef files
- added Language.ts class vor language table
- added version to datasetxml2oai-pmh.xslt
2023-07-17 19:13:30 +02:00

135 lines
3.5 KiB
TypeScript

import {
column,
BaseModel,
SnakeCaseNamingStrategy,
manyToMany,
ManyToMany,
belongsTo,
BelongsTo,
hasMany,
HasMany,
computed,
} from '@ioc:Adonis/Lucid/Orm';
import { DateTime } from 'luxon';
import dayjs from 'dayjs';
import Person from './Person';
import User from './User';
import Title from './Title';
import Description from './Description';
import License from './License';
import Subject from './Subject';
import File from './File';
export default class Dataset extends BaseModel {
public static namingStrategy = new SnakeCaseNamingStrategy();
public static primaryKey = 'id';
public static table = 'documents';
public static selfAssignPrimaryKey = false;
@column({ isPrimary: true })
public id: number;
@column({})
public server_state: string;
@column({})
public publisherName: string;
@column({ columnName: 'creating_corporation' })
public creatingCorporation: string;
@column.dateTime({ columnName: 'embargo_date' })
public embargoDate: DateTime;
@column({})
public type: string;
@column({})
public language: string;
@column({})
public account_id: number | null = null;
@column({})
public editor_id: number | null = null;
@column({})
public reviewer_id: number | null = null;
@column({})
public reject_editor_note: string | null;
@column({})
public reject_reviewer_note: string | null;
@column.dateTime({ columnName: 'server_date_published' })
public serverDatePublished: DateTime;
// @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',
})
public createdAt: DateTime;
@column.dateTime({ autoCreate: true, autoUpdate: true, columnName: 'server_date_modified' })
public updatedAt: DateTime;
@manyToMany(() => Person, {
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>;
@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>;
@hasMany(() => File, {
foreignKey: 'document_id',
})
public files: HasMany<typeof File>;
@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;
}
}