server/database/entities/Like.ts

46 lines
940 B
TypeScript
Raw Normal View History

2023-10-28 22:21:04 +02:00
import {
BaseEntity,
CreateDateColumn,
Entity,
ManyToOne,
PrimaryGeneratedColumn,
} from "typeorm";
import { User } from "./User";
import { Status } from "./Status";
import { Like as LysandLike } from "~types/lysand/Object";
import { getConfig } from "@config";
2023-10-28 22:21:04 +02:00
/**
* Represents a Like entity in the database.
*/
@Entity({
name: "likes",
})
export class Like extends BaseEntity {
/** The unique identifier of the Like. */
@PrimaryGeneratedColumn("uuid")
id!: string;
/** The User who liked the Status. */
@ManyToOne(() => User)
liker!: User;
/** The Status that was liked. */
@ManyToOne(() => Status)
liked!: Status;
@CreateDateColumn()
created_at!: Date;
toLysand(): LysandLike {
return {
id: this.id,
author: this.liker.uri,
type: "Like",
created_at: new Date(this.created_at).toISOString(),
object: this.liked.toLysand().uri,
uri: `${getConfig().http.base_url}/actions/${this.id}`,
};
}
2023-10-28 22:21:04 +02:00
}