Добавлен CurrentUserEnhancer
This commit is contained in:
parent
446e494978
commit
0d7b684244
5 changed files with 62 additions and 5 deletions
|
|
@ -27,9 +27,6 @@ export class EventEmitterModule implements OnModuleInit {
|
|||
return {
|
||||
module: EventEmitterModule,
|
||||
imports: [
|
||||
ServeStaticModule.forRoot({
|
||||
rootPath: join(__dirname, '..', 'client'),
|
||||
}),
|
||||
ConfigModule.forRoot({ load: [() => params?.config || MainConfig()] }),
|
||||
],
|
||||
providers: [
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ export module RedmineTypes {
|
|||
status: IdAndName;
|
||||
priority: IdAndName;
|
||||
author: IdAndName;
|
||||
assigned_to?: IdAndName;
|
||||
category: IdAndName;
|
||||
fixed_version: IdAndName;
|
||||
subject: string;
|
||||
|
|
|
|||
|
|
@ -7,18 +7,28 @@ import { ConfigModule } from '@nestjs/config';
|
|||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import configuration from './configs/app';
|
||||
import { CurrentUserEnhancer } from './issue-enhancers/current-user-enhancer';
|
||||
import { CustomFieldsEnhancer } from './issue-enhancers/custom-fields-enhancer';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
EventEmitterModule.register({
|
||||
config: configuration().redmineIssueEventEmitterConfig,
|
||||
enhancers: [new TimestampEnhancer(), new CustomFieldsEnhancer()],
|
||||
enhancers: [
|
||||
new TimestampEnhancer(),
|
||||
new CustomFieldsEnhancer(),
|
||||
new CurrentUserEnhancer(),
|
||||
],
|
||||
}),
|
||||
ConfigModule.forRoot({ load: [configuration] }),
|
||||
],
|
||||
controllers: [AppController, MainController],
|
||||
providers: [AppService, UsersService, CustomFieldsEnhancer],
|
||||
providers: [
|
||||
AppService,
|
||||
UsersService,
|
||||
CustomFieldsEnhancer,
|
||||
CurrentUserEnhancer,
|
||||
],
|
||||
})
|
||||
export class AppModule {
|
||||
constructor(
|
||||
|
|
|
|||
41
src/issue-enhancers/current-user-enhancer.ts
Normal file
41
src/issue-enhancers/current-user-enhancer.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
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';
|
||||
|
||||
@Injectable()
|
||||
export class CurrentUserEnhancer implements IssueEnhancerInterface {
|
||||
name = 'current-user';
|
||||
|
||||
private rules = {
|
||||
New: 'dev',
|
||||
'In Progress': 'dev',
|
||||
'Re-opened': 'dev',
|
||||
'Code Review': 'cr',
|
||||
Resolved: 'qa',
|
||||
Testing: 'qa',
|
||||
'Wait Release': 'dev',
|
||||
Pending: 'dev',
|
||||
Feedback: 'qa',
|
||||
Closed: 'dev',
|
||||
Rejected: 'dev',
|
||||
};
|
||||
|
||||
init() {
|
||||
return;
|
||||
}
|
||||
|
||||
async enhance(
|
||||
issue: RedmineTypes.Issue,
|
||||
): Promise<RedmineTypes.Issue & Record<string, any>> {
|
||||
const res: RedmineTypes.Issue & Record<string, any> = { ...issue };
|
||||
|
||||
const status = issue.status.name;
|
||||
|
||||
const fieldName = this.rules[status];
|
||||
if (fieldName) {
|
||||
res.current_user = { ...res[fieldName] };
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
@ -46,6 +46,14 @@ export class CustomFieldsEnhancer implements IssueEnhancerInterface {
|
|||
}
|
||||
}
|
||||
|
||||
const dev = issue.assigned_to;
|
||||
if (dev && dev.id) {
|
||||
const devUser = await this.usersService.getUser(dev.id);
|
||||
if (devUser) {
|
||||
res.dev = { ...devUser };
|
||||
}
|
||||
}
|
||||
|
||||
const tags = customFields.find((cf) => cf.name === 'Tags');
|
||||
if (tags && tags.value) {
|
||||
res.tags = tags.value.split(/[ ,;]/);
|
||||
|
|
|
|||
Loading…
Reference in a new issue