Разработка парсера событий для календаря

This commit is contained in:
Pavel Gnedov 2023-06-24 17:55:20 +07:00
parent 54a7e19b4f
commit a0e183075f
3 changed files with 69 additions and 0 deletions

View file

@ -0,0 +1,6 @@
{
"interviewProjects": [
"Программисты, инженеры HW"
],
"customFieldDateFormat": "yyyy-MM-dd HH:mm"
}

View file

@ -0,0 +1,4 @@
{
"interviewProjects": [],
"customFieldDateFormat": "yyyy-MM-dd HH:mm"
}

View file

@ -0,0 +1,59 @@
import { IssueEnhancerInterface } from '@app/event-emitter/issue-enhancers/issue-enhancer-interface';
import { RedmineTypes } from '@app/event-emitter/models/redmine-types';
import { Injectable } from '@nestjs/common';
import * as Luxon from 'luxon';
export type SubjectParserParam = {
regexp: string;
format: string;
type: string;
};
export type DescriptionParserParam = {};
@Injectable()
export class InterviewEnhancer implements IssueEnhancerInterface {
name = 'interview';
constructor(
public interviewProjects: string[] = [],
public customFieldDateFormat: string = 'yyyy-MM-dd HH:mm',
public subjectParserParams: SubjectParserParam[]
) {}
async enhance(
issue: RedmineTypes.Issue,
): Promise<RedmineTypes.Issue & Record<string, any>> {
const res: RedmineTypes.ExtendedIssue = { ...issue };
if (this.interviewProjects.indexOf(res.project.name) < 0) {
return res;
}
const subject = res.subject;
const nextEventDateField = res.custom_fields.find((cf) => {
return cf.name === 'Дата следующего обновления';
});
if ()
const nextEventDate = Luxon.DateTime.fromFormat(nextEventDateField.value, this.customFieldDateFormat);
return res;
}
private getNextEventDate(issue: RedmineTypes.ExtendedIssue): Luxon.DateTime|null {
const nextEventDateField = issue.custom_fields.find((cf) => {
return cf.name === 'Дата следующего обновления';
});
if (!nextEventDateField) return null;
const nextEventDate = Luxon.DateTime.fromFormat(nextEventDateField.value, this.customFieldDateFormat);
if (!nextEventDate.isValid) return null;
return nextEventDate;
}
private getDateFromSubject(issue: RedmineTypes.ExtendedIssue): Luxon.DateTime|null {
const subject = issue.subject;
return null;
}
}