UNPKG

infinity-forge

Version:
193 lines • 16.6 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 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) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (g && (g = 0, op[0] && (_ = 0)), _) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getBlog = getBlog; var ui_1 = require("../../../../../../../ui/index.js"); function GetBlogV1(_a) { return __awaiter(this, arguments, void 0, function (_b) { var search, page, category, res, error_1; var _c, _d, _e; var ctx = _b.ctx, apiUrl = _b.apiUrl; return __generator(this, function (_f) { switch (_f.label) { case 0: _f.trys.push([0, 2, , 3]); search = (_c = ctx === null || ctx === void 0 ? void 0 : ctx.query) === null || _c === void 0 ? void 0 : _c.search; page = ((_d = ctx === null || ctx === void 0 ? void 0 : ctx.query) === null || _d === void 0 ? void 0 : _d.page) || 1; category = (_e = ctx === null || ctx === void 0 ? void 0 : ctx.query) === null || _e === void 0 ? void 0 : _e.category; return [4 /*yield*/, (0, ui_1.api)({ method: 'get', serverContext: ctx, url: "blog/list?search=".concat(search || '', "&page=").concat(page || 1, "&category=").concat(category || ''), }, apiUrl)]; case 1: res = _f.sent(); return [2 /*return*/, res || null]; case 2: error_1 = _f.sent(); return [2 /*return*/, null]; case 3: return [2 /*return*/]; } }); }); } function GetBlogV2(_a) { return __awaiter(this, arguments, void 0, function (_b) { var page, Search, category, locale_1, response, responseHighlight, categories, error_2; var _c, _d, _e, _f, _g, _h, _j; var ctx = _b.ctx, apiUrl = _b.apiUrl, entityKey = _b.entityKey, entityKeyCategory = _b.entityKeyCategory; return __generator(this, function (_k) { switch (_k.label) { case 0: _k.trys.push([0, 4, , 5]); page = ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.query) === null || _c === void 0 ? void 0 : _c.page) || 1; Search = ((_d = ctx === null || ctx === void 0 ? void 0 : ctx.query) === null || _d === void 0 ? void 0 : _d.search) || undefined; category = ((_e = ctx === null || ctx === void 0 ? void 0 : ctx.query) === null || _e === void 0 ? void 0 : _e.category) || undefined; locale_1 = ((_f = ctx === null || ctx === void 0 ? void 0 : ctx.query) === null || _f === void 0 ? void 0 : _f.locale) || (ctx === null || ctx === void 0 ? void 0 : ctx.locale) || 'pt-BR'; return [4 /*yield*/, (0, ui_1.api)({ url: 'admin/contents/blog/paginated', serverContext: ctx, method: 'get', body: { page: page, Search: Search, Url: category, EntityKey: entityKey }, }, apiUrl)]; case 1: response = _k.sent(); return [4 /*yield*/, (0, ui_1.api)({ url: 'admin/contents/blog/paginated', serverContext: ctx, method: 'get', body: { page: 1, Search: Search, Url: category, EntityKey: entityKey, Destaque: true }, }, apiUrl)]; case 2: responseHighlight = _k.sent(); return [4 /*yield*/, (0, ui_1.api)({ url: "admin/properties/categoria/blog/listCategories?EntityKey=".concat(entityKeyCategory || 'blog', "&pageSize=1000"), serverContext: ctx, method: 'get', }, apiUrl)]; case 3: categories = _k.sent(); return [2 /*return*/, { page: { pageTitle: 'Blog', }, categorias: (_g = categories === null || categories === void 0 ? void 0 : categories.items) === null || _g === void 0 ? void 0 : _g.map(function (categorie) { var _a, _b, _c, _d, _e, _f; var jsonContentData = (0, ui_1.parseJSON)(categorie === null || categorie === void 0 ? void 0 : categorie.jsonContent); var i18Top = ((_a = categorie === null || categorie === void 0 ? void 0 : categorie.i18n) === null || _a === void 0 ? void 0 : _a[locale_1]) || ((_b = categorie === null || categorie === void 0 ? void 0 : categorie.i18n) === null || _b === void 0 ? void 0 : _b['pt-BR']) || null; var i18Inside = ((_c = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.i18n) === null || _c === void 0 ? void 0 : _c[locale_1]) || ((_d = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.i18n) === null || _d === void 0 ? void 0 : _d['pt-BR']) || null; var i18 = i18Top || i18Inside || categorie; return { titulo: (_e = i18 === null || i18 === void 0 ? void 0 : i18.titulo) !== null && _e !== void 0 ? _e : '', url: (_f = categorie === null || categorie === void 0 ? void 0 : categorie.url) !== null && _f !== void 0 ? _f : '', }; }), highlights: (_h = responseHighlight === null || responseHighlight === void 0 ? void 0 : responseHighlight.items) === null || _h === void 0 ? void 0 : _h.map(function (item) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t; var jsonContentData = (0, ui_1.parseJSON)(item === null || item === void 0 ? void 0 : item.jsonContent); var i18Top = ((_a = item === null || item === void 0 ? void 0 : item.i18n) === null || _a === void 0 ? void 0 : _a[locale_1]) || ((_b = item === null || item === void 0 ? void 0 : item.i18n) === null || _b === void 0 ? void 0 : _b['pt-BR']) || null; var i18Inside = ((_c = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.i18n) === null || _c === void 0 ? void 0 : _c[locale_1]) || ((_d = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.i18n) === null || _d === void 0 ? void 0 : _d['pt-BR']) || null; var i18 = i18Top || i18Inside || {}; var data = { id: item === null || item === void 0 ? void 0 : item.id, ordem: (_e = item === null || item === void 0 ? void 0 : item.ordem) !== null && _e !== void 0 ? _e : null, titulo: (_f = ((i18 === null || i18 === void 0 ? void 0 : i18.titulo) || (item === null || item === void 0 ? void 0 : item.titulo))) !== null && _f !== void 0 ? _f : '', thumbnail: (_j = (_h = (_g = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.thumbnail) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.url) !== null && _j !== void 0 ? _j : '', imagem: (_p = (((_l = (_k = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.images) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.url) || ((_o = (_m = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.thumbnail) === null || _m === void 0 ? void 0 : _m[0]) === null || _o === void 0 ? void 0 : _o.url))) !== null && _p !== void 0 ? _p : '', url: (_q = ((i18 === null || i18 === void 0 ? void 0 : i18.url) || (item === null || item === void 0 ? void 0 : item.url))) !== null && _q !== void 0 ? _q : '', tags: (_r = ((i18 === null || i18 === void 0 ? void 0 : i18.tags) || (item === null || item === void 0 ? void 0 : item.tags))) !== null && _r !== void 0 ? _r : '', destaque: (_s = item === null || item === void 0 ? void 0 : item.destaque) !== null && _s !== void 0 ? _s : false, dataCriacao: item === null || item === void 0 ? void 0 : item.dataCriacao, descricao: (_t = ((i18 === null || i18 === void 0 ? void 0 : i18.descricao) || (item === null || item === void 0 ? void 0 : item.descricao))) !== null && _t !== void 0 ? _t : '', fields: { CategoriaId: item === null || item === void 0 ? void 0 : item.categoriaId, }, }; return data; }), pagination: response === null || response === void 0 ? void 0 : response.pagination, posts: (_j = response === null || response === void 0 ? void 0 : response.items) === null || _j === void 0 ? void 0 : _j.map(function (item) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t; var jsonContentData = (0, ui_1.parseJSON)(item === null || item === void 0 ? void 0 : item.jsonContent); var i18Top = ((_a = item === null || item === void 0 ? void 0 : item.i18n) === null || _a === void 0 ? void 0 : _a[locale_1]) || ((_b = item === null || item === void 0 ? void 0 : item.i18n) === null || _b === void 0 ? void 0 : _b['pt-BR']) || null; var i18Inside = ((_c = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.i18n) === null || _c === void 0 ? void 0 : _c[locale_1]) || ((_d = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.i18n) === null || _d === void 0 ? void 0 : _d['pt-BR']) || null; var i18 = i18Top || i18Inside || {}; var data = { id: item === null || item === void 0 ? void 0 : item.id, ordem: (_e = item === null || item === void 0 ? void 0 : item.ordem) !== null && _e !== void 0 ? _e : null, titulo: (_f = ((i18 === null || i18 === void 0 ? void 0 : i18.titulo) || (item === null || item === void 0 ? void 0 : item.titulo))) !== null && _f !== void 0 ? _f : '', thumbnail: (_j = (_h = (_g = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.thumbnail) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.url) !== null && _j !== void 0 ? _j : '', imagem: (_p = (((_l = (_k = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.images) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.url) || ((_o = (_m = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.thumbnail) === null || _m === void 0 ? void 0 : _m[0]) === null || _o === void 0 ? void 0 : _o.url))) !== null && _p !== void 0 ? _p : '', url: (_q = ((i18 === null || i18 === void 0 ? void 0 : i18.url) || (item === null || item === void 0 ? void 0 : item.url))) !== null && _q !== void 0 ? _q : '', tags: (_r = ((i18 === null || i18 === void 0 ? void 0 : i18.tags) || (item === null || item === void 0 ? void 0 : item.tags))) !== null && _r !== void 0 ? _r : '', destaque: (_s = item === null || item === void 0 ? void 0 : item.destaque) !== null && _s !== void 0 ? _s : false, dataCriacao: item === null || item === void 0 ? void 0 : item.dataCriacao, descricao: (_t = ((i18 === null || i18 === void 0 ? void 0 : i18.descricao) || (item === null || item === void 0 ? void 0 : item.descricao))) !== null && _t !== void 0 ? _t : '', fields: { CategoriaId: item === null || item === void 0 ? void 0 : item.categoriaId, }, }; return data; }), }]; case 4: error_2 = _k.sent(); return [2 /*return*/, null]; case 5: return [2 /*return*/]; } }); }); } function getBlog(_a) { return __awaiter(this, arguments, void 0, function (_b) { var params; var ctx = _b.ctx, apiUrl = _b.apiUrl, entityKey = _b.entityKey, entityKeyCategory = _b.entityKeyCategory; return __generator(this, function (_c) { switch (_c.label) { case 0: params = { apiUrl: apiUrl, ctx: ctx, entityKey: entityKey, entityKeyCategory: entityKeyCategory }; if (!process.env.tenant) return [3 /*break*/, 2]; return [4 /*yield*/, GetBlogV2(params)]; case 1: return [2 /*return*/, _c.sent()]; case 2: return [4 /*yield*/, GetBlogV1(params)]; case 3: return [2 /*return*/, _c.sent()]; } }); }); } //# sourceMappingURL=index.js.map