2023-01-25 17:35:28 +01:00
|
|
|
import { ISharedLinkRepository } from '@app/domain';
|
2023-06-02 04:09:57 +02:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2023-01-25 17:35:28 +01:00
|
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
import { Repository } from 'typeorm';
|
|
|
|
import { SharedLinkEntity } from '../entities';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class SharedLinkRepository implements ISharedLinkRepository {
|
2023-06-02 04:09:57 +02:00
|
|
|
constructor(@InjectRepository(SharedLinkEntity) private repository: Repository<SharedLinkEntity>) {}
|
2023-01-25 17:35:28 +01:00
|
|
|
|
|
|
|
get(userId: string, id: string): Promise<SharedLinkEntity | null> {
|
|
|
|
return this.repository.findOne({
|
|
|
|
where: {
|
|
|
|
id,
|
|
|
|
userId,
|
|
|
|
},
|
|
|
|
relations: {
|
|
|
|
assets: {
|
|
|
|
exifInfo: true,
|
|
|
|
},
|
|
|
|
album: {
|
|
|
|
assets: {
|
2023-02-18 21:58:55 +01:00
|
|
|
exifInfo: true,
|
2023-01-25 17:35:28 +01:00
|
|
|
},
|
2023-02-28 01:28:45 +01:00
|
|
|
owner: true,
|
2023-01-25 17:35:28 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
order: {
|
|
|
|
createdAt: 'DESC',
|
|
|
|
assets: {
|
2023-02-19 17:44:53 +01:00
|
|
|
fileCreatedAt: 'ASC',
|
2023-01-25 17:35:28 +01:00
|
|
|
},
|
|
|
|
album: {
|
|
|
|
assets: {
|
2023-02-19 17:44:53 +01:00
|
|
|
fileCreatedAt: 'ASC',
|
2023-01-25 17:35:28 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getAll(userId: string): Promise<SharedLinkEntity[]> {
|
|
|
|
return this.repository.find({
|
|
|
|
where: {
|
|
|
|
userId,
|
|
|
|
},
|
|
|
|
relations: {
|
|
|
|
assets: true,
|
2023-02-28 01:28:45 +01:00
|
|
|
album: {
|
|
|
|
owner: true,
|
|
|
|
},
|
2023-01-25 17:35:28 +01:00
|
|
|
},
|
|
|
|
order: {
|
|
|
|
createdAt: 'DESC',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-01 22:56:37 +02:00
|
|
|
async getByKey(key: Buffer): Promise<SharedLinkEntity | null> {
|
2023-01-25 17:35:28 +01:00
|
|
|
return await this.repository.findOne({
|
|
|
|
where: {
|
2023-06-01 22:56:37 +02:00
|
|
|
key,
|
2023-01-25 17:35:28 +01:00
|
|
|
},
|
|
|
|
relations: {
|
|
|
|
assets: true,
|
|
|
|
album: {
|
2023-02-18 21:58:55 +01:00
|
|
|
assets: true,
|
2023-01-25 17:35:28 +01:00
|
|
|
},
|
2023-01-31 19:11:49 +01:00
|
|
|
user: true,
|
2023-01-25 17:35:28 +01:00
|
|
|
},
|
|
|
|
order: {
|
|
|
|
createdAt: 'DESC',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-02 04:09:57 +02:00
|
|
|
create(entity: Partial<SharedLinkEntity>): Promise<SharedLinkEntity> {
|
|
|
|
return this.save(entity);
|
2023-01-25 17:35:28 +01:00
|
|
|
}
|
|
|
|
|
2023-06-02 04:09:57 +02:00
|
|
|
update(entity: Partial<SharedLinkEntity>): Promise<SharedLinkEntity> {
|
|
|
|
return this.save(entity);
|
2023-01-25 17:35:28 +01:00
|
|
|
}
|
|
|
|
|
2023-06-02 04:09:57 +02:00
|
|
|
async remove(entity: SharedLinkEntity): Promise<void> {
|
|
|
|
await this.repository.remove(entity);
|
2023-01-25 17:35:28 +01:00
|
|
|
}
|
|
|
|
|
2023-06-02 04:09:57 +02:00
|
|
|
private async save(entity: Partial<SharedLinkEntity>): Promise<SharedLinkEntity> {
|
|
|
|
await this.repository.save(entity);
|
|
|
|
return this.repository.findOneOrFail({ where: { id: entity.id } });
|
2023-01-25 17:35:28 +01:00
|
|
|
}
|
|
|
|
}
|