Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/common/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ export const deleteUser = async (
await entityManager
.getRepository(ArticlePost)
.update({ authorId: userId }, { authorId: null });
// Manually set user source posts to ghost user
await entityManager
.getRepository(Post)
.update(
{ authorId: userId, sourceId: userId },
{ authorId: ghostUser.id, sourceId: ghostUser.id },
);
// Manually set shared post to 404 dummy user
await entityManager
.getRepository(Post)
Expand Down
2 changes: 2 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const ghostUser = {
id: '404',
username: 'ghost',
name: 'Deleted user',
image:
'https://media.daily.dev/image/upload/s--hNIUzLiO--/f_auto/v1705327420/public/ghost_vlftth',
};

export const deletedPost = {
Expand Down
32 changes: 32 additions & 0 deletions src/migration/1762425247562-GhostUserSource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { ghostUser } from "../common";

export class GhostUserSource1762425247562 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(/* sql */ `
INSERT INTO "public"."source" (
"id",
"name",
"image",
"handle",
"type",
"userId"
)
VALUES (
'${ghostUser.id}',
'${ghostUser.name}',
'${ghostUser.image}',
'${ghostUser.id}',
'user',
'${ghostUser.id}'
)
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(/* sql */ `
DELETE FROM "public"."source"
WHERE "id" = '${ghostUser.id}'
`);
}
}
Loading