clean up userId and albumId
This commit is contained in:
@@ -12,11 +12,11 @@ export enum AlbumUserRole {
|
|||||||
@Index('IDX_427c350ad49bd3935a50baab73', ['album'])
|
@Index('IDX_427c350ad49bd3935a50baab73', ['album'])
|
||||||
@Index('IDX_f48513bf9bccefd6ff3ad30bd0', ['user'])
|
@Index('IDX_f48513bf9bccefd6ff3ad30bd0', ['user'])
|
||||||
export class AlbumUserEntity {
|
export class AlbumUserEntity {
|
||||||
@PrimaryColumn({ type: 'uuid' })
|
@PrimaryColumn({ type: 'uuid', name: 'albumsId' })
|
||||||
albumsId!: string;
|
albumId!: string;
|
||||||
|
|
||||||
@PrimaryColumn({ type: 'uuid' })
|
@PrimaryColumn({ type: 'uuid', name: 'usersId' })
|
||||||
usersId!: string;
|
userId!: string;
|
||||||
|
|
||||||
@JoinColumn({ name: 'albumsId' })
|
@JoinColumn({ name: 'albumsId' })
|
||||||
@ManyToOne(() => AlbumEntity, { onDelete: 'CASCADE', onUpdate: 'CASCADE', nullable: false })
|
@ManyToOne(() => AlbumEntity, { onDelete: 'CASCADE', onUpdate: 'CASCADE', nullable: false })
|
||||||
|
|||||||
@@ -11,19 +11,18 @@ export class AlbumUserRepository implements IAlbumUserRepository {
|
|||||||
constructor(@InjectRepository(AlbumUserEntity) private repository: Repository<AlbumUserEntity>) {}
|
constructor(@InjectRepository(AlbumUserEntity) private repository: Repository<AlbumUserEntity>) {}
|
||||||
|
|
||||||
async create(dto: Partial<AlbumUserEntity>): Promise<AlbumUserEntity> {
|
async create(dto: Partial<AlbumUserEntity>): Promise<AlbumUserEntity> {
|
||||||
const { user, album } = await this.repository.save(dto);
|
const { userId, albumId } = await this.repository.save(dto);
|
||||||
return this.repository.findOneOrFail({ where: { user, album }, relations: { user: true } });
|
return this.repository.findOneOrFail({ where: { userId, albumId } });
|
||||||
}
|
}
|
||||||
|
|
||||||
async update({ userId, albumId }: AlbumPermissionId, dto: Partial<AlbumUserEntity>): Promise<AlbumUserEntity> {
|
async update({ userId, albumId }: AlbumPermissionId, dto: Partial<AlbumUserEntity>): Promise<AlbumUserEntity> {
|
||||||
await this.repository.update({ user: { id: userId }, album: { id: albumId } }, dto);
|
await this.repository.update({ userId, albumId }, dto);
|
||||||
return this.repository.findOneOrFail({
|
return this.repository.findOneOrFail({
|
||||||
where: { user: { id: userId }, album: { id: albumId } },
|
where: { userId, albumId },
|
||||||
relations: { user: true },
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete({ userId, albumId }: AlbumPermissionId): Promise<void> {
|
async delete({ userId, albumId }: AlbumPermissionId): Promise<void> {
|
||||||
await this.repository.delete({ user: { id: userId }, album: { id: albumId } });
|
await this.repository.delete({ userId, albumId });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,9 +231,7 @@ export class AlbumService {
|
|||||||
throw new BadRequestException('User not found');
|
throw new BadRequestException('User not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
album.sharedUsers.push(
|
album.sharedUsers.push(await this.albumUserRepository.create({ userId: userId, albumId: id }));
|
||||||
await this.albumUserRepository.create({ user: { id: userId }, album: { id } } as AlbumUserEntity),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapAlbumWithoutAssets(album);
|
return mapAlbumWithoutAssets(album);
|
||||||
|
|||||||
Reference in New Issue
Block a user