2024-03-14 19:25:27 +00:00
|
|
|
import { column, SnakeCaseNamingStrategy, computed, manyToMany } from '@adonisjs/lucid/orm';
|
2023-03-03 15:54:28 +00:00
|
|
|
import { DateTime } from 'luxon';
|
|
|
|
import dayjs from 'dayjs';
|
2024-04-30 09:50:50 +00:00
|
|
|
import Dataset from './dataset.js';
|
|
|
|
import BaseModel from './base_model.js';
|
2024-03-14 19:25:27 +00:00
|
|
|
import type { ManyToMany } from "@adonisjs/lucid/types/relations";
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
export default class Person extends BaseModel {
|
2023-06-22 15:20:04 +00:00
|
|
|
public static namingStrategy = new SnakeCaseNamingStrategy();
|
|
|
|
public static primaryKey = 'id';
|
|
|
|
public static table = 'persons';
|
|
|
|
public static selfAssignPrimaryKey = false;
|
|
|
|
// only the academic_title, email, first_name, identifier_orcid, last_name and name_type attributes are allowed to be mass assigned.
|
|
|
|
public static fillable: string[] = ['academic_title', 'email', 'first_name', 'identifier_orcid', 'last_name', 'name_type'];
|
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
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column({ columnName: 'academic_title' })
|
|
|
|
public academicTitle: string;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column()
|
|
|
|
public email: string;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column({})
|
|
|
|
public firstName: string;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column({})
|
|
|
|
public lastName: string;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column({})
|
|
|
|
public identifierOrcid: string;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column({})
|
|
|
|
public status: boolean;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column({})
|
|
|
|
public nameType: string;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column.dateTime({
|
|
|
|
serialize: (value: Date | null) => {
|
|
|
|
return value ? dayjs(value).format('MMMM D YYYY HH:mm a') : value;
|
|
|
|
},
|
|
|
|
autoCreate: true,
|
|
|
|
})
|
|
|
|
public createdAt: DateTime;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@computed({
|
|
|
|
serializeAs: 'name',
|
2023-03-03 15:54:28 +00:00
|
|
|
})
|
2023-06-22 15:20:04 +00:00
|
|
|
public get fullName() {
|
|
|
|
return `${this.firstName} ${this.lastName}`;
|
|
|
|
}
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-03-24 10:41:52 +00:00
|
|
|
// @computed()
|
2023-06-22 15:20:04 +00:00
|
|
|
// public get progress(): number {
|
|
|
|
// return 50;
|
|
|
|
// }
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-03-24 10:41:52 +00:00
|
|
|
// @computed()
|
2023-06-22 15:20:04 +00:00
|
|
|
// public get created_at() {
|
|
|
|
// return '2023-03-21 08:45:00';
|
|
|
|
// }
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
@computed()
|
|
|
|
public get datasetCount() {
|
2023-06-22 15:20:04 +00:00
|
|
|
const stock = this.$extras.datasets_count; //my pivot column name was "stock"
|
|
|
|
return stock;
|
|
|
|
}
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-11-27 16:17:22 +00:00
|
|
|
@computed()
|
|
|
|
public get pivot_contributor_type() {
|
|
|
|
const contributor_type = this.$extras.pivot_contributor_type; //my pivot column name was "stock"
|
|
|
|
return contributor_type;
|
|
|
|
}
|
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@manyToMany(() => Dataset, {
|
|
|
|
pivotForeignKey: 'person_id',
|
|
|
|
pivotRelatedForeignKey: 'document_id',
|
|
|
|
pivotTable: 'link_documents_persons',
|
|
|
|
pivotColumns: ['role', 'sort_order', 'allow_email_contact'],
|
|
|
|
})
|
|
|
|
public datasets: ManyToMany<typeof Dataset>;
|
2023-03-03 15:54:28 +00:00
|
|
|
}
|