mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
46 lines
940 B
TypeScript
46 lines
940 B
TypeScript
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";
|
|
|
|
/**
|
|
* 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}`,
|
|
};
|
|
}
|
|
}
|