Функция добавления числового timestamp для строковых полей с датами
This commit is contained in:
parent
b91f54b26a
commit
d858c7e228
2 changed files with 41 additions and 0 deletions
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { RedmineTypes } from '../models/redmine-types';
|
||||||
|
|
||||||
|
export interface IssueEnhancerInterface {
|
||||||
|
enhance(issue: RedmineTypes.Issue): RedmineTypes.Issue & Record<string, any>;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
import { RedmineTypes } from '../models/redmine-types';
|
||||||
|
import { IssueEnhancerInterface } from './issue-enhancer-interface';
|
||||||
|
|
||||||
|
export class TimestampEnhancer implements IssueEnhancerInterface {
|
||||||
|
enhance(issue: RedmineTypes.Issue): RedmineTypes.Issue & Record<string, any> {
|
||||||
|
return this.createTimestamp(this.enhanceJournal(issue), [
|
||||||
|
'closed_on',
|
||||||
|
'created_on',
|
||||||
|
'updated_on',
|
||||||
|
]) as RedmineTypes.Issue & Record<string, any>;
|
||||||
|
}
|
||||||
|
|
||||||
|
private enhanceJournal(issue: Record<string, any>): Record<string, any> {
|
||||||
|
if (!issue.journals || issue.journals.length === 0) {
|
||||||
|
return issue;
|
||||||
|
}
|
||||||
|
const journals = issue.journals;
|
||||||
|
for (let i = 0; i < journals.length; i++) {
|
||||||
|
journals[i] = this.createTimestamp(journals[i], ['created_on']);
|
||||||
|
}
|
||||||
|
return issue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private createTimestamp(
|
||||||
|
issue: Record<string, any>,
|
||||||
|
fieldNames: string[],
|
||||||
|
): Record<string, any> {
|
||||||
|
for (let i = 0; i < fieldNames.length; i++) {
|
||||||
|
const fieldName = fieldNames[i];
|
||||||
|
if (issue[fieldName]) {
|
||||||
|
issue[`${fieldName}_timestamp`] = new Date(issue[fieldName]).getTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return issue;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue