Доработаны enhancer-ы задач
This commit is contained in:
parent
b0acc664d5
commit
90c4433afb
4 changed files with 19 additions and 4 deletions
|
|
@ -6,23 +6,33 @@ import { IssueEnhancerInterface } from './issue-enhancer-interface';
|
|||
@Injectable()
|
||||
export class EnhancerService {
|
||||
private logger = new Logger(EnhancerService.name);
|
||||
private initilialized = false;
|
||||
|
||||
constructor(
|
||||
private moduleRef: ModuleRef,
|
||||
@Inject('ENHANCERS')
|
||||
private enhancers: IssueEnhancerInterface[],
|
||||
) {
|
||||
this.enhancers.forEach((e) => e.init(this.moduleRef));
|
||||
) {}
|
||||
|
||||
private init(): void {
|
||||
if (!this.initilialized) {
|
||||
this.logger.log(`Initialize EnhancerService`);
|
||||
this.enhancers.forEach((e) => e.init(this.moduleRef));
|
||||
}
|
||||
}
|
||||
|
||||
async enhanceIssue(
|
||||
issue: RedmineTypes.Issue & Record<string, any>,
|
||||
): Promise<RedmineTypes.Issue & Record<string, any>> {
|
||||
this.init();
|
||||
for (let i = 0; i < this.enhancers.length; i++) {
|
||||
const enhancer = this.enhancers[i];
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
this.logger.debug(`Start enhancer "${enhancer.name}" for issue.id = ${issue.id}...`);
|
||||
issue = await enhancer.enhance(issue);
|
||||
this.logger.debug(
|
||||
`Issue after enhancer: issue = ${JSON.stringify(issue)}`,
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
`Success finished enhancer "${enhancer.name}" for issue.id = ${issue.id}...`,
|
||||
);
|
||||
}
|
||||
return issue;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { ModuleRef } from '@nestjs/core';
|
|||
import { RedmineTypes } from '../models/redmine-types';
|
||||
|
||||
export interface IssueEnhancerInterface {
|
||||
name: string;
|
||||
init(moduleRef: ModuleRef);
|
||||
enhance(
|
||||
issue: RedmineTypes.Issue,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import { IssueEnhancerInterface } from './issue-enhancer-interface';
|
|||
|
||||
@Injectable()
|
||||
export class TimestampEnhancer implements IssueEnhancerInterface {
|
||||
name = 'timestamp';
|
||||
|
||||
init() {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import { ModuleRef } from '@nestjs/core';
|
|||
|
||||
@Injectable()
|
||||
export class CustomFieldsEnhancer implements IssueEnhancerInterface {
|
||||
name = 'custom-fields';
|
||||
|
||||
private usersService: UsersService;
|
||||
|
||||
init(moduleRef: ModuleRef): void {
|
||||
|
|
@ -46,7 +48,7 @@ export class CustomFieldsEnhancer implements IssueEnhancerInterface {
|
|||
|
||||
const tags = customFields.find((cf) => cf.name === 'Tags');
|
||||
if (tags && tags.value) {
|
||||
res.tags = tags.value.split(',; ');
|
||||
res.tags = tags.value.split(/[ ,;]/);
|
||||
}
|
||||
|
||||
const sp = customFields.find(
|
||||
|
|
|
|||
Loading…
Reference in a new issue