UNPKG

@ournet/news-data

Version:
51 lines (50 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const domain_1 = require("@ournet/domain"); const news_domain_1 = require("@ournet/news-domain"); const dynamo_article_content_1 = require("./dynamo-article-content"); class DynamoArticleContentRepository extends domain_1.BaseRepository { constructor(client, tableSuffix) { super(new news_domain_1.ArticleContentValidator()); this.model = new dynamo_article_content_1.ArticleContentModel(client, tableSuffix); } async put(content) { content = super.beforeCreate(content); return this.model.put(content); } async innerCreate(data) { return await this.model.create(data); } async innerUpdate(data) { return await this.model.update({ remove: data.delete, key: { id: data.id }, set: data.set, }); } async delete(id) { const oldItem = await this.model.delete({ id }); return !!oldItem; } async exists(id) { const item = await this.getById(id, { fields: ['id'] }); return !!item; } async getById(id, options) { return await this.model.get({ id }, options && { attributes: options.fields }); } async getByIds(ids, options) { return await this.model.getItems(ids.map(id => ({ id })), options && { attributes: options.fields }); } async deleteStorage() { await Promise.all([ this.model.deleteTable(), ]); } async createStorage() { await Promise.all([ this.model.createTable(), ]); } } exports.DynamoArticleContentRepository = DynamoArticleContentRepository;