59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { SeriesEntity } from './entities/series.entity';
|
|
import { Repository } from 'typeorm';
|
|
import { CreateSeriesDto } from './dto/create-series.dto';
|
|
import { SeriesDto } from './dto/series.dto';
|
|
import { SeriesSubscriptionEntity } from './entities/series-subscription.entity';
|
|
import { UUID } from 'crypto';
|
|
import { SeriesSubscriptionDto } from './dto/series-subscription.dto';
|
|
|
|
@Injectable()
|
|
export class SeriesService {
|
|
constructor(
|
|
@InjectRepository(SeriesEntity)
|
|
private seriesRepository: Repository<SeriesEntity>,
|
|
@InjectRepository(SeriesSubscriptionEntity)
|
|
private seriesSubscriptionRepository: Repository<SeriesSubscriptionEntity>,
|
|
) { }
|
|
|
|
|
|
async addSeries(series: CreateSeriesDto) {
|
|
return await this.seriesRepository.insert(series);
|
|
}
|
|
|
|
async addSeriesSubscription(series: SeriesSubscriptionDto) {
|
|
return await this.seriesSubscriptionRepository.insert(series);
|
|
}
|
|
|
|
async deleteSeries(series: SeriesDto) {
|
|
return await this.seriesRepository.delete(series);
|
|
}
|
|
|
|
async deleteSeriesSubscription(subscription: SeriesSubscriptionDto) {
|
|
return await this.seriesSubscriptionRepository.delete(subscription);
|
|
}
|
|
|
|
async getSeries(series: SeriesDto) {
|
|
return await this.seriesRepository.findOne({
|
|
where: series
|
|
})
|
|
}
|
|
|
|
async getAllSeries() {
|
|
return await this.seriesRepository.find()
|
|
}
|
|
|
|
async getSeriesSubscribedBy(userId: UUID) {
|
|
return await this.seriesSubscriptionRepository.find({
|
|
where: {
|
|
userId,
|
|
}
|
|
});
|
|
}
|
|
|
|
async updateSeries(series: CreateSeriesDto) {
|
|
return await this.seriesRepository.upsert(series, ['provider', 'providerSeriesId']);
|
|
}
|
|
}
|