Front/Back: add tv-series auto sync when vising the calendar

This commit is contained in:
X4Lo committed 2024-10-21 15:59:04 +01:00
1 parent 9530b52830
commit 7160669468
2 files changed
+34 -16

No files matched your search

@@ -8,26 +8,30 @@ const Media = require("../../models/Media");
async function getEpisodesBetweenDates(startDate, endDate) {
// Get the first and last day of the month based on the provided date
const formatedStartDate = moment(startDate).format('YYYY-MM-DD');
const formatedEndDate = moment(endDate).format('YYYY-MM-DD');
// Fetch episodes that aired within the current month
// fetch episodes that aired within the current month
const episodes = await Episode.findAll({
where: {
air_date: {
[Op.between]: [formatedStartDate, formatedEndDate]
}
},
},
include: [
{
model: Season,
as: 'season',
include: {
model: Entry, as: 'entry', include: [
model: Entry,
as: 'entry',
include: [
{ model: EntryId, as: 'entryId' },
{ model: Media, as: 'medias' },
]
{
model: Media,
as: 'medias',
},
],
}
}
]
@@ -7,10 +7,11 @@ import {
} from '@fullcalendar/core';
import dayGridPlugin from '@fullcalendar/daygrid';
import interactionPlugin from '@fullcalendar/interaction';
import { Title } from '@angular/platform-browser';
import { environment } from '../../../../environments/environment.prod';
import { Entry } from '../../../shared/models/entry.model';
import { Router } from '@angular/router';
import { ToastService } from '../../../shared/services/toast.service';
import { EntryService } from '../../../core/services/entry.service';
@Component({
selector: 'app-calendar-page',
@@ -36,7 +37,12 @@ export class CalendarPageComponent implements OnInit {
height: 'auto',
};
constructor(private episodeService: EpisodeService, private router: Router) {}
constructor(
private episodeService: EpisodeService,
private toastService: ToastService,
private entryService: EntryService,
private router: Router
) {}
ngOnInit() {
const today = new Date();
@@ -49,15 +55,24 @@ export class CalendarPageComponent implements OnInit {
// console.log('First Day of First Week:', firstDayOfFirstWeek);
// console.log('Last Day of Last Week:', lastDayOfLastWeek);
this.fetchEpisodes(firstDayOfFirstWeek, lastDayOfLastWeek);
this.toastService.show('Welcome', 'hello', 'success');
this.entryService.syncSeries().subscribe({
next: (result) => {
console.log(`Tv-Series Synced Successfully`);
},
error: (error) => {
console.log(`Error Syncing Tv-Series Successfully`);
},
});
// this.fetchEpisodes(firstDayOfFirstWeek, lastDayOfLastWeek);
}
fetchEpisodes(startDate: string, endDate: string) {
this.episodeService.getMonthEpisodes(startDate, endDate).subscribe({
next: (result) => {
// console.log(result);
this.calendarOptions.events = result
.filter((e) => e.season.season_number != 0)
.filter((e) => e.season.season_number != 0 && e.entry.showInCalendar)
.map((e) => {
return {
title: `S${e.season.season_number}E${e.episode_number}`,
@@ -78,9 +93,9 @@ export class CalendarPageComponent implements OnInit {
// ? month change
handleDatesSet(arg: DatesSetArg) {
// console.log('View dates changed:', arg.startStr, arg.endStr);
console.log('View dates changed:', arg.startStr, arg.endStr);
this.fetchEpisodes(arg.startStr, arg.endStr);
this.fetchEpisodes(arg.startStr.split('T')[0], arg.endStr.split('T')[0]);
}
handleEventClick(clickInfo: EventClickArg) {
@@ -89,7 +104,6 @@ export class CalendarPageComponent implements OnInit {
// const event = clickInfo.event as any;
// console.log(event);
// this.router.navigate([`/entries/${clickInfo.event.publicId}`]);
// Example: You can also access other event properties
// console.log('Clicked event details:', clickInfo.event);
}
@@ -149,8 +163,8 @@ export class CalendarPageComponent implements OnInit {
getPosterPath(entry: Entry) {
// * Not in library, use TMDB poster
if (!entry.isInLibrary)
return `https://image.tmdb.org/t/p/w342` + entry.poster_path;
// if (!entry.isInLibrary)
// return `https://image.tmdb.org/t/p/w342` + entry.poster_path;
// * Is in library: use a local poster
if (entry.medias) {