fix(server): user delete with stacked assets (#10642)

This commit is contained in:
Jason Rasmussen
2024-06-26 09:29:52 -04:00
committed by GitHub
parent 8a445cac07
commit 63041674c2
6 changed files with 64 additions and 12 deletions

View File

@@ -3,7 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { AssetStackEntity } from 'src/entities/asset-stack.entity';
import { IAssetStackRepository } from 'src/interfaces/asset-stack.interface';
import { Instrumentation } from 'src/utils/instrumentation';
import { Repository } from 'typeorm';
import { In, Repository } from 'typeorm';
@Instrumentation()
@Injectable()
@@ -34,6 +34,13 @@ export class AssetStackRepository implements IAssetStackRepository {
});
}
async deleteAll(userId: string): Promise<void> {
// TODO add owner to stack entity
const stacks = await this.repository.find({ where: { primaryAsset: { ownerId: userId } } });
const stackIds = new Set(stacks.map((stack) => stack.id));
await this.repository.delete({ id: In([...stackIds]) });
}
private async save(entity: Partial<AssetStackEntity>) {
const { id } = await this.repository.save(entity);
return this.repository.findOneOrFail({