fix(server): restore user (#15763)

This commit is contained in:
Jason Rasmussen
2025-01-29 11:49:08 -05:00
committed by GitHub
parent 9033a99587
commit a0aea021a1
9 changed files with 39 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ import { DB, UserMetadata as DbUserMetadata, Users } from 'src/db';
import { DummyValue, GenerateSql } from 'src/decorators';
import { UserMetadata } from 'src/entities/user-metadata.entity';
import { UserEntity, withMetadata } from 'src/entities/user.entity';
import { UserStatus } from 'src/enum';
import {
IUserRepository,
UserFindOptions,
@@ -140,6 +141,16 @@ export class UserRepository implements IUserRepository {
.executeTakeFirst() as unknown as Promise<UserEntity>;
}
restore(id: string): Promise<UserEntity> {
return this.db
.updateTable('users')
.set({ status: UserStatus.ACTIVE, deletedAt: null })
.where('users.id', '=', asUuid(id))
.returning(columns)
.returning(withMetadata)
.executeTakeFirst() as unknown as Promise<UserEntity>;
}
async upsertMetadata<T extends keyof UserMetadata>(id: string, { key, value }: { key: T; value: UserMetadata[T] }) {
await this.db
.insertInto('user_metadata')