Redmine types added

This commit is contained in:
Pavel Gnedov 2022-05-17 15:57:03 +07:00
parent 755eecdeed
commit 2fb145d671
7 changed files with 123 additions and 3 deletions

View file

@ -1,11 +1,12 @@
import { DynamicModule, Module } from '@nestjs/common';
import { RedmineIssuesCacheWriterService } from './redmine-issues-cache-writer.service';
import nano = require('nano');
import { RedmineTypes } from 'libs/redmine-types';
@Module({})
export class RedmineIssuesCacheWriterModule {
static register(params: {
issueDocumentScope: nano.DocumentScope<any>;
issueDocumentScope: nano.DocumentScope<RedmineTypes.Issue>;
}): DynamicModule {
return {
module: RedmineIssuesCacheWriterModule,

View file

@ -1,9 +1,13 @@
import { Inject, Injectable } from '@nestjs/common';
import { RedmineTypes } from 'libs/redmine-types';
import nano from 'nano';
@Injectable()
export class RedmineIssuesCacheWriterService {
constructor(@Inject() private issueDb: nano.DocumentScope<any>) {}
constructor(
@Inject('ISSUE_DOCUMENT_SCOPE')
private issueDb: nano.DocumentScope<RedmineTypes.Issue>,
) {}
async saveIssue(issue: any): Promise<void> {
const id = Number(issue['id']);

97
libs/redmine-types/index.d.ts vendored Normal file
View file

@ -0,0 +1,97 @@
/// <reference types="typescript" />
export module RedmineTypes {
export type IdAndName = {
id: number;
name: string;
};
export type CustomField = {
id: number;
name: string;
value: string;
};
export type JournalDetail = {
property: string;
name: string;
old_value: string;
new_value: string;
};
export type Journal = {
id: number;
user: IdAndName;
notes: string;
created_on: string;
details?: JournalDetail[];
};
export type Issue = {
id: number;
project: IdAndName;
tracker: IdAndName;
status: IdAndName;
priority: IdAndName;
author: IdAndName;
category: IdAndName;
fixed_version: IdAndName;
subject: string;
description: string;
start_date: string;
done_ratio: number;
spent_hours: number;
total_spent_hours: number;
custom_fields: CustomField[];
created_on: string;
updated_on?: string;
closed_on?: string;
relations?: Record<string, any>[];
}
export module Unknown {
export const num = -1;
export const str = '';
export const idAndName: IdAndName = {
id: -1,
name: str
};
export const unknownName = 'Unknown';
export const subject = 'Unknown';
export const date = '1970-01-01T00:00:00Z';
export const issue: Issue = {
id: num,
project: idAndName,
tracker: idAndName,
status: idAndName,
priority: idAndName,
author: idAndName,
category: idAndName,
fixed_version: idAndName,
subject: subject,
description: str,
start_date: date,
done_ratio: num,
spent_hours: num,
total_spent_hours: num,
custom_fields: [],
created_on: date
};
export const user: User = {
id: num,
firstname: unknownName,
lastname: unknownName,
mail: str
};
}
export type User = {
id: number;
firstname: string;
lastname: string;
mail: string;
}
}

View file

View file

@ -0,0 +1,12 @@
{
"name": "redmine-types",
"version": "0.1.0",
"description": "",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Pavel Gnedov",
"license": "MIT"
}

View file

@ -83,5 +83,8 @@
"^@app/event-emitter(|/.*)$": "<rootDir>/libs/event-emitter/src/$1",
"^@app/redmine-issues-cache-writer(|/.*)$": "<rootDir>/libs/redmine-issues-cache-writer/src/$1"
}
}
},
"workspaces": [
"libs/redmine-types"
]
}

View file

@ -29,6 +29,9 @@
],
"@app/redmine-issues-cache-writer/*": [
"libs/redmine-issues-cache-writer/src/*"
],
"@app/redmine-types/*": [
"libs/redmine-types/*"
]
}
}