@ournet/news-data
Version:
Ournet news data module
77 lines (76 loc) • 2.48 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const dynamo_item_1 = require("dynamo-item");
const news_domain_1 = require("@ournet/news-domain");
const dynamo_event_1 = require("./dynamo-event");
class TopicEventHelper {
static create(locale, eventId, createdAt, topics) {
const expiresAt = news_domain_1.EventHelper.topicExpiresAt(new Date(createdAt));
return topics.map((topic) => {
const item = {
eventId,
createdAt,
expiresAt,
topicId: topic.id,
locale: dynamo_event_1.DynamoEventHelper.createLocaleKey(locale)
};
return item;
});
}
}
exports.TopicEventHelper = TopicEventHelper;
class TopicEventModel extends dynamo_item_1.DynamoItem {
localeLastTopicsIndexName() {
return "locale-last-topics-index";
}
topicLastEventsIndexName() {
return "topic-last-events-index";
}
constructor(client, tableSuffix) {
super({
hashKey: {
name: "topicId",
type: "S"
},
rangeKey: {
name: "eventId",
type: "S"
},
name: "topic_events",
tableName: `ournet_events__topic_${tableSuffix}`,
indexes: [
{
name: "topic-last-events-index",
hashKey: {
name: "topicId",
type: "S"
},
rangeKey: {
name: "createdAt",
type: "S"
},
type: "LOCAL",
projection: {
type: "KEYS_ONLY"
}
},
{
name: "locale-last-topics-index",
hashKey: {
name: "locale",
type: "S"
},
rangeKey: {
name: "createdAt",
type: "S"
},
type: "GLOBAL",
projection: {
type: "KEYS_ONLY"
}
}
]
}, client);
}
}
exports.TopicEventModel = TopicEventModel;