fix(SPG-550) Season Period - Generate hari libur belum terfilter berdasarkan periode tanggal

pull/3/head
Aswin Ashar Abdullah 2024-06-24 16:01:06 +07:00
parent 5fa89e8666
commit 067025312e
5 changed files with 36 additions and 10 deletions

View File

@ -0,0 +1,4 @@
export interface FilterGoogleCalendarEntity {
start_date: Date;
end_date: Date;
}

View File

@ -5,7 +5,7 @@ import { IndexHolidayCalendarManager } from './managers/index-holiday-google-cal
export class GoogleCalendarOrchestrator {
constructor(private indexHoliday: IndexHolidayCalendarManager) { }
async holiday() {
return await this.indexHoliday.execute();
async holiday(params) {
return await this.indexHoliday.execute(params);
}
}

View File

@ -1,9 +1,10 @@
import { Injectable } from '@nestjs/common';
import { google } from 'googleapis';
import { FilterGoogleCalendarEntity } from '../../entities/filter-google-calendar.entity';
@Injectable()
export class IndexHolidayCalendarManager {
async execute() {
async execute(param: FilterGoogleCalendarEntity) {
const events = [];
const calendar = google.calendar({
version: 'v3',
@ -13,8 +14,8 @@ export class IndexHolidayCalendarManager {
const res = await calendar.events.list({
calendarId: calendarId,
timeMin: new Date().getFullYear() + '-01-01T00:00:00Z',
timeMax: new Date().getFullYear() + '-12-31T23:59:59Z',
timeMin: param.start_date ? param.start_date + 'T00:00:00Z' : new Date().getFullYear() + '-01-01T00:00:00Z',
timeMax: param.end_date ? param.end_date + 'T23:59:59Z' : new Date().getFullYear() + '-12-31T23:59:59Z',
singleEvents: true,
orderBy: 'startTime',
});

View File

@ -0,0 +1,18 @@
import { ApiProperty } from "@nestjs/swagger";
import { FilterGoogleCalendarEntity } from "../../domain/entities/filter-google-calendar.entity";
export class FilterGoogleCalendarDto implements FilterGoogleCalendarEntity {
@ApiProperty({
required: false,
type: Date,
example: '2024-04-01'
})
start_date: Date;
@ApiProperty({
required: false,
type: Date,
example: '2024-04-30'
})
end_date: Date;
}

View File

@ -1,7 +1,8 @@
import { GoogleCalendarOrchestrator } from './../domain/usecases/google-calendar.orchestrator';
import { Controller, Get } from '@nestjs/common';
import { Controller, Get, Query } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Public } from 'src/core/guards';
import { FilterGoogleCalendarDto } from './dto/filter-google-calendar.dto';
@ApiTags(`google calendar - read`)
@Controller('google-calendar')
@ -10,7 +11,9 @@ export class GoogleCalendarController {
constructor(private orchestrator: GoogleCalendarOrchestrator) { }
@Get('/holiday')
async calendar() {
return await this.orchestrator.holiday();
async calendar(
@Query() params: FilterGoogleCalendarDto,
) {
return await this.orchestrator.holiday(params);
}
}