Исправлены ошибки линтера
This commit is contained in:
parent
f2e0bd7f47
commit
ea8115cbee
2 changed files with 128 additions and 119 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import { Controller, Get, Inject, Logger, Param, Query } from "@nestjs/common";
|
import { Controller, Get, Inject, Logger, Param, Query } from '@nestjs/common';
|
||||||
import { CalendarService } from "./calendar.service";
|
import { CalendarService } from './calendar.service';
|
||||||
import nano from 'nano';
|
import nano from 'nano';
|
||||||
import { UNLIMITED } from "../consts/consts";
|
import { UNLIMITED } from '../consts/consts';
|
||||||
|
|
||||||
@Controller('calendar')
|
@Controller('calendar')
|
||||||
export class CalendarController {
|
export class CalendarController {
|
||||||
|
|
@ -9,7 +9,7 @@ export class CalendarController {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject('CALENDAR_SERVICE')
|
@Inject('CALENDAR_SERVICE')
|
||||||
private calendarService: CalendarService
|
private calendarService: CalendarService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
|
|
@ -20,38 +20,34 @@ export class CalendarController {
|
||||||
@Get('/simple')
|
@Get('/simple')
|
||||||
async simple(
|
async simple(
|
||||||
@Query('project') project?: string,
|
@Query('project') project?: string,
|
||||||
@Query('category') category?: string
|
@Query('category') category?: string,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const andSection: any[] = [
|
const andSection: any[] = [
|
||||||
{
|
{
|
||||||
"closed_on": {
|
closed_on: {
|
||||||
"$exists": false
|
$exists: false,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
if (project) {
|
if (project) {
|
||||||
andSection.push({
|
andSection.push({
|
||||||
"project.name": {
|
'project.name': {
|
||||||
"$in": [
|
$in: [project],
|
||||||
project
|
},
|
||||||
]
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (category) {
|
if (category) {
|
||||||
andSection.push({
|
andSection.push({
|
||||||
"category.name": {
|
'category.name': {
|
||||||
"$in": [
|
$in: [category],
|
||||||
category
|
},
|
||||||
]
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const query: nano.MangoQuery = {
|
const query: nano.MangoQuery = {
|
||||||
selector: {
|
selector: {
|
||||||
"$and": andSection
|
$and: andSection,
|
||||||
},
|
},
|
||||||
limit: UNLIMITED
|
limit: UNLIMITED,
|
||||||
};
|
};
|
||||||
return await this.calendarService.getICalData(query);
|
return await this.calendarService.getICalData(query);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { Injectable, Logger } from "@nestjs/common";
|
import { Injectable } from '@nestjs/common';
|
||||||
import { CalendarEvent } from "../models/calendar-event";
|
import { CalendarEvent } from '../models/calendar-event';
|
||||||
import { RedmineTypes } from "../models/redmine-types";
|
import { RedmineTypes } from '../models/redmine-types';
|
||||||
import * as Luxon from 'luxon';
|
import * as Luxon from 'luxon';
|
||||||
import { IssuesService } from "../issues/issues.service";
|
import { IssuesService } from '../issues/issues.service';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -44,25 +44,35 @@ export type IssueAndEvent = {
|
||||||
export class CalendarService {
|
export class CalendarService {
|
||||||
private interval = 30 * 24 * 60 * 60 * 1000; // 30 days
|
private interval = 30 * 24 * 60 * 60 * 1000; // 30 days
|
||||||
|
|
||||||
constructor(public calendarEventsKey: string, private issuesService: IssuesService) {}
|
constructor(
|
||||||
|
public calendarEventsKey: string,
|
||||||
|
private issuesService: IssuesService,
|
||||||
|
) {}
|
||||||
|
|
||||||
async getICalData(filter: any): Promise<string> {
|
async getICalData(filter: any): Promise<string> {
|
||||||
const issues = await this.issuesService.find(filter);
|
const issues = await this.issuesService.find(filter);
|
||||||
const actualEvents = this.getActualEvents(issues);
|
const actualEvents = this.getActualEvents(issues);
|
||||||
const formattedEvents = actualEvents.map((event) => {
|
const formattedEvents = actualEvents
|
||||||
|
.map((event) => {
|
||||||
return this.generateICalendarEvent(event.issue, event.event);
|
return this.generateICalendarEvent(event.issue, event.event);
|
||||||
}).filter((event) => {
|
})
|
||||||
|
.filter((event) => {
|
||||||
return !!event;
|
return !!event;
|
||||||
});
|
});
|
||||||
const res = this.generateICalendar(formattedEvents);
|
const res = this.generateICalendar(formattedEvents);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getActualEvents(issues: RedmineTypes.ExtendedIssue[]): IssueAndEvent[] {
|
private getActualEvents(
|
||||||
|
issues: RedmineTypes.ExtendedIssue[],
|
||||||
|
): IssueAndEvent[] {
|
||||||
const res: IssueAndEvent[] = [];
|
const res: IssueAndEvent[] = [];
|
||||||
for (let i = 0; i < issues.length; i++) {
|
for (let i = 0; i < issues.length; i++) {
|
||||||
const issue = issues[i];
|
const issue = issues[i];
|
||||||
if (!issue[this.calendarEventsKey] || issue[this.calendarEventsKey].length <= 0) {
|
if (
|
||||||
|
!issue[this.calendarEventsKey] ||
|
||||||
|
issue[this.calendarEventsKey].length <= 0
|
||||||
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const events = issue[this.calendarEventsKey];
|
const events = issue[this.calendarEventsKey];
|
||||||
|
|
@ -80,11 +90,14 @@ export class CalendarService {
|
||||||
const to = now + this.interval;
|
const to = now + this.interval;
|
||||||
return Boolean(
|
return Boolean(
|
||||||
(from <= event.fromTimestamp && event.fromTimestamp <= to) ||
|
(from <= event.fromTimestamp && event.fromTimestamp <= to) ||
|
||||||
(from <= event.toTimestamp && event.toTimestamp <= to)
|
(from <= event.toTimestamp && event.toTimestamp <= to),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private generateICalendarEvent(issue: RedmineTypes.Issue, data: CalendarEvent): string | null {
|
private generateICalendarEvent(
|
||||||
|
issue: RedmineTypes.Issue,
|
||||||
|
data: CalendarEvent,
|
||||||
|
): string | null {
|
||||||
if (!data) return null;
|
if (!data) return null;
|
||||||
return `BEGIN:VEVENT
|
return `BEGIN:VEVENT
|
||||||
UID:${randomUUID()}@example.com
|
UID:${randomUUID()}@example.com
|
||||||
|
|
@ -97,7 +110,7 @@ END:VEVENT`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private formatTimestamp(timestamp: number, fullDay?: boolean): string {
|
private formatTimestamp(timestamp: number, fullDay?: boolean): string {
|
||||||
let format: string = fullDay ? "yyyyMMdd" : "yyyyMMdd'T'HHmmss'Z'";
|
const format: string = fullDay ? 'yyyyMMdd' : "yyyyMMdd'T'HHmmss'Z'";
|
||||||
let datetime = Luxon.DateTime.fromMillis(timestamp);
|
let datetime = Luxon.DateTime.fromMillis(timestamp);
|
||||||
if (!fullDay) datetime = datetime.setZone('utc');
|
if (!fullDay) datetime = datetime.setZone('utc');
|
||||||
return datetime.toFormat(format);
|
return datetime.toFormat(format);
|
||||||
|
|
@ -107,7 +120,7 @@ END:VEVENT`;
|
||||||
return `BEGIN:VCALENDAR
|
return `BEGIN:VCALENDAR
|
||||||
VERSION:2.0
|
VERSION:2.0
|
||||||
PRODID:-//Example Corp.//CalDAV Client//EN
|
PRODID:-//Example Corp.//CalDAV Client//EN
|
||||||
${events.join("\n")}
|
${events.join('\n')}
|
||||||
END:VCALENDAR`;
|
END:VCALENDAR`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue