2023-03-03 15:54:28 +00:00
|
|
|
import {
|
|
|
|
column,
|
|
|
|
BaseModel,
|
|
|
|
SnakeCaseNamingStrategy,
|
|
|
|
computed,
|
|
|
|
manyToMany,
|
|
|
|
ManyToMany,
|
|
|
|
} from '@ioc:Adonis/Lucid/Orm';
|
|
|
|
import { DateTime } from 'luxon';
|
|
|
|
import dayjs from 'dayjs';
|
|
|
|
import Dataset from './Dataset';
|
|
|
|
|
|
|
|
export default class Person extends BaseModel {
|
|
|
|
public static namingStrategy = new SnakeCaseNamingStrategy();
|
|
|
|
public static primaryKey = 'id';
|
|
|
|
public static table = 'persons';
|
|
|
|
public static selfAssignPrimaryKey = false;
|
|
|
|
|
|
|
|
@column({
|
|
|
|
isPrimary: true,
|
|
|
|
})
|
|
|
|
public id: number;
|
|
|
|
|
|
|
|
@column({})
|
|
|
|
public academicTitle: string;
|
|
|
|
|
|
|
|
@column()
|
|
|
|
public email: string;
|
|
|
|
|
|
|
|
@column({})
|
|
|
|
public firstName: string;
|
|
|
|
|
|
|
|
@column({})
|
|
|
|
public lastName: string;
|
|
|
|
|
|
|
|
@column({})
|
|
|
|
public identifierOrcid: string;
|
|
|
|
|
|
|
|
@column({})
|
|
|
|
public status: boolean;
|
|
|
|
|
|
|
|
@column({})
|
|
|
|
public nameType: string;
|
|
|
|
|
|
|
|
@column.dateTime({
|
|
|
|
serialize: (value: Date | null) => {
|
|
|
|
return value ? dayjs(value).format('MMMM D YYYY HH:mm a') : value;
|
|
|
|
},
|
|
|
|
autoCreate: true,
|
|
|
|
})
|
2023-03-24 10:41:52 +00:00
|
|
|
public createdAt: DateTime;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
@computed({
|
|
|
|
serializeAs: 'name'
|
|
|
|
})
|
|
|
|
public get fullName() {
|
2023-03-24 10:41:52 +00:00
|
|
|
return `${this.firstName} ${this.lastName}`;
|
2023-03-03 15:54:28 +00:00
|
|
|
}
|
|
|
|
|
2023-03-24 10:41:52 +00:00
|
|
|
// @computed()
|
|
|
|
// public get progress(): number {
|
|
|
|
// return 50;
|
|
|
|
// }
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-03-24 10:41:52 +00:00
|
|
|
// @computed()
|
|
|
|
// public get created_at() {
|
|
|
|
// return '2023-03-21 08:45:00';
|
|
|
|
// }
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
@computed()
|
|
|
|
public get datasetCount() {
|
|
|
|
const stock = this.$extras.datasets_count //my pivot column name was "stock"
|
|
|
|
return stock
|
|
|
|
}
|
|
|
|
|
|
|
|
@manyToMany(() => Dataset, {
|
|
|
|
pivotForeignKey: 'person_id',
|
|
|
|
pivotRelatedForeignKey: 'document_id',
|
|
|
|
pivotTable: 'link_documents_persons',
|
|
|
|
pivotColumns: ['role', 'sort_order', 'allow_email_contact']
|
|
|
|
})
|
|
|
|
public datasets: ManyToMany<typeof Dataset>;
|
|
|
|
}
|