forked from getsentry/integration-platform-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.ts
59 lines (52 loc) · 1.78 KB
/
options.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import express from 'express';
import Item from '../../models/Item.model';
import SentryInstallation from '../../models/SentryInstallation.model';
import User from '../../models/User.model';
const router = express.Router();
type SentrySelectOption = {
label: string;
value: string;
default?: boolean;
};
// These endpoints are used to populate the options for 'Select' FormFields in Sentry.
router.get('/items', async (request, response) => {
const {installationId: uuid} = request.query;
const sentryInstallation = await SentryInstallation.findOne({
where: {uuid},
});
if (!sentryInstallation) {
return response.sendStatus(404);
}
// We can use the installation data to filter the items we return to Sentry.
const items = await Item.findAll({
where: {organizationId: sentryInstallation.organizationId},
});
// Sentry requires the results in this exact format.
const result: SentrySelectOption[] = items.map(item => ({
label: item.title,
value: item.id,
}));
console.info('Populating item options in Sentry');
return response.send(result);
});
router.get('/users', async (request, response) => {
const {installationId: uuid} = request.query;
const sentryInstallation = await SentryInstallation.findOne({
where: {uuid},
});
if (!sentryInstallation) {
return response.sendStatus(404);
}
// We can use the installation data to filter the users we return to Sentry.
const users = await User.findAll({
where: {organizationId: sentryInstallation.organizationId},
});
// Sentry requires the results in this exact format.
const result: SentrySelectOption[] = users.map(user => ({
label: user.name,
value: user.id,
}));
console.info('Populating user options in Sentry');
return response.send(result);
});
export default router;