'How to structure content actions with Postgres and TypeOrm

I'm currently working on a content api with Nestjs, TypeOrm, and Postgres. I've got content and comments working fine, but I'm struggling to find a way that I can create a set of actions that are dynamic and can be extended if needed.

This is what my TypeORM schemas look like for content and comments currently. I have these in a nestjs factory so this is what a generated TypeOrm entity would be.

class Content {
    @PrimaryGeneratedColumn('uuid')
    id: string;

    @CreateDateColumn({ type: 'timestamptz' })
    createdAt: Date;

    @UpdateDateColumn({ type: 'timestamptz' })
    updatedAt: Date;

    @Column({ default: '' })
    title: string;

    @Column({ default: '' })
    body: string;

    @Column({ default: '' })
    image: string;

    @Column({ default: '' })
    video: string;

    @ManyToOne(
        (_type) => userEntity,
        (user) => user.content,
        {
            eager: true,
            onDelete: 'CASCADE',
        },
    )
    author: User;

    @OneToMany((_type) => Comment, (comment) => comment.parentContent, {
        eager: true,
    })
    comments: Comment[];
}

class Comment {
    @PrimaryGeneratedColumn('uuid')
    id: string;

    @CreateDateColumn({ type: 'timestamptz' })
    createdAt: Date;

    @UpdateDateColumn({ type: 'timestamptz' })
    updatedAt: Date;

    @Column()
    body: string;

    @ManyToOne((_type) => Content, (content) => content.comments, {
        onDelete: 'CASCADE',
    })
    @Exclude()
    parentContent: Content;

    @ManyToOne((_type) => Comment, (comment) => comment.replies, {
        onDelete: 'CASCADE',
    })
    @Exclude()
    parentComment: Comment;

    @OneToMany((_type) => Comment, (comment) => comment.parentComment)
    replies: Comment[];

    @ManyToOne(
        (_type) => userEntity,
        (user) => user.comments,
        {
            eager: true,
            onDelete: 'CASCADE',
        },
    )
    author: User;
}

I've tried a few different ways of setting this up, but would mainly like some input on how people generally set up these systems. While some ways technically work they don't seem to be good in the sense of a scalable app.

It seems that most actions (like, favorite, bookmark) are just boolean so I'm thinking that we would be able to just reuse that logic and change the name, but I'm struggling to see a good way to do that with Postgres. Any help would be appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source