Исправлены ошибки и добавлен логгер
This commit is contained in:
parent
d774e6784b
commit
fd0f1fc1f7
1 changed files with 14 additions and 5 deletions
|
|
@ -1,10 +1,12 @@
|
|||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import { RedmineTypes } from 'libs/redmine-types';
|
||||
import nano from 'nano';
|
||||
import { SaveResponse } from './save-response';
|
||||
|
||||
@Injectable()
|
||||
export class RedmineIssuesCacheWriterService {
|
||||
private logger = new Logger(RedmineIssuesCacheWriterService.name);
|
||||
|
||||
constructor(
|
||||
@Inject('ISSUE_DOCUMENT_SCOPE')
|
||||
private issueDbProvider: () => Promise<
|
||||
|
|
@ -13,6 +15,9 @@ export class RedmineIssuesCacheWriterService {
|
|||
) {}
|
||||
|
||||
async saveIssue(issue: any): Promise<SaveResponse> {
|
||||
this.logger.debug(
|
||||
`Saving issue ${issue?.id || '-'} - ${issue?.subject || '-'}`,
|
||||
);
|
||||
const id = Number(issue['id']);
|
||||
let prevIssue: (nano.DocumentGetResponse & RedmineTypes.Issue) | null;
|
||||
const issueDb = await this.issueDbProvider();
|
||||
|
|
@ -32,11 +37,15 @@ export class RedmineIssuesCacheWriterService {
|
|||
newIssue._rev = prevIssue._rev;
|
||||
await issueDb.insert(newIssue);
|
||||
}
|
||||
return {
|
||||
const res = {
|
||||
prev: prevIssue,
|
||||
current: newIssue,
|
||||
journalsDiff: this.getJournalsDiff(prevIssue, newIssue),
|
||||
};
|
||||
this.logger.debug(
|
||||
`Saving issue success ${issue?.id || '-'} - ${issue?.subject || '-'}`,
|
||||
);
|
||||
return res;
|
||||
}
|
||||
|
||||
getJournalsDiff(
|
||||
|
|
@ -45,11 +54,11 @@ export class RedmineIssuesCacheWriterService {
|
|||
): RedmineTypes.Journal[] {
|
||||
if (
|
||||
(!prev || !prev.journals || prev.journals.length === 0) &&
|
||||
current.journals
|
||||
current?.journals
|
||||
) {
|
||||
return current.journals;
|
||||
} else if (prev.journals && current.journals) {
|
||||
return this.calcJournalsDiff(prev.journals, current.journals);
|
||||
} else if (prev?.journals && current?.journals) {
|
||||
return this.calcJournalsDiff(prev?.journals, current?.journals);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue