Skip to content

Commit 0522591

Browse files
committed
reports to jira instead of discord
1 parent a47617b commit 0522591

File tree

6 files changed

+120
-21
lines changed

6 files changed

+120
-21
lines changed

src/controllers/entries.controller.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { config } from "../services/config.service.js"
77
import * as EntryService from "../services/entry.service.js"
88
import * as Database from "../services/database.service.js"
99
import * as DiscordService from "../services/discord.service.js"
10+
import * as AtlassianService from "../services/atlassian.service.js"
1011

1112
import queryNumberParser from "../middleware/queryNumberParser.middleware.js"
1213
import queryArrayParser from "../middleware/queryArrayParser.middleware.js"
@@ -57,7 +58,8 @@ export default class EntriesController {
5758

5859
res.status(StatusCode.Created).end();
5960

60-
DiscordService.sendNewEntryNotification(req.body.name, req.body.type);
61+
// DiscordService.sendNewEntryNotification(req.body.name, req.body.type);
62+
AtlassianService.newEntryTicket(req.body.name);
6163
}
6264

6365
@Get("unapproved")

src/controllers/report.controller.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import validate from "../middleware/validation.middleware.js"
88

99
import { config } from "../services/config.service.js"
1010
import * as Database from "../services/database.service.js"
11-
import * as Discord from "../services/discord.service.js"
11+
import * as Atlassian from "../services/atlassian.service.js"
1212

1313

1414
const newReportLimiter = rateLimit({
@@ -27,7 +27,7 @@ export default class ReportController {
2727

2828
if (!entry) return res.status(StatusCode.NotFound).send({ error: "entry_not_found" }).end();
2929

30-
let sent = await Discord.sendReport(entry, req.body.type, req.body.message);
30+
let sent = await Atlassian.createReportTicket(entry, req.body.type, req.body.message);
3131

3232
if (!sent) return res.status(StatusCode.InternalServerError).end();
3333

src/models/entryMapping.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import IDictionary from "../types/dictionary"
2+
3+
export const typeMapping: IDictionary = {
4+
group: "Gruppe/Verein",
5+
therapist: "Therapeut*in/Psychiater*in",
6+
surveyor: "Gutachter*in",
7+
endocrinologist: "Endokrinologische Praxis",
8+
surgeon: "Operateur*in",
9+
logopedics: "Logopäd*in",
10+
hairremoval: "Haarentfernung"
11+
}
12+
13+
export const reportTypeMapping = {
14+
edit: "Änderungsvorschlag",
15+
report: "Nicht empfehlenswert",
16+
other: "Sonstiges"
17+
}

src/services/atlassian.service.ts

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import axios from "axios";
2+
import { DatabaseEntry } from "../models/database/entry.model";
3+
import { reportTypeMapping } from "../models/entryMapping";
4+
import IDictionary from "../types/dictionary";
5+
import { config } from "./config.service.js";
6+
7+
export async function createReportTicket(entry: DatabaseEntry<"out">, type: keyof typeof reportTypeMapping, message: string) {
8+
const customFields = new Map<string, unknown>();
9+
customFields.set(config.atlassian.customFieldReportType, { id: config.atlassian.customfieldReportTypeMapping[type] });
10+
customFields.set(config.atlassian.customfieldURL, config.reportEntryURL + entry._id);
11+
12+
const body: IDictionary = {
13+
fields: {
14+
issuetype: {
15+
id: config.atlassian.issueTypes.report
16+
},
17+
summary: entry.name,
18+
project: {
19+
id: config.atlassian.projectId,
20+
},
21+
description: {
22+
content: [
23+
{
24+
content: [
25+
{
26+
text: message,
27+
type: "text"
28+
}
29+
],
30+
type: "paragraph"
31+
}
32+
],
33+
type: "doc",
34+
version: 1
35+
},
36+
...Object.fromEntries(customFields.entries())
37+
}
38+
}
39+
40+
try {
41+
await axios.post(config.atlassian.apiURL, body, {
42+
auth: {
43+
username: config.atlassian.username,
44+
password: config.atlassian.key,
45+
}
46+
});
47+
return true;
48+
} catch (e: any) {
49+
console.error(`Error while creating atlassian jira ticket! Status Code: ${e.message}`);
50+
return false;
51+
}
52+
}
53+
54+
export async function newEntryTicket(name: string) {
55+
const body: IDictionary = {
56+
fields: {
57+
issuetype: {
58+
id: config.atlassian.issueTypes.newEntry
59+
},
60+
summary: name,
61+
project: {
62+
id: config.atlassian.projectId,
63+
}
64+
}
65+
}
66+
67+
try {
68+
await axios.post(config.atlassian.apiURL, body, {
69+
auth: {
70+
username: config.atlassian.username,
71+
password: config.atlassian.key,
72+
}
73+
});
74+
return true;
75+
} catch (e: any) {
76+
console.error(`Error while creating atlassian jira ticket! Status Code: ${e.message}`);
77+
return false;
78+
}
79+
}

src/services/config.service.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,24 @@ const defaultConfig = {
6060
}
6161
},
6262
discordWebhookURL: "",
63-
reportEntryURL: "https://transdb.de/manage/database?id="
63+
reportEntryURL: "https://transdb.de/manage/database?id=",
64+
atlassian: {
65+
apiURL: "",
66+
username: "",
67+
key: "",
68+
projectId: "",
69+
customfieldReportTypeMapping: {
70+
edit: "10026",
71+
report: "10027",
72+
other: "10028"
73+
},
74+
issueTypes: {
75+
report: "10003",
76+
newEntry: "10014"
77+
},
78+
customfieldURL: "customfield_10040",
79+
customFieldReportType: "customfield_10041"
80+
}
6481
};
6582

6683
const configPath = "./config.json";

src/services/discord.service.ts

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
11
import axios from "axios"
22
import { config } from "./config.service.js"
33
import { DatabaseEntry } from "../models/database/entry.model.js"
4-
import IDictionary from "../types/dictionary"
5-
6-
const typeMapping: IDictionary = {
7-
group: "Gruppe/Verein",
8-
therapist: "Therapeut*in/Psychiater*in",
9-
surveyor: "Gutachter*in",
10-
endocrinologist: "Endokrinologische Praxis",
11-
surgeon: "Operateur*in",
12-
logopedics: "Logopäd*in",
13-
hairremoval: "Haarentfernung"
14-
}
15-
16-
const reportTypeMapping = {
17-
edit: "Änderungsvorschlag",
18-
report: "Nicht empfehlenswert",
19-
other: "Sonstiges"
20-
}
4+
import { reportTypeMapping, typeMapping } from "../models/entryMapping.js";
215

226
/**
237
* Send a Discord webhook to notify the creation of a new entry

0 commit comments

Comments
 (0)