hippofish/packages/backend/src/models/LatestNote.ts

50 lines
983 B
TypeScript
Raw Normal View History

2024-09-30 03:27:38 +02:00
import { PrimaryColumn, Entity, JoinColumn, Column, ManyToOne } from 'typeorm';
import { MiUser } from '@/models/User.js';
import { MiNote } from '@/models/Note.js';
/**
* Maps a user to the most recent post by that user.
* Public, home-only, and followers-only posts are included.
* DMs are not counted.
*/
@Entity('latest_note')
export class LatestNote {
@PrimaryColumn({
name: 'user_id',
type: 'varchar' as const,
length: 32,
})
public userId: string;
@ManyToOne(() => MiUser, {
onDelete: 'CASCADE',
})
@JoinColumn({
name: 'user_id',
})
2024-09-30 03:27:38 +02:00
public user: MiUser | null;
@Column({
name: 'note_id',
type: 'varchar' as const,
length: 32,
})
public noteId: string;
@ManyToOne(() => MiNote, {
onDelete: 'CASCADE',
})
@JoinColumn({
name: 'note_id',
})
2024-09-30 03:27:38 +02:00
public note: MiNote | null;
2024-09-30 03:52:57 +02:00
2024-09-30 05:22:58 +02:00
constructor(data?: Partial<LatestNote>) {
if (!data) return;
2024-09-30 03:52:57 +02:00
for (const [k, v] of Object.entries(data)) {
2024-09-30 04:50:39 +02:00
(this as Record<string, unknown>)[k] = v;
2024-09-30 03:52:57 +02:00
}
}
2024-09-30 03:27:38 +02:00
}