mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-10-01 01:05:53 -04:00
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import * as Promise from "bluebird";
|
|
import WidgetRecord from "./models/WidgetRecord";
|
|
import { Widget } from "../integrations/Widget";
|
|
import { resolveIfExists } from "./DimensionStore";
|
|
|
|
export class WidgetStore {
|
|
|
|
public static listAll(isEnabled?: boolean): Promise<Widget[]> {
|
|
let conditions = {};
|
|
if (isEnabled === true || isEnabled === false) conditions = {where: {isEnabled: isEnabled}};
|
|
return WidgetRecord.findAll(conditions).then(widgets => widgets.map(w => new Widget(w)));
|
|
}
|
|
|
|
public static setEnabled(type: string, isEnabled: boolean): Promise<any> {
|
|
return WidgetRecord.findOne({where: {type: type}}).then(resolveIfExists).then(widget => {
|
|
widget.isEnabled = isEnabled;
|
|
return widget.save();
|
|
});
|
|
}
|
|
|
|
public static setOptions(type: string, options: any): Promise<any> {
|
|
const optionsJson = JSON.stringify(options);
|
|
return WidgetRecord.findOne({where: {type: type}}).then(resolveIfExists).then(widget => {
|
|
widget.optionsJson = optionsJson;
|
|
return widget.save();
|
|
});
|
|
}
|
|
|
|
private constructor() {
|
|
}
|
|
|
|
} |