1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/backend/model/sql/enitites/FaceRegionEntry.ts

56 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-01-27 07:03:40 +08:00
import {FaceRegion, FaceRegionBox} from '../../../../common/entities/PhotoDTO';
import {Column, Entity, ManyToOne, PrimaryGeneratedColumn} from 'typeorm';
2019-01-12 23:41:45 +08:00
import {PersonEntry} from './PersonEntry';
2019-01-27 07:03:40 +08:00
import {MediaEntity} from './MediaEntity';
2019-01-12 23:41:45 +08:00
export class FaceRegionBoxEntry implements FaceRegionBox {
@Column('int')
height: number;
@Column('int')
width: number;
@Column('int')
2019-03-11 03:57:27 +08:00
left: number;
2019-01-12 23:41:45 +08:00
@Column('int')
2019-03-11 03:57:27 +08:00
top: number;
2019-01-12 23:41:45 +08:00
}
/**
* This is a switching table between media and persons
*/
@Entity()
export class FaceRegionEntry {
@PrimaryGeneratedColumn({unsigned: true})
2019-01-12 23:41:45 +08:00
id: number;
@Column(type => FaceRegionBoxEntry)
box: FaceRegionBoxEntry;
// @PrimaryColumn('int')
@ManyToOne(type => MediaEntity, media => media.metadata.faces, {onDelete: 'CASCADE', nullable: false})
media: MediaEntity;
// @PrimaryColumn('int')
@ManyToOne(type => PersonEntry, person => person.faces, {onDelete: 'CASCADE', nullable: false})
person: PersonEntry;
name: string;
2019-01-27 07:03:40 +08:00
public static fromRawToDTO(raw: {
faces_id: number,
faces_mediaId: number,
faces_personId: number,
faces_boxHeight: number,
faces_boxWidth: number,
2019-03-11 03:57:27 +08:00
faces_boxLeft: number,
faces_boxTop: number,
2019-01-27 07:03:40 +08:00
person_id: number,
person_name: string
}): FaceRegion {
return {
2019-03-11 03:57:27 +08:00
box: {width: raw.faces_boxWidth, height: raw.faces_boxHeight, left: raw.faces_boxLeft, top: raw.faces_boxTop},
2019-01-27 07:03:40 +08:00
name: raw.person_name
};
}
2019-01-12 23:41:45 +08:00
}