airship-server
Version:
Airship is a framework for Node.JS & TypeScript that helps you to write big, scalable and maintainable API servers.
58 lines • 2.5 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const BaseNotificationsService_1 = require("../domain/BaseNotificationsService");
const ContestNotificationSubscription_1 = require("../../../hhEvents/domain/entity/notifications/ContestNotificationSubscription");
class NotificationsService extends BaseNotificationsService_1.BaseNotificationsService {
constructor(db) {
super();
this._db = db;
}
subscribeToNotification(groupId, userId) {
return __awaiter(this, void 0, void 0, function* () {
yield this.unSubscribeToNotification(groupId, userId);
yield this._db.ContestNotificationSubscription.create({
groupId,
userId
});
});
}
unSubscribeToNotification(groupId, userId) {
return __awaiter(this, void 0, void 0, function* () {
yield this._db.ContestNotificationSubscription.destroy({
where: {
groupId,
userId
}
});
});
}
isSubscribedToNotification(groupId, userId) {
return __awaiter(this, void 0, void 0, function* () {
let subscription = yield this._db.ContestNotificationSubscription.findOne({
groupId,
userId
});
return !!subscription;
});
}
getSubscribersForGroup(groupId) {
return __awaiter(this, void 0, void 0, function* () {
let subscriptions = yield this._db.ContestNotificationSubscription.findAll({
where: {
groupId
}
});
return subscriptions.map(s => new ContestNotificationSubscription_1.default(s.groupId, s.userId));
});
}
}
exports.default = NotificationsService;
//# sourceMappingURL=NotificationsService.js.map