-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplugin.ts
69 lines (60 loc) · 2.01 KB
/
plugin.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
60
61
62
63
64
65
66
67
68
69
import * as notifications from "./lib/db/notifications";
import {AnyCallback, noop} from "./lib/fn";
import * as unattendUser from "./lib/unattendUser";
import {eventRepository} from "./lib/db/event";
const logger = require('./lib/logger');
const meta = require("./plugin.json");
meta.nbbId = meta.id.replace(/nodebb-plugin-/, "");
export function setup(params, callback): void {
const adminModule = require("./lib/admin");
const api = require("./lib/api");
const actions = require("./lib/actions").default;
adminModule
.init(params, meta)
.then(() => {
api.setConfig(adminModule.getPluginSettings())
api
.init(params)
.then(callback)
})
actions(params, meta, noop);
}
export function catchAttendanceChange(params, callback?: AnyCallback): void {
logger.debug("caught attendance change, yay. params: " + JSON.stringify(params))
const tid = Number(params.tid)
const uid = Number(params.uid)
callback = callback || noop;
if (params.probability >= 1) {
return callback(null, null);
}
unattendUser.unattendUser(tid, uid).then(resultCount => {
if (resultCount) {
notifications.notifyAutoUnslotted(tid, uid, resultCount);
}
callback(null, null);
}).catch(error => {
callback(error, null)
});
}
export function filterAttendanceSlotted(params, callback: (err: Error, userIds: number[])=> void): void {
const tid = params.tid;
eventRepository.getSlottedUserIds(tid).then(userIds => {
params.userIds = userIds;
callback(null, userIds);
}).catch(error => {
callback(error, [])
});
}
export function handleHeaders(params, callback): void {
callback(null, null);
}
export const admin = {
menu(customHeader, callback: AnyCallback) {
customHeader.plugins.push({
icon: "fa-calendar",
name: meta.name,
route: "/plugins/" + meta.nbbId,
});
callback(null, customHeader);
},
};