fix(SPG-550) Season Period - Generate hari libur belum terfilter berdasarkan periode tanggal
parent
5fa89e8666
commit
067025312e
|
@ -0,0 +1,4 @@
|
||||||
|
export interface FilterGoogleCalendarEntity {
|
||||||
|
start_date: Date;
|
||||||
|
end_date: Date;
|
||||||
|
}
|
|
@ -3,9 +3,9 @@ import { IndexHolidayCalendarManager } from './managers/index-holiday-google-cal
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GoogleCalendarOrchestrator {
|
export class GoogleCalendarOrchestrator {
|
||||||
constructor(private indexHoliday: IndexHolidayCalendarManager) {}
|
constructor(private indexHoliday: IndexHolidayCalendarManager) { }
|
||||||
|
|
||||||
async holiday() {
|
async holiday(params) {
|
||||||
return await this.indexHoliday.execute();
|
return await this.indexHoliday.execute(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { google } from 'googleapis';
|
import { google } from 'googleapis';
|
||||||
|
import { FilterGoogleCalendarEntity } from '../../entities/filter-google-calendar.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class IndexHolidayCalendarManager {
|
export class IndexHolidayCalendarManager {
|
||||||
async execute() {
|
async execute(param: FilterGoogleCalendarEntity) {
|
||||||
const events = [];
|
const events = [];
|
||||||
const calendar = google.calendar({
|
const calendar = google.calendar({
|
||||||
version: 'v3',
|
version: 'v3',
|
||||||
|
@ -13,8 +14,8 @@ export class IndexHolidayCalendarManager {
|
||||||
|
|
||||||
const res = await calendar.events.list({
|
const res = await calendar.events.list({
|
||||||
calendarId: calendarId,
|
calendarId: calendarId,
|
||||||
timeMin: new Date().getFullYear() + '-01-01T00:00:00Z',
|
timeMin: param.start_date ? param.start_date + 'T00:00:00Z' : new Date().getFullYear() + '-01-01T00:00:00Z',
|
||||||
timeMax: new Date().getFullYear() + '-12-31T23:59:59Z',
|
timeMax: param.end_date ? param.end_date + 'T23:59:59Z' : new Date().getFullYear() + '-12-31T23:59:59Z',
|
||||||
singleEvents: true,
|
singleEvents: true,
|
||||||
orderBy: 'startTime',
|
orderBy: 'startTime',
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -1,16 +1,19 @@
|
||||||
import { GoogleCalendarOrchestrator } from './../domain/usecases/google-calendar.orchestrator';
|
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 { ApiTags } from '@nestjs/swagger';
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
|
import { FilterGoogleCalendarDto } from './dto/filter-google-calendar.dto';
|
||||||
|
|
||||||
@ApiTags(`google calendar - read`)
|
@ApiTags(`google calendar - read`)
|
||||||
@Controller('google-calendar')
|
@Controller('google-calendar')
|
||||||
@Public(true)
|
@Public(true)
|
||||||
export class GoogleCalendarController {
|
export class GoogleCalendarController {
|
||||||
constructor(private orchestrator: GoogleCalendarOrchestrator) {}
|
constructor(private orchestrator: GoogleCalendarOrchestrator) { }
|
||||||
|
|
||||||
@Get('/holiday')
|
@Get('/holiday')
|
||||||
async calendar() {
|
async calendar(
|
||||||
return await this.orchestrator.holiday();
|
@Query() params: FilterGoogleCalendarDto,
|
||||||
|
) {
|
||||||
|
return await this.orchestrator.holiday(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue